请选择 进入手机版 | 继续访问电脑版
查看: 464|回复: 1

Zabbix监控LVS状态及keepalived VIP漂移

34

主题

34

帖子

138

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
138
羊大仙 发表于 2015-12-10 20:19:53 | 显示全部楼层 |阅读模式

此文只说lvs监控,lvs+keepalived的部署,请参考我另外的文章。 

http://yangrong.blog.51cto.com/6945369/1575909

1、监控目标

   lvs的每秒会话连接数

   lvs的每秒包转发数

   lvs每秒转发带宽

   VIP切换情况

   keepalived进程的存活

 

2zabbix_sender汇报脚本

主要汇报内容:

会话连接数,每秒包转发数,每秒转发带宽,VIP

 

监控python脚本,采用zabbix_sender上报方式:

# cat/usr/local/lvsmonitor/lvs_status_sender.py
#!/usr/bin/env python
#coding=utf-8
#date 2015-7-8
#auth :yangr
#function:汇报lvs的相关状态,有每秒连接数,每秒转发数,VIP主从切换.每秒转发带宽
#lvs_conns_sec,lvs_packets_sec,keepalived_vip_status
 
import os,commands,sys,time
#变量定义----------------------
#从zabbix_agentd.conf中获取server IP或hostname
zabbix_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=10051
timestamp = int(time.time())
keepalived_vip=['192.168.1.100']  #指定VIP
tmp_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"$1),strtonum("0x"$2), strtonum("0x"$3), strtonum("0x"$4),strtonum("0x"$5)}'|awk '{print $2}' ''')
 
         #获取每秒转发的流量
         status,lvs_bit_sec=commands.getstatusoutput('''tail -1/proc/net/ip_vs_stats | /usr/bin/awk '{print strtonum("0x"$1),strtonum("0x"$2), strtonum("0x"$3),strtonum("0x"$4), strtonum("0x"$5)}'|awk '{print $4}' ''')
         #获取lvs会话连接数
         status,lvs_conns_sec=commands.getstatusoutput('wc -l/proc/net/ip_vs_conn')
         #获取VIP状态,如值非0为master,为0则是backup,如果有变动,则进行了切换
         status,lvs_keepalived_vip_status=commands.getstatusoutput('/sbin/ipaddr |grep %s |wc -l'%keepalived_vip[0])
    #如果本机有VIP,则取出VIP的最后一段十进制。
         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
         #把 key值信息写到一个临时文件,格式为 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
         os.popen(send_data_cmd)

 

定时任务设置:

#crontab -l
#zabbix_sender汇报lvs的监控信息
* * * * * /usr/bin/python/usr/local/lvsmonitor/lvs_status_sender.py >>/var/log/crontab.log2>&1

 

3zabbix server端监控项配置:

lvs_packets_sec,

lvs_bit_sec, 

lvs_conns_se,

lvs_keepalived_vip_status,

keepalived,

zabbix中创建一个lvs监控模板,创建五个名称如上的监控项,键值如下图所示:

 

 3.1) lvs监控模板中item配置图


 3.2) lvs监控模板中tragger配置图

此处对三个监控项进行报警设置

  1 VIP有变动,无论从有到无或从无到有,有变动代表发生了切换,则告警

  2 keepalived进程down掉告警

  3 lvs每秒转发请求大于5W,告警(这个依实际情况判断,如果远远高于正常请求值,代表有CC攻击)

wKiom1WsdsGCWTgDAACoMLJ3z5k423.jpg



一切设置好后,就可以创建一台监控主机,调用lvs监控模板,然后查看数据获取是否正确。

如有问题,欢迎留言。


本文出自 “楊雲” 博客,请务必保留此出处http://yangrong.blog.51cto.com/6945369/1676312

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

2411

主题

2699

帖子

7853

积分

论坛元老

Rank: 8Rank: 8

积分
7853
JamTrolley 发表于 2017-5-26 12:26:22 | 显示全部楼层
Buy Flagyl  Cheap Clomid Pills Prix Cialis 10 Mg Maroc Comment Prendre Kamagra  Implicane Online Buy Accutane Online Canada Generic Viagra Lowest Prices  Clomid Online Buy Cialis One Day Prix Comprar Viagra Sin Receta Propecia  Strattera To Buy Commenti Levitra Zithromax For Uti  Buy Generic Strattera Le Cialis Efficace Cialis Hello Big Boy Effect  How Much Is Nolvadex Baclofene Indication Sertralina Generic  Buy Lasix Overnight Shipping On Asthma Inhalers discount worldwide fedex shipping isotretinoin pills  Generic Propecia Cvs Cheapest Viagra Available Prescribed Ciprodex Otic And Amoxicillin  Generic Antabuse Cheap How Do I Buy Viagra Online Spain Cialis Coupons  Deltasone Online Pharmacy Viagra Ungesund Promethazine 25 Mg Tablet  Clomid Generic Viagra Echt Oder Falsch Manyfacturing Amoxicillin  Inderal Online Cheap Cialis 20 Mg Einnehmen Purchase Diflucan Online No Prescription  Buy Levitra 20mg Proscar Propecia Finasteride 5mg Cialis Rezeptfrei 5mg  Lasix Usa Blog Medication And Amoxicillin Peces De Colores Priligy  Propecia Website Tadalafil 20 Mg Softgel Priligy Euro  Cialis Online No Dapoxetina E Tadalafil Propecia After 5 Years Side Effects  Cialis On Line Robaxin 500 Onlike No Prescription Controindicazioni Propecia Finasteride  Cheap Kamagra No Rx Levitra Vasodilatador Dog Keflex Side Effects  Purchase Accutane Online Levitra Cost Uk Valor Propecia  Order Antabuse In Usa Viagra Senza Ricetta Roma Buy Zofran From Mexican Pharmacy  Purchase Alli Amoxicillin Vomiting shipped ups on line isotretinoin 10mg in usa  Propecia Tablets Buy Tuf 20 Softabs Cheap Acquista Viagra Line  Cheap Deltasone 40mg El Cialis Funciona Cialis Mode Emploi  How To Buy Kamagra Propecia Hipertension Priligy Crema  Purchase Alli Cialis Para Que Es Amoxicillin And Cat Eye  Online Priligy Discount Provera Amex Accepted Free Consultation Can You Buy Diflucan At Walmart  Vibramycin Sample Amoxicillin And Yeast Infection Cialis Diario 5 Mg  Buy Cheap Zoloft Pills Cialis 5mg No Prescription Buy Tadacip Uk  Accutane 80mg Baclofene Luxembourg Cephalexin No Perscriptions  Propranolol Overseas Pharmacy Se Puede Comprar Cialis En Farmacias Amoxicillin Age Weight Restrictions  By Cheap Amoxil Viagra Generic Very Very Cheap Kamagra En Jovenes  Generic Deltasone 20mg Vega H Can Amoxicillin Be Taken With Fluconazole  Priligy Pastillas Viagra Online Expressversand Antobiotics By Mail  Purchase Amoxil Propecia Und Viagra Priligy Originale Vendita On Line  Order Cheap Cytotec Baclofene Princeps Amoxicillin Capsule  Cheap Generic Vibramycin Kamagra Autorise En France Viagra Aus Der Turkei  Cost Of Kamagra Cialis 5 Mg Dosi Canada Drug Superstore  Generic For Cytotec Analysis Report On Amoxicillin Sodium Vendo Cialis Concepcion  Buy Prednisone 20mg Cephalexin Veterinary Cialis Brand Name Usa Price  Clomid Order Zoloft Fast Delivery Buy Fluoxetine 20mg In Canada  Viagra Free Trial Alli Avaibility Canada Drug Pharmacy  Purchase Priligy Kamagra Bristol
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表