三、Lvs的监控设置
1、目的
lvs负载均衡的各tcp和udp端口的连接数
2、简略实施步骤
zabbix的自定义脚本采集数据;
自定义模板文件
自定义screen显示
3、zabbix_agentd.conf配置增加
## 20121220 for lvs status
UserParameter=b11_80,/home/zabbix/lvs-connection.sh b11_80
UserParameter=b12_80,/home/zabbix/lvs-connection.sh b12_80
UserParameter=b31_40177,/home/zabbix/lvs-connection.sh b31_40177
UserParameter=b32_40177,/home/zabbix/lvs-connection.sh b32_40177
UserParameter=b31_40172,/home/zabbix/lvs-connection.sh b31_40172
UserParameter=b32_40172,/home/zabbix/lvs-connection.sh b32_40172
UserParameter=b31_40252,/home/zabbix/lvs-connection.sh b31_40252
UserParameter=b32_40252,/home/zabbix/lvs-connection.sh b32_40252
UserParameter=b31_40174,/home/zabbix/lvs-connection.sh b31_40174
UserParameter=b32_40174,/home/zabbix/lvs-connection.sh b32_40174
#20130204 for airtalk lvs
UserParameter=b191_4001,/home/zabbix/lvs-connection.sh b191_4001
UserParameter=b192_4001,/home/zabbix/lvs-connection.sh b192_4001
UserParameter=b31_4002,/home/zabbix/lvs-connection.sh b31_4002
UserParameter=b32_4002,/home/zabbix/lvs-connection.sh b32_4002
UserParameter=b191_4003,/home/zabbix/lvs-connection.sh b191_4003
UserParameter=b192_4003,/home/zabbix/lvs-connection.sh b192_4003
UserParameter=b195_3012,/home/zabbix/lvs-connection.sh b195_3012
UserParameter=b196_3012,/home/zabbix/lvs-connection.sh b196_3012
4、lvs-connection.sh脚本内容
#!/bin/bash
function b11_80 {
sudo ipvsadm -l -n | grep 192.168.10.11:80 |awk '{print $5+0}'
}
function b12_80 {
sudo ipvsadm -l -n | grep 192.168.10.12:80 |awk '{print $5+0}'
}
function b31_40172 {
sudo ipvsadm -l -n | grep 192.168.10.31:40172 |awk '{print $5+0}'
}
function b32_40172 {
sudo ipvsadm -l -n | grep 192.168.10.32:40172 |awk '{print $5+0}'
}
function b31_40177 {
sudo ipvsadm -l -n | grep 192.168.10.31:40177 |awk '{print $6+0}'
}
function b32_40177 {
sudo ipvsadm -l -n | grep 192.168.10.32:40177 |awk '{print $6+0}'
}
function b31_40174 {
sudo ipvsadm -l -n | grep 192.168.10.31:40174 |awk '{print $6+0}'
}
function b32_40174 {
sudo ipvsadm -l -n | grep 192.168.10.32:40174 |awk '{print $6+0}'
}
function b31_40252 {
sudo ipvsadm -l -n | grep 192.168.10.31:40252 |awk '{print $6+0}'
}
function b32_40252 {
sudo ipvsadm -l -n | grep 192.168.10.32:40252 |awk '{print $6+0}'
}
function b31_40177 {
sudo ipvsadm -l -n | grep 192.168.10.31:40177 |awk '{print $6+0}'
}
function b32_40177 {
sudo ipvsadm -l -n | grep 192.168.10.32:40177 |awk '{print $6+0}'
}
# airtalk tcp ports 4001-4003
function b191_4001 {
sudo ipvsadm -l -n | grep 192.168.10.191:4001 |awk '{print $5+0}'
}
function b192_4001 {
sudo ipvsadm -l -n | grep 192.168.10.192:4001 |awk '{print $5+0}'
}
function b31_4002 {
sudo ipvsadm -l -n | grep 192.168.10.31:4002 |awk '{print $5+0}'
}
function b32_4002 {
sudo ipvsadm -l -n | grep 192.168.10.32:4002 |awk '{print $5+0}'
}
function b191_4003 {
sudo ipvsadm -l -n | grep 192.168.10.191:4003 |awk '{print $5+0}'
}
function b192_4003 {
sudo ipvsadm -l -n | grep 192.168.10.192:4003 |awk '{print $5+0}'
}
# airtalk tcp port 3012
function b195_3012 {
sudo ipvsadm -l -n | grep 192.168.10.195:3012 |awk '{print $5+0}'
}
function b196_3012 {
sudo ipvsadm -l -n | grep 192.168.10.196:3012 |awk '{print $5+0}'
}
# Run the requested function
$1
脚本调试过程中用到的命令如下
去掉无用的行
ipvsadm -l -n |tail -n +4 | grep "\-"
统计tcp总连接数,如果http增加或者减少需要相应调整
ipvsadm -l -n |tail -n +4 | grep "\-" | head -4 |awk '{sum=sum+$5}END{print sum}'
统计udp总连接数,调整同上
ipvsadm -l -n |tail -n +4 | grep "\-" | tail -n +4 |awk '{sum=sum+$6}END{print sum}'
5、zabbix server端设置
主要为lvs_status模版文件,screen已经定义在其中
-
2.02013-08-12T05:16:54Z--Templates--navidog_lvs_statusnavidog_lvs_status--Templates--airtalk lvs connections-lvs_connection--- airtalk b31 tcp 4002 connections00b31_4002609036503001000--airtalk lvs connections
-- airtalk b32 tcp 4002 connections00b32_4002609036503001000--airtalk lvs connections
-- airtalk b191 tcp 4001 connections00b191_4001609036503001000--airtalk lvs connections
-- airtalk b191 tcp 4003 connections00b191_4003609036503001000--airtalk lvs connections
-- airtalk b192 tcp 4001 connections00b192_4001609036503001000--airtalk lvs connections
-- airtalk b192 tcp 4003 connections00b192_4003609036503001000--airtalk lvs connections
-- airtalk b195 tcp 3012 connections00b195_3012609036503001000--airtalk lvs connections
-- airtalk b196 tcp 3012 connections00b196_3012609036503001000--airtalk lvs connections
-- airtalk tcp 4001 connections1504001609036503001last("b191_4001") + last("b192_4001")000--airtalk lvs connections
-- b11 http connections00b11_80609036503001000--lvs_connection
-- b12 http connections00b12_80609036503001000--lvs_connection
-- b31 3.x tcp 40172 connections00b31_40172609036503001000--lvs_connection
-- b31 3.x udp 40174 connections00b31_40174609036503001000--lvs_connection
-- b31 3.x udp connections00b31_40252609036503001000--lvs_connection
-- b31 4.x udp connections00b31_40177609036503001000--lvs_connection
-- b32 3.x tcp 40172 connections00b32_40172609036503001000--lvs_connection
-- b32 3.x udp 40174 connections00b32_40174609036503001000--lvs_connection
-- b32 3.x udp connections00b32_40252609036503001000--lvs_connection
-- b32 4.x udp connections00b32_40177609036503001000--lvs_connection
--{navidog_lvs_status:b11_80.nodata(3m)}=1{HOSTNAME} b11 nginx down040-{navidog_lvs_status:b12_80.nodata(3m)}=1{HOSTNAME} b12 nginx down040-{navidog_lvs_status:4001.count(#3,1,"le")}=3{HOSTNAME} DM 4001 lower 1050-{navidog_lvs_status:4001.nodata(5m)}=1{HOSTNAME} DM 4001 nodata for 5 M040-{navidog_lvs_status:4001.count(#3,500,"ge")}=3{HOSTNAME} DM 4001 reached 500050-{navidog_lvs_status:b11_80.count(#3,15000."ge")}=3{HOSTNAME} lvs for b11 reached 15K !040-{navidog_lvs_status:b12_80.count(#3,15000."ge")}=3{HOSTNAME} lvs for b12 reached 15K !040--airtalk lvs status10002000.0000100.0000110100.00000.00000000--30C80000020-- navidog_lvs_statusb31_4002
-4000C800020-- navidog_lvs_statusb32_4002
-100000C8020-- navidog_lvs_statusb191_4001
-50C800C8020-- navidog_lvs_statusb191_4003
-2000C8C8020-- navidog_lvs_statusb192_4001
-60C8C800020-- navidog_lvs_statusb192_4003
-00C8C8C8020-- navidog_lvs_status4001
-70960000020-- navidog_lvs_statusb195_3012
-80009600020-- navidog_lvs_statusb196_3012
-LVS CONNECTIONS9002000.0000100.0000110100.00000.00000000--00C80000120-- navidog_lvs_statusb11_80
-1000C800120-- navidog_lvs_statusb12_80
-200000C8120-- navidog_lvs_statusb31_40177
-30C800C8120-- navidog_lvs_statusb32_40177
-40C8C8C8120-- navidog_lvs_statusb31_40252
-50000096120-- navidog_lvs_statusb32_40252
-6000C8C8120-- navidog_lvs_statusb31_40172
-70960000120-- navidog_lvs_statusb32_40172
-80C8C800120-- navidog_lvs_statusb31_40174
-90009600120-- navidog_lvs_statusb32_40174
-100960096020-- navidog_lvs_statusb195_3012
-110009696020-- navidog_lvs_statusb196_3012