zoukankan      html  css  js  c++  java
  • 监控LVS

    监控LVS

    #!/usr/bin/python-2.6.6
    #data 2017-10-17
    #auth liuchao
    import commands,os,time
    #------------------------------------------------
    zabbix_agent_file='/etc/zabbix/zabbix_agentd.conf'
    keepalived_vip=['192.168.41.157']
    tmp_file_path='/tmp/lvs_status.txt'
    zabbix_server_port=10051
    timestamp=int(time.time())
    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()
    #------------------------------------------------
    def monit_lvs():
            lvs_packets_sec=commands.getstatusoutput('''tail -n 1 /proc/net/ip_vs_stats | awk '{print strtonum("0x"$1),strtonum("0x"$2),strtonum("0x"$3),strtonum("0x"$4),strtonum("0x"$5)}
    ' |awk '{print $2}' ''')[1]
            lvs_bit_sec=commands.getstatusoutput('''tail -n 1 /proc/net/ip_vs_stats | awk '{print strtonum("0x"$1),strtonum("0x"$2),strtonum("0x"$3),strtonum("0x"$4),strtonum("0x"$5)}' |a
    wk '{print $4}' ''')[1]
            lvs_conns_sec=commands.getstatusoutput('''awk 'END{print NR-1}' /proc/net/ip_vs_conn | awk '{print $1}' ''')[1]
            lvs_keepalived_vip_status=commands.getstatusoutput('/sbin/ip addr |grep %s |wc -l' %keepalived_vip[0])[1]
            if int(lvs_keepalived_vip_status) != 0:
                    status,result_ip=commands.getstatusoutput('''echo %s |awk -F '.' '{print $NF}' ''' %keepalived_vip[0])
                    try:
                            lvs_keepalived_vip_status=int(result_ip)
                    except:
                            pass
            with open(tmp_file_path,'wb') as f:
                    f.write('%s %s %s %s
    '%(zabbix_hostname,'lvs_packets_sec',timestamp,lvs_packets_sec))
                    f.write('%s %s %s %s
    '%(zabbix_hostname,'lvs_bit_sec',timestamp,lvs_bit_sec))
                    f.write('%s %s %s %s
    '%(zabbix_hostname,'lvs_conns_sec',timestamp,lvs_conns_sec))
                    f.write('%s %s %s %s
    '%(zabbix_hostname,'lvs_keepalived_vip_status',timestamp,lvs_keepalived_vip_status))
    #-----------------------------------------------------
    if __name__=='__main__':
            monit_lvs()
            send_data_cmd='/usr/bin/zabbix_sender -vv -z %s -p %s -T -i %s' %(zabbix_server,zabbix_server_port,tmp_file_path)
            #print send_data_cmd
            os.popen(send_data_cmd)
  • 相关阅读:
    python读写操作(txt, mat, xls, etc文件)
    开发linux版QQ就是支持未来的国产操作系统
    为知笔记linux绿色版的快速调用
    数学物理中的常见误区
    markdown语法小结
    信息爆炸时代的知识获取
    matlab: 数据的读写
    APS期刊投稿准备: REVTex格式
    markdown基本语法
    常见的数学关系
  • 原文地址:https://www.cnblogs.com/liuchaogege/p/8074050.html
Copyright © 2011-2022 走看看