zabbix 监控LVS(实例)

简介: /etc/zabbix/zabbix_agentd.confUnsafeUserParameters=1UserParameter=ipvsadm.activeconn[],/etc/zabbix/ipvsadm.

/etc/zabbix/zabbix_agentd.conf

UnsafeUserParameters=1
UserParameter=ipvsadm.activeconn[],/etc/zabbix/ipvsadm.py active 12 3 UserParameter=ipvsadm.inactconn[*],/etc/zabbix/ipvsadm.py inactive1 23
UserParameter=ipvsadm.weight[
],/etc/zabbix/ipvsadm.py weight 12 $3
UserParameter=ipvsadm.discovery,/etc/zabbix/ipvsadm_discover.sh

vi /etc/zabbix/ipvsadm_discover.sh

!/bin/bash

SVC_FLG=1
END_FLG=0
IFS=$'\n'

echo '{"data":['

for LINE in sudo /usr/sbin/ipvsadm -Ln
do

echo ${LINE}

    TYPE=`echo ${LINE} | awk '{print $1}'`
    IP_INFO=`echo ${LINE} | awk '{print $2}'`
    if [ ${END_FLG} != 0 ] ; then
            echo ", "
            END_FLG=0
    fi
    if [ "${TYPE}" = "TCP" -o "${TYPE}" = "UDP" ] ; then
            CUR_TYPE=${TYPE}
            CUR_IP_INFO=${IP_INFO}
            SVC_FLG=0
    elif [ "${TYPE}" = "->" -a ${SVC_FLG} = 0 ] ; then
            echo -n "{\"{#VTYPE}\":\"${CUR_TYPE}\",\"{#VIPINFO}\":\"${CUR_IP_INFO}\",\"{#RIPINFO}\":\"${IP_INFO}\"}"
            END_FLG=1
    fi

done
echo "]}"

vi /etc/zabbix/ipvaadm.py

!/bin/env python

-- coding: utf-8 --

usage: ipvsadm.py acctiveconn tcp 172.18.0.12:80 172.17.0.22:80

import sys

def parserArgs(args):
p = dict()
if args[1] not in ('active', 'inactive', 'weight') :
print 'type error'
sys.exit(1)
p['type'] = args[1]
p['proto'] = args[2].upper()
vip = args[3].split(':')
p['vipHex'] = ipToHexStr(vip[0])
p['vipPort'] = '%04X' % int(vip[1])
rip = args[4].split(':')
p['ripHex'] = ipToHexStr(rip[0])
p['ripPort'] = '%04X' % int(rip[1])
#print p
return p

def ipToHexStr(ip):
buf=list()
for i in ip.split('.'):
buf.append('%02X' % int(i))

return "".join(buf)

def findData(args):
vip = "%s %s:%s" % (args['proto'], args['vipHex'], args['vipPort'])
rip = " -> %s:%s" % (args['ripHex'], args['ripPort'])
vipStr = None
result = None
for line in file("/proc/net/ip_vs"):
if line.startswith(vip):
vipStr = True
continue
if vipStr is True and line.startswith(rip):
break
# -> AC110016:0050 Masq 1 10 157
import re
values = re.split('\s+', line)
#print values
# ['', '->', 'AC110016:0050', 'Masq', '1', '0', '0', '']
result = dict()
result['weight'] = values[4]
result['active'] = values[5]
result['inactive'] = values[6]
return result[args['type']]

if name == "main":
args = parserArgs(sys.argv)
print findData(args)

导入模板 zb_template.xml

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.2</version>
<date>2018-12-21T02:33:10Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template App LVS</template>
<name>Template App LVS</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>LVS</name>
</application>
</applications>
<items/>
<discovery_rules>
<discovery_rule>
<name>ipvsadm Service</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>ipvsadm.discovery</key>
<delay>30</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>Active Connections on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.activeconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
<item_prototype>
<name>InActive Connections on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.inactconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
<item_prototype>
<name>Balance Weight on {#RIPINFO} for {#VIPINFO} {#VTYPE}</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
<delay>30</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>LVS</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Template App LVS:ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}].last()}<1</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>No Weight to {#RIPINFO}</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes>
<graph_prototype>
<name>Balance Weight {#RIPINFO} for {#VIPINFO} {#VTYPE}</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>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.weight[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
<graph_prototype>
<name>Connections Statictics on {#RIPINFO} for {#VIPINFO} {#VTYPE}</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>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.activeconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>2774A4</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template App LVS</host>
<key>ipvsadm.inactconn[{#VTYPE},{#VIPINFO},{#RIPINFO}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>

目录
相关文章
|
3月前
|
监控 安全 Linux
在Linux中,zabbix如何监控脑裂?
在Linux中,zabbix如何监控脑裂?
|
15天前
|
SQL 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
51 7
|
1月前
|
SQL 监控 数据库
OceanBase社区版可以通过Zabbix监控
【10月更文挑战第5天】随着OceanBase社区版的广泛应用,企业纷纷采用这一高性能、高可用的分布式数据库系统。为了确保系统的稳定运行,使用成熟的Zabbix监控工具进行全面监控至关重要。本文通过具体示例介绍了如何配置Zabbix监控OceanBase,包括安装配置、创建监控模板和监控项、编写脚本、设置触发器及图形展示等步骤,帮助读者快速上手,及时发现并解决问题,确保业务始终处于最佳状态。
48 2
|
2月前
|
监控 关系型数据库 MySQL
zabbix agent集成percona监控MySQL的插件实战案例
这篇文章是关于如何使用Percona监控插件集成Zabbix agent来监控MySQL的实战案例。
55 2
zabbix agent集成percona监控MySQL的插件实战案例
|
3月前
|
SQL 监控 分布式数据库
【解锁数据库监控的神秘力量!】OceanBase社区版与Zabbix的完美邂逅 —— 揭秘分布式数据库监控的终极奥秘!
【8月更文挑战第7天】随着OceanBase社区版的普及,企业广泛采用这一高性能、高可用的分布式数据库。为保障系统稳定,使用成熟的Zabbix监控工具对其进行全方位监控至关重要。本文通过实例介绍如何在Zabbix中配置监控OceanBase的方法,包括创建监控模板、添加监控项(如TPS)、设置触发器及图形展示,并提供示例脚本帮助快速上手。通过这些步骤,可以有效监控OceanBase状态,确保业务连续性。
102 0
|
5月前
|
监控 数据库 Docker
Zabbix监控神通数据库教程
**摘要:** 本文介绍了如何使用Docker安装和配置神舟通用数据库,并利用Zabbix进行监控。首先,通过Docker安装数据库镜像,启动容器并映射端口。接着,使用默认凭证连接数据库并验证安装。然后,将数据库的Python模块和库文件复制到主机,并安装Python3.5及相应模块,创建外部检查脚本以实现Zabbix的监控功能。示例展示了查询数据库版本的监控指标配置。最后,提到了监控结果的界面展示,并邀请读者探索更多Zabbix监控技巧。
85 0
Zabbix监控神通数据库教程
|
4月前
|
监控 关系型数据库 应用服务中间件
Linux zabbix监控 软件的安装
Linux zabbix监控 软件的安装
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
1119 0
|
2月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
72 8
LVS+Keepalived 负载均衡
|
2月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
63 5