zabbix添加对haproxy的监控

HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。HAProxy本身提供一个web页面可以显示haproxy的各种信息,方便管理员查看系统状态等。此次我采用socat(socat是netcat的扩展实现)这款开源软件通过haproxy的socks配合zabbix实现haproxy系统的状态监控。

一、安装socat
wget http://www.dest-unreach.org/socat/download/socat-1.7.3.0.tar.gz
tar xzf socat-1.7.3.0.tar.gz
cd socat-1.7.3.0
./configure
make && make install
which socat #安装完自动会在/usr/local/bin 创建执行程序
/usr/local/bin/socat

二、开启haproxy sock
编辑haproxy配置文件在global下添加如下:
global
stats socket /tmp/haproxy.sock mode 600 level admin

# 重启haproxy
/etc/init.d/haproxy restart

Haproxy 信息

[[email protected] socat-1.7.3.0]# echo "show info" |socat /tmp/haproxy.sock stdio
Name: HAProxy
Version: 1.5.19
Release_date: 2016/12/25
Nbproc: 1
Process_num: 1
Pid: 20816
Uptime: 1d 21h14m40s
Uptime_sec: 162880
Memmax_MB: 0
Ulimit-n: 400034
Maxsock: 400034
Maxconn: 200000
Hard_maxconn: 200000
CurrConns: 0
CumConns: 45
CumReq: 45
MaxSslConns: 0
CurrSslConns: 0
CumSslConns: 0
Maxpipes: 0
PipesUsed: 0
PipesFree: 0
ConnRate: 0
ConnRateLimit: 0
MaxConnRate: 2
SessRate: 0
SessRateLimit: 0
MaxSessRate: 2
SslRate: 0
SslRateLimit: 0
MaxSslRate: 0
SslFrontendKeyRate: 0
SslFrontendMaxKeyRate: 0
SslFrontendSessionReuse_pct: 0
SslBackendKeyRate: 0
SslBackendMaxKeyRate: 0
SslCacheLookups: 0
SslCacheMisses: 0
CompressBpsIn: 0
CompressBpsOut: 0
CompressBpsRateLim: 0
ZlibMemUsage: 0
MaxZlibMemUsage: 0
Tasks: 7
Run_queue: 1
Idle_pct: 100
node: 210-61-161-118.hinet-ip.hinet.net
description:

[[email protected] socat-1.7.3.0]# echo "show stat" |socat /tmp/haproxy.sock stdio
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
admin_stats,FRONTEND,,,0,1,10,13,619,2481,0,0,11,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,2,,,,0,0,0,11,2,0,,0,2,13,,,0,0,0,0,,,,,,,,
admin_stats,BACKEND,0,0,0,1,1,2,619,2481,0,0,,2,0,0,0,UP,0,0,0,,0,163002,0,,1,2,0,,0,,1,0,,1,,,,0,0,0,0,2,0,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,
im_access_6666,FRONTEND,,,0,1,200000,31,6617,8443,0,0,0,,,,,OPEN,,,,,,,,,1,3,0,,,,0,0,0,1,,,,,,,,,,,0,0,0,,,0,0,0,0,,,,,,,,
im_access_6666,im01,0,0,0,1,100000,16,3473,4235,,0,,0,0,0,0,UP,1,1,0,0,0,163002,0,,1,3,1,,16,,2,0,,1,L4OK,,0,,,,,,,0,,,,2,0,,,,,4285,,,0,1,0,3116,
im_access_6666,im02,0,0,0,1,100000,15,3144,4208,,0,,0,0,0,0,UP,1,1,0,0,0,163002,0,,1,3,2,,15,,2,0,,1,L4OK,,0,,,,,,,0,,,,0,0,,,,,4885,,,0,1,0,3778,
im_access_6666,BACKEND,0,0,0,1,20000,31,6617,8443,0,0,,0,0,0,0,UP,2,2,0,,0,163002,0,,1,3,0,,31,,1,0,,1,,,,,,,,,,,,,,2,0,0,0,0,0,4285,,,0,1,0,6804,

看到这里大家都明白了,我们可以通过“show stat”返回的信息,过滤出我们想要得到的监控字段数据。这里我们主要取qcur(queue数量)、scur(session数量)、bin(入站流量)、bout(出站流量)、status(后端服务器状态)、downtime(宕机总时长)、check_status(健康检测状态),自定义key收集这些数据制作相应的item,如果你想监控更多信息可以取更多的字段数据。
大家看到这些字段数据使用”,”分隔,非常方便我们用awk来过滤数据,具体自定义key见代码。首先,我们需要建立一个HAProxy模版,然后建立发现规则,来发现这些后端服务器,这样每次haproxy添加服务的时候,zabbix就会自动发现这些后端服务器、自动建立item、自动建立Graph、自动建立Trigger,一切全部自动完成。

三、Step by Step
1、导入haproxy模版

2、添加.sh文件到/usr/bin目录下
# cd /usr/bin
# cat ckey.ha.bin.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $9}‘

# cat ckey.ha.bout.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $10}‘

# cat ckey.ha.downtime.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $25}‘

# cat ckey.ha.lastchk.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $38}‘

# cat ckey.ha.queue.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $3}‘

# cat ckey.ha.session.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $5}‘

# cat ckey.ha.status.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo "show stat" |socat /tmp/haproxy.sock stdio|grep "\<$1\>"|grep -v "^FRONTEND"|grep -v "^BACKEND"|awk -F "," ‘{print $18}‘

# 建立发现规则
key shell如下:(这里有一点需要注意,就是haproxy.sock这个文件的权限问题,默认是644,单纯执行这个shell没问题,但如果需要zabbix用户去获取返回值的时候就会提示权限不足,所以我直接将haproxy.sock设置成了666,也可以设置visudo,我为了方便直接修改了这个文件权限)
# cat has.discovery.sh
#!/bin/bash
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
printf ‘{\n‘
printf ‘\t"data":[\n‘
export LINE=$(echo "show stat" |socat /tmp/haproxy.sock stdio|grep -v "^#"|grep -v "^admin_stats"|awk -F "," ‘{print $2}‘|grep -v "^FRONTEND"|grep -v "^BACKEND"|grep -v "^$"|wc -l)
export N=0
#printf ‘\t\t{\n‘
for i in $(echo "show stat" |socat /tmp/haproxy.sock stdio|grep -v "^#"|grep -v "^admin_stats"|awk -F "," ‘{print $2}‘|grep -v "^FRONTEND"|grep -v "^BACKEND");
do printf "\t\t\t{\"{#SNAME}\":\"$i\"}";
N=$(($N+1))
if [ $N -eq $LINE ];
then
printf ‘\n‘
else
printf ‘,\n‘
fi
done;
printf ‘]}\n‘

3、定义key配置文件
[[email protected] src]# vim /etc/zabbix/zabbix_agentd.d/HaProxy_status.conf
UserParameter=has.discovery,/usr/bin/has.discovery.sh
UserParameter=ckey.ha.bin[*],/usr/bin/ckey.ha.bin.sh $1
UserParameter=ckey.ha.bout[*],/usr/bin/ckey.ha.bout.sh $1
UserParameter=ckey.ha.downtime[*],/usr/bin/ckey.ha.downtime.sh $1
UserParameter=ckey.ha.lastchk[*],/usr/bin/ckey.ha.lastchk.sh $1
UserParameter=ckey.ha.queue[*],/usr/bin/ckey.ha.queue.sh $1
UserParameter=ckey.ha.session[*],/usr/bin/ckey.ha.session.sh $1
UserParameter=ckey.ha.status[*],/usr/bin/ckey.ha.status.sh $1

重启zabbix客户端
# /etc/init.d/zabbix-agent restart

4.在web上操作主机添加模板

在zabbix-server端测试:
[[email protected] ~]# zabbix_get -s 1.1.1.1 -p 10050-k has.discovery
{
"data":[
2017/11/17 17:06:38 socat[8231] E open("/usr/local/haproxy/haproxy.sock", 02002, 0666): Permission denied
2017/11/17 17:06:38 socat[8241] E open("/usr/local/haproxy/haproxy.sock", 02002, 0666): Permission denied
]}

修改权限即可
[[email protected] src]# chmod 666 /tmp/haproxy.sock

[[email protected] ~]# zabbix_get -s 1.1.1.1 -p 10050 -k has.discovery
{
"data":[
{"{#SNAME}":"im01"},
{"{#SNAME}":"im02"}
]}

sed -i "s#/usr/local/haproxy/haproxy.sock#/tmp/haproxy.sock#g" *.sh

监控模板zbx_haproxy_templates.xml

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>3.0</version>
    <date>2017-11-17T06:48:38Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>Template HaProxy Service</template>
            <name>Template HaProxy Service</name>
            <description/>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>NetWork</name>
                </application>
                <application>
                    <name>Status</name>
                </application>
            </applications>
            <items/>
            <discovery_rules>
                <discovery_rule>
                    <name>ha.vserver.discovery</name>
                    <type>0</type>
                    <snmp_community/>
                    <snmp_oid/>
                    <key>has.discovery</key>
                    <delay>1800</delay>
                    <status>0</status>
                    <allowed_hosts/>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <filter>
                        <evaltype>0</evaltype>
                        <formula/>
                        <conditions/>
                    </filter>
                    <lifetime>30</lifetime>
                    <description/>
                    <item_prototypes>
                        <item_prototype>
                            <name>ha.vserver.bps.in $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>1</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.bin[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>0</value_type>
                            <allowed_hosts/>
                            <units>bps</units>
                            <delta>1</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>6</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>NetWork</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.bps.out $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>1</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.bout[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>0</value_type>
                            <allowed_hosts/>
                            <units>bps</units>
                            <delta>1</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>8</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>NetWork</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.downtime $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>0</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.downtime[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>3</value_type>
                            <allowed_hosts/>
                            <units>s</units>
                            <delta>0</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>1</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>Status</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.lastchk $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>0</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.lastchk[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>3</value_type>
                            <allowed_hosts/>
                            <units/>
                            <delta>0</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>1</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>Status</name>
                                </application>
                            </applications>
                            <valuemap>
                                <name>HTTP response status code</name>
                            </valuemap>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.queue $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>0</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.queue[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>0</value_type>
                            <allowed_hosts/>
                            <units/>
                            <delta>0</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>1</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>NetWork</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.session $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>0</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.session[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>365</trends>
                            <status>0</status>
                            <value_type>3</value_type>
                            <allowed_hosts/>
                            <units/>
                            <delta>0</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>1</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>NetWork</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                        <item_prototype>
                            <name>ha.vserver.status $1</name>
                            <type>0</type>
                            <snmp_community/>
                            <multiplier>0</multiplier>
                            <snmp_oid/>
                            <key>ckey.ha.status[{#SNAME}]</key>
                            <delay>60</delay>
                            <history>90</history>
                            <trends>0</trends>
                            <status>0</status>
                            <value_type>4</value_type>
                            <allowed_hosts/>
                            <units/>
                            <delta>0</delta>
                            <snmpv3_contextname/>
                            <snmpv3_securityname/>
                            <snmpv3_securitylevel>0</snmpv3_securitylevel>
                            <snmpv3_authprotocol>0</snmpv3_authprotocol>
                            <snmpv3_authpassphrase/>
                            <snmpv3_privprotocol>0</snmpv3_privprotocol>
                            <snmpv3_privpassphrase/>
                            <formula>1</formula>
                            <delay_flex/>
                            <params/>
                            <ipmi_sensor/>
                            <data_type>0</data_type>
                            <authtype>0</authtype>
                            <username/>
                            <password/>
                            <publickey/>
                            <privatekey/>
                            <port/>
                            <description/>
                            <inventory_link>0</inventory_link>
                            <applications>
                                <application>
                                    <name>Status</name>
                                </application>
                            </applications>
                            <valuemap/>
                            <logtimefmt/>
                            <application_prototypes/>
                        </item_prototype>
                    </item_prototypes>
                    <trigger_prototypes>
                        <trigger_prototype>
                            <expression>{Template HaProxy Service:ckey.ha.bin[{#SNAME}].max(#5)}&gt;2000000</expression>
                            <name>Ha.Vserver {#SNAME} Inbound Flyde over 2Mbps</name>
                            <url/>
                            <status>0</status>
                            <priority>2</priority>
                            <description/>
                            <type>0</type>
                            <dependencies/>
                        </trigger_prototype>
                        <trigger_prototype>
                            <expression>{Template HaProxy Service:ckey.ha.lastchk[{#SNAME}].last(,2m)}&lt;&gt;200</expression>
                            <name>Ha.Vserver {#SNAME} is Check Failed</name>
                            <url/>
                            <status>0</status>
                            <priority>4</priority>
                            <description/>
                            <type>0</type>
                            <dependencies/>
                        </trigger_prototype>
                        <trigger_prototype>
                            <expression>{Template HaProxy Service:ckey.ha.status[{#SNAME}].strlen(,2m)}&lt;&gt;2</expression>
                            <name>Ha.Vserver {#SNAME} is Down</name>
                            <url/>
                            <status>0</status>
                            <priority>4</priority>
                            <description/>
                            <type>0</type>
                            <dependencies>
                                <dependency>
                                    <name>Ha.Vserver {#SNAME} is Check Failed</name>
                                    <expression>{Template HaProxy Service:ckey.ha.lastchk[{#SNAME}].last(,2m)}&lt;&gt;200</expression>
                                </dependency>
                            </dependencies>
                        </trigger_prototype>
                        <trigger_prototype>
                            <expression>{Template HaProxy Service:ckey.ha.bout[{#SNAME}].max(#5)}&gt;2000000</expression>
                            <name>Ha.Vserver {#SNAME} Outbound Flyde over 2Mbps</name>
                            <url/>
                            <status>0</status>
                            <priority>2</priority>
                            <description/>
                            <type>0</type>
                            <dependencies/>
                        </trigger_prototype>
                    </trigger_prototypes>
                    <graph_prototypes>
                        <graph_prototype>
                            <name>Ha.Vserver.DownTime {#SNAME}</name>
                            <width>900</width>
                            <height>200</height>
                            <yaxismin>0.0000</yaxismin>
                            <yaxismax>100.0000</yaxismax>
                            <show_work_period>1</show_work_period>
                            <show_triggers>1</show_triggers>
                            <type>0</type>
                            <show_legend>1</show_legend>
                            <show_3d>0</show_3d>
                            <percent_left>0.0000</percent_left>
                            <percent_right>0.0000</percent_right>
                            <ymin_type_1>0</ymin_type_1>
                            <ymax_type_1>0</ymax_type_1>
                            <ymin_item_1>0</ymin_item_1>
                            <ymax_item_1>0</ymax_item_1>
                            <graph_items>
                                <graph_item>
                                    <sortorder>0</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>009999</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>7</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.downtime[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                            </graph_items>
                        </graph_prototype>
                        <graph_prototype>
                            <name>Ha.Vserver.LastCheck {#SNAME}</name>
                            <width>900</width>
                            <height>200</height>
                            <yaxismin>0.0000</yaxismin>
                            <yaxismax>100.0000</yaxismax>
                            <show_work_period>1</show_work_period>
                            <show_triggers>1</show_triggers>
                            <type>0</type>
                            <show_legend>1</show_legend>
                            <show_3d>0</show_3d>
                            <percent_left>0.0000</percent_left>
                            <percent_right>0.0000</percent_right>
                            <ymin_type_1>0</ymin_type_1>
                            <ymax_type_1>0</ymax_type_1>
                            <ymin_item_1>0</ymin_item_1>
                            <ymax_item_1>0</ymax_item_1>
                            <graph_items>
                                <graph_item>
                                    <sortorder>0</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>00DD00</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>2</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.lastchk[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                            </graph_items>
                        </graph_prototype>
                        <graph_prototype>
                            <name>Ha.Vserver.NetWrok Flow {#SNAME}</name>
                            <width>900</width>
                            <height>200</height>
                            <yaxismin>0.0000</yaxismin>
                            <yaxismax>100.0000</yaxismax>
                            <show_work_period>1</show_work_period>
                            <show_triggers>1</show_triggers>
                            <type>0</type>
                            <show_legend>1</show_legend>
                            <show_3d>0</show_3d>
                            <percent_left>0.0000</percent_left>
                            <percent_right>0.0000</percent_right>
                            <ymin_type_1>0</ymin_type_1>
                            <ymax_type_1>0</ymax_type_1>
                            <ymin_item_1>0</ymin_item_1>
                            <ymax_item_1>0</ymax_item_1>
                            <graph_items>
                                <graph_item>
                                    <sortorder>0</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>1A7C11</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>7</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.bin[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                                <graph_item>
                                    <sortorder>1</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>F63100</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>7</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.bout[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                            </graph_items>
                        </graph_prototype>
                        <graph_prototype>
                            <name>Ha.Vserver.NetWrok Session_Queue {#SNAME}</name>
                            <width>900</width>
                            <height>200</height>
                            <yaxismin>0.0000</yaxismin>
                            <yaxismax>100.0000</yaxismax>
                            <show_work_period>1</show_work_period>
                            <show_triggers>1</show_triggers>
                            <type>0</type>
                            <show_legend>1</show_legend>
                            <show_3d>0</show_3d>
                            <percent_left>0.0000</percent_left>
                            <percent_right>0.0000</percent_right>
                            <ymin_type_1>0</ymin_type_1>
                            <ymax_type_1>0</ymax_type_1>
                            <ymin_item_1>0</ymin_item_1>
                            <ymax_item_1>0</ymax_item_1>
                            <graph_items>
                                <graph_item>
                                    <sortorder>0</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>BB00BB</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>2</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.queue[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                                <graph_item>
                                    <sortorder>1</sortorder>
                                    <drawtype>0</drawtype>
                                    <color>0000CC</color>
                                    <yaxisside>0</yaxisside>
                                    <calc_fnc>2</calc_fnc>
                                    <type>0</type>
                                    <item>
                                        <host>Template HaProxy Service</host>
                                        <key>ckey.ha.session[{#SNAME}]</key>
                                    </item>
                                </graph_item>
                            </graph_items>
                        </graph_prototype>
                    </graph_prototypes>
                    <host_prototypes/>
                </discovery_rule>
            </discovery_rules>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <value_maps>
        <value_map>
            <name>HTTP response status code</name>
            <mappings>
                <mapping>
                    <value>100</value>
                    <newvalue>Continue</newvalue>
                </mapping>
                <mapping>
                    <value>101</value>
                    <newvalue>Switching Protocols</newvalue>
                </mapping>
                <mapping>
                    <value>102</value>
                    <newvalue>Processing</newvalue>
                </mapping>
                <mapping>
                    <value>200</value>
                    <newvalue>OK</newvalue>
                </mapping>
                <mapping>
                    <value>201</value>
                    <newvalue>Created</newvalue>
                </mapping>
                <mapping>
                    <value>202</value>
                    <newvalue>Accepted</newvalue>
                </mapping>
                <mapping>
                    <value>203</value>
                    <newvalue>Non-Authoritative Information</newvalue>
                </mapping>
                <mapping>
                    <value>204</value>
                    <newvalue>No Content</newvalue>
                </mapping>
                <mapping>
                    <value>205</value>
                    <newvalue>Reset Content</newvalue>
                </mapping>
                <mapping>
                    <value>206</value>
                    <newvalue>Partial Content</newvalue>
                </mapping>
                <mapping>
                    <value>207</value>
                    <newvalue>Multi-Status</newvalue>
                </mapping>
                <mapping>
                    <value>208</value>
                    <newvalue>Already Reported</newvalue>
                </mapping>
                <mapping>
                    <value>226</value>
                    <newvalue>IM Used</newvalue>
                </mapping>
                <mapping>
                    <value>300</value>
                    <newvalue>Multiple Choices</newvalue>
                </mapping>
                <mapping>
                    <value>301</value>
                    <newvalue>Moved Permanently</newvalue>
                </mapping>
                <mapping>
                    <value>302</value>
                    <newvalue>Found</newvalue>
                </mapping>
                <mapping>
                    <value>303</value>
                    <newvalue>See Other</newvalue>
                </mapping>
                <mapping>
                    <value>304</value>
                    <newvalue>Not Modified</newvalue>
                </mapping>
                <mapping>
                    <value>305</value>
                    <newvalue>Use Proxy</newvalue>
                </mapping>
                <mapping>
                    <value>306</value>
                    <newvalue>Switch Proxy</newvalue>
                </mapping>
                <mapping>
                    <value>307</value>
                    <newvalue>Temporary Redirect</newvalue>
                </mapping>
                <mapping>
                    <value>308</value>
                    <newvalue>Permanent Redirect/Resume Incomplete</newvalue>
                </mapping>
                <mapping>
                    <value>400</value>
                    <newvalue>Bad Request</newvalue>
                </mapping>
                <mapping>
                    <value>401</value>
                    <newvalue>Unauthorized</newvalue>
                </mapping>
                <mapping>
                    <value>402</value>
                    <newvalue>Payment Required</newvalue>
                </mapping>
                <mapping>
                    <value>403</value>
                    <newvalue>Forbidden</newvalue>
                </mapping>
                <mapping>
                    <value>404</value>
                    <newvalue>Not Found</newvalue>
                </mapping>
                <mapping>
                    <value>405</value>
                    <newvalue>Method Not Allowed</newvalue>
                </mapping>
                <mapping>
                    <value>406</value>
                    <newvalue>Not Acceptable</newvalue>
                </mapping>
                <mapping>
                    <value>407</value>
                    <newvalue>Proxy Authentication Required</newvalue>
                </mapping>
                <mapping>
                    <value>408</value>
                    <newvalue>Request Timeout</newvalue>
                </mapping>
                <mapping>
                    <value>409</value>
                    <newvalue>Conflict</newvalue>
                </mapping>
                <mapping>
                    <value>410</value>
                    <newvalue>Gone</newvalue>
                </mapping>
                <mapping>
                    <value>411</value>
                    <newvalue>Length Required</newvalue>
                </mapping>
                <mapping>
                    <value>412</value>
                    <newvalue>Precondition Failed</newvalue>
                </mapping>
                <mapping>
                    <value>413</value>
                    <newvalue>Payload Too Large</newvalue>
                </mapping>
                <mapping>
                    <value>414</value>
                    <newvalue>Request-URI Too Long</newvalue>
                </mapping>
                <mapping>
                    <value>415</value>
                    <newvalue>Unsupported Media Type</newvalue>
                </mapping>
                <mapping>
                    <value>416</value>
                    <newvalue>Requested Range Not Satisfiable</newvalue>
                </mapping>
                <mapping>
                    <value>417</value>
                    <newvalue>Expectation Failed</newvalue>
                </mapping>
                <mapping>
                    <value>418</value>
                    <newvalue>I‘m a Teapot</newvalue>
                </mapping>
                <mapping>
                    <value>419</value>
                    <newvalue>Authentication Timeout</newvalue>
                </mapping>
                <mapping>
                    <value>420</value>
                    <newvalue>Method Failure/Enhance Your Calm</newvalue>
                </mapping>
                <mapping>
                    <value>421</value>
                    <newvalue>Misdirected Request</newvalue>
                </mapping>
                <mapping>
                    <value>422</value>
                    <newvalue>Unprocessable Entity</newvalue>
                </mapping>
                <mapping>
                    <value>423</value>
                    <newvalue>Locked</newvalue>
                </mapping>
                <mapping>
                    <value>424</value>
                    <newvalue>Failed Dependency</newvalue>
                </mapping>
                <mapping>
                    <value>426</value>
                    <newvalue>Upgrade Required</newvalue>
                </mapping>
                <mapping>
                    <value>428</value>
                    <newvalue>Precondition Required</newvalue>
                </mapping>
                <mapping>
                    <value>429</value>
                    <newvalue>Too Many Requests</newvalue>
                </mapping>
                <mapping>
                    <value>431</value>
                    <newvalue>Request Header Fields Too Large</newvalue>
                </mapping>
                <mapping>
                    <value>440</value>
                    <newvalue>Login Timeout</newvalue>
                </mapping>
                <mapping>
                    <value>444</value>
                    <newvalue>No Response</newvalue>
                </mapping>
                <mapping>
                    <value>449</value>
                    <newvalue>Retry With</newvalue>
                </mapping>
                <mapping>
                    <value>450</value>
                    <newvalue>Blocked by Windows Parental Controls</newvalue>
                </mapping>
                <mapping>
                    <value>451</value>
                    <newvalue>Unavailable for Legal Reasons/Redirect</newvalue>
                </mapping>
                <mapping>
                    <value>494</value>
                    <newvalue>Request Header Too Large</newvalue>
                </mapping>
                <mapping>
                    <value>495</value>
                    <newvalue>Cert Error</newvalue>
                </mapping>
                <mapping>
                    <value>496</value>
                    <newvalue>No Cert</newvalue>
                </mapping>
                <mapping>
                    <value>497</value>
                    <newvalue>HTTP to HTTPS</newvalue>
                </mapping>
                <mapping>
                    <value>498</value>
                    <newvalue>Token Expired/Invalid</newvalue>
                </mapping>
                <mapping>
                    <value>499</value>
                    <newvalue>Client Closed Request/Token Required</newvalue>
                </mapping>
                <mapping>
                    <value>500</value>
                    <newvalue>Internal Server Error</newvalue>
                </mapping>
                <mapping>
                    <value>501</value>
                    <newvalue>Not Implemented</newvalue>
                </mapping>
                <mapping>
                    <value>502</value>
                    <newvalue>Bad Gateway</newvalue>
                </mapping>
                <mapping>
                    <value>503</value>
                    <newvalue>Service Unavailable</newvalue>
                </mapping>
                <mapping>
                    <value>504</value>
                    <newvalue>Gateway Timeout</newvalue>
                </mapping>
                <mapping>
                    <value>505</value>
                    <newvalue>HTTP Version Not Supported</newvalue>
                </mapping>
                <mapping>
                    <value>506</value>
                    <newvalue>Variant Also Negotiates</newvalue>
                </mapping>
                <mapping>
                    <value>507</value>
                    <newvalue>Insufficient Storage</newvalue>
                </mapping>
                <mapping>
                    <value>508</value>
                    <newvalue>Loop Detected</newvalue>
                </mapping>
                <mapping>
                    <value>509</value>
                    <newvalue>Bandwidth Limit Exceeded</newvalue>
                </mapping>
                <mapping>
                    <value>510</value>
                    <newvalue>Not Extended</newvalue>
                </mapping>
                <mapping>
                    <value>511</value>
                    <newvalue>Network Authentication Required</newvalue>
                </mapping>
                <mapping>
                    <value>520</value>
                    <newvalue>Unknown Error</newvalue>
                </mapping>
                <mapping>
                    <value>598</value>
                    <newvalue>Network Read Timeout Error</newvalue>
                </mapping>
                <mapping>
                    <value>599</value>
                    <newvalue>Network Connect Timeout Error</newvalue>
                </mapping>
            </mappings>
        </value_map>
    </value_maps>
</zabbix_export>
时间: 2024-10-05 04:58:06

zabbix添加对haproxy的监控的相关文章

Zabbix添加对Windows OS监控

Zabbix服务器搭建完成后,下面来添加对Windows系统的监控 下载Agent https://www.zabbix.com/download 因为我们安装的是Zabbix 3.2.10 所以我们下载较新的3.2.7版本的Agent 下载完成后解压出来两个文件夹 Bin  下面的win64和win32对应不同位数系统的exe文件 conf 下面的是zabbix Agent的配置文件 2:配置Agent 打开zabbix_agentd.win.conf (推荐使用notepad++,没有用写字

Zabbix添加网卡内外流量监控

题外话:zabbix讲究一气呵成,从头到尾没人打扰然后布置.但是干运维难免有人来打扰,这个过来要求布环境,那个要求来买服务器.所以zabbix之路难免走的坑坑洼洼. 现在笔者想对host名单里面的zabbix_server进行网卡的内外流量情况的一个监控,首先登录zabbix之后,configuration---hosts,出现如下的菜单: 现在可以看到这个zabbix_server后面link了很多个模板,正是因为link了很多的模板,所以导致它的items非常多,42个.现在是要在zabbi

zabbix添加主机并创建监控模板

主动模式和被动模式 被动模式,服务器端会主动连接客户端获取监控数据,客户端被动地接受,并把数据传递给服务器端主动模式,客户端主动把监控数据汇总然后再汇报给客户端,服务端只负责接收数据当客户端数量非常多的时候,建议使用主动模式,因为服务器不再会去所有客户机上请求回报数据,这样降低服务端的压力当客户端没有公网IP地址时,而又需要监控内网的客户端的时候,这时候适用主动模式,因为客户端能够访问到公网服务器的IP,反过来服务器不能和服务端通信,这就需要客户端把监控数据要主动发给服务端,这里就非常适合适用主

zabbix 添加磁盘剩余容量监控方法

1.新建监控模板 Configuration--Templates--Create template 在Template name中输入disk space 50Gb 然后,保存即可. 2.新建Items Name为The free disk space is less than 50Gb key为:vfs.fs.size[/data,free] 保存即可 3.创建Triggers Trigger的名字为The free disk space is less than 50Gb Expressi

给zabbix添加percona监控模板

简单说明一下给zabbix添加的percona的监控模板. 在percona官方网站有说明怎么安装,这里记录下步骤.首先搭建好的zabbix环境. 监控插件连接 : 链接:https://pan.baidu.com/s/1xHbc_HhmN-XuGGiKrg7nPQ 提取码:i4ku yum安装percona的监控插件(安装在要监控的mysql服务器上) yum install -y percona-zabbix-templates-1.1.8-1.noarch.rpm 安装完成之后会生成如下四

Zabbix添加自己需要监控的项

Zabbix添加自己需要监控的项 比如cpu,内存,网卡流量等 创建监控项 选择添加你要监控的项 查看你监控的项

在zabbix上添加tcp连接数的监控项

搭建一个zabbix监控服务,但是zabbix上没有默认的模板对tcp连接数的监控.后去网上搜索好多文章都没有一个完成的操作步骤,可能本人还是小白吧. 以下详细写下本人的操作步骤. 1.检查安装包和了解zabbix对tcp连接数的监控配置过程. zabbix的服务器端和客户端的安装就不再累述了,直接说本次操作过程(该过程以RPM为例,源码包更简单). a.客户端上必须的安装包:zabbix-agent.zabbix-sender.zabbix-get和zabbix-web可以不用安装. b.了解

zabbix添加Tomcat监控

参靠了网上一些关于zabbix添加Tomcat的监控配置,自己整理了下: 一.服务器端配置1.找到zabbix源码存放路径 # find / -name zabbix_java #/usr/local/src/zabbix-2.2.6/src/zabbix_java 2.安装Zabbix-Java-gateway # cd /usr/local/src/zabbix-2.2.6 # ./configure --enable-java --prefix=/usr/local/zabbix/zabb

Zabbix监控(一):添加主机Host和监控项Items

一.添加监控主机Host 1.默认已添加Zabbix服务器本机,对自身状态进行监控,应用了Linux和Zabbix Server两个模板: 2.点击右侧的Creat host添加监控主机,Groups可在右侧选择一个或在New group中创建一个: 3.在Templates项中添加模板,windows系统的就选择Template OS Windows模板,添加并保存: 4.监控主机HV01如果安装配置好zabbix agent的话,过一会Z(Zabbix)图标变绿,表示监控正常: 5.如果Z图