This article only says LVs monitoring,lvs+keepalived deployment, please refer to my additional article.
http://yangrong.blog.51cto.com/6945369/1575909
1, monitoring objectives
number of Session connections per second for LVs
number of packet forwards per second for LVs
LVS Forwarding bandwidth per second
VIP Switching Situation
survival of the keepalived process
2,Zabbix_senderReporting Scripts
Main report content:
number of Session connections, packet forwarding per second, forwarding bandwidth per second , VIP Value
monitor Python scripts, using Zabbix_sender escalation methods:
# cat/usr/local/lvsmonitor/lvs_status_sender.py#!/usr/bin/env python#coding=utf-8#date 2015-7-8 #auth :yangr#function: report the relevant status of LVS, the number of connections per second, the number of forwards per second, VIP switch. Forward bandwidth per second #lvs_conns_sec,lvs_packets_sec,keepalived_vip _status import os,commands,sys,time# variable Definition----------------------#从zabbix_agentd. conf get server IP or hostnamezabbix_agent_file= '/usr/local/zabbix/etc/zabbix_agentd.conf ' if notos.path.exists (zabbix_agent_ File): sys.exit (4) Zabbix_server=commands.getstatusoutput ( ' grep ' ^serveractive ' %s|awk -F[=] ' {print $2} ' '%zabbix_agent_file ' [1].strip () Zabbix_hostname=commands.getstatusoutput (' grep ' ^hostname ' %s|awk -F[=] ' {print $2} ' "%zabbix_agent_file" [1].strip () if not zabbix_server or notzabbix_hostname: sys.exit () Zabbix_server_port=10051timestamp = int ( Time.time ()) Keepalived_vip=[' 192.168.1.100 '] #指定VIPtmp_file_path = '/tmp/lvs_status.txt ' #指定监控值输出文件 #--------- ---------------- def monit_lvs (): #获取每秒包转发数 status,lvs_packets_sec=commands.getstatusoutput ("' Tail -1/proc/net/ip_vs_stats | /usr/bin/awk ' {print strtonum ("0x"), Strtonum ("0x"), strtonum ("0x"), strtonum ("0x" $4), Strtonum ("0x" $)} ' |awk ' {print $2} ' ') #获取每秒转发的流量 status,lvs_bit_sec=commands.getstatusoutput ("' tail -1/proc/net/ip_vs_stats | /usr/ bin/awk ' {print strtonum ("0x"), Strtonum ("0x" $), strtonum ("0x" $), Strtonum ("0x" $4), Strtonum ("0x")} ' |awk ' {print $4} ' ') # Gets the number of LVS session connections &Nbsp; status,lvs_conns_sec=commands.getstatusoutput (' Wc -l/proc/net/ip_vs_ Conn ') #获取VIP状态, if the value is not 0 is master, 0 is backup, if there is a change, it is switched status,lvs_keepalived_vip_status=commands.getstatusoutput ('/ Sbin/ipaddr |grep %s |wc -l '%keepalived_vip[0]) #如果本机有VIP, The last decimal of the VIP is removed. if int (lvs_keepalived_vip_status) != 0: status,result_ip=commands.getstatusoutput (' echo%s|awk -F ') ' {print $NF} ' '%keepalived_vip[0]) try: &nbsP; lvs_keepalived_vip_status =int (RESULT_IP) except: pass #把 key Value information is written to a temporary file in the format hostname,key,timestamp,value with open (Tmp_file_path, ' WB ') as f: F.write ('%s %s %s %s\n '% (zabbix_hostname, ' lvs_packets_sec ', timestamp,lvs_packets_sec) F.write ('%s %s %s %s\n '% (zabbix_hostname, ' lvs_bit_sec ', timestamp,lvs_bit_sec) f.write ('%s %s %s %s\n '% ( Zabbix_hostname, ' lvs_conns_sec ', timestamp,lvs_packets_sec)) f.write ('%s %s %s %s\n '% ( Zabbix_hostname, ' Lvs_keepalived_vip_status ', timestamp,lvs_keepalived_vip_status)) if __name__= = ' __main__ ': monit_lvs () #把临时文件通过zabbix_sender命令发送到server端 send_data_cmd= '/usr/local/zabbix/bin/zabbix_sender -vv -z %s-p %s -t -i %s '% (zabbix_server,zabbix_server_port,tmp_file_path) #print  SEND_DATA_CMD &NBsp; os.popen (Send_data_cmd)
Scheduled Task settings:
#crontab-l#zabbix_sender Reporting LVS Monitoring information * * * * */usr/bin/python/usr/local/lvsmonitor/lvs_status_sender.py >>/var/ Log/crontab.log2>&1
3,Zabbix ServerEnd Monitoring item configuration:
Lvs_packets_sec,
Lvs_bit_sec,
Lvs_conns_se,
Lvs_keepalived_vip_status,
Keepalived,
Create a lvs monitoring template in Zabbix, creating five names, such as the monitoring entries above, as shown in the key values:
3.1) the item configuration Diagram in the LVS monitoring template
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/DF/wKioL1WseKLCe8l3AADSl4fZa3E281.jpg "style=" float: none; "title=" QQ picture 20150720121841.png "alt=" Wkiol1wseklce8l3aadsl4fza3e281.jpg "/>
3.2) tragger configuration diagram in the LVS monitoring template
Alarm settings for three monitoring items here
1) VIP has a change, whether from there to nothing or from scratch, there is a change in the representative of the switch, then the alarm
2) keepalived process down alarm
3) LVs per second forwarding request greater than 5W, alarm (this according to the actual situation, if far higher than the normal request value, representing a CC attack)
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/E2/wKiom1WsdsGCWTgDAACoMLJ3z5k423.jpg "title=" QQ picture 20150720121845.png "style=" Float:none; "alt=" wkiom1wsdsgcwtgdaacomlj3z5k423.jpg "/>
When everything is set up, you can create a monitoring host, invoke the LVS monitoring template, and see if the data gets correct.
If you have any questions, please leave a message.
This article is from the "Yang Cloud" blog, please be sure to keep this source http://yangrong.blog.51cto.com/6945369/1676312
Zabbix monitoring LVs status and keepalived VIP drift