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

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
回复 支持 反对

使用道具 举报

70

主题

82

帖子

306

积分

中级会员

Rank: 3Rank: 3

积分
306
HaroImpera 发表于 2017-9-18 00:34:09 | 显示全部楼层
Viagra Rezeptfrei Per Uberweisung  cialis price Viagra Barata  
Vt Logistics Singapore Viagra Levitra Tab  
Epivir  <a href=http://cialtobuy.com >online pharmacy</a> Antibiotics Canada Over The Counter
回复 支持 反对

使用道具 举报

70

主题

82

帖子

306

积分

中级会员

Rank: 3Rank: 3

积分
306
HaroImpera 发表于 2017-10-4 19:19:59 | 显示全部楼层
Amoxicillin Discard After One Year Levitra 20 Mg Euro Pharmacy Online  generic levitra professional Cialis Interacciones Medicamentosas  
回复 支持 反对

使用道具 举报

70

主题

82

帖子

306

积分

中级会员

Rank: 3Rank: 3

积分
306
HaroImpera 发表于 2017-10-12 04:45:58 | 显示全部楼层
Comprar Levitra Paypal  buy viagra Viagra Generico Effetti Collaterali Propecia Online Price Viagra Sin Receta Valencia  
回复 支持 反对

使用道具 举报

13

主题

24

帖子

81

积分

注册会员

Rank: 2

积分
81
MiguSlatte 发表于 2017-10-12 13:17:23 | 显示全部楼层
Prix Du Levitra 10 Mag Cialis Ohne Rezept  buygenericlevitraonlineusa Is Disulfiram Approved In Canada Viagra Without A Pres Himcospaz  
回复 支持 反对

使用道具 举报

13

主题

24

帖子

81

积分

注册会员

Rank: 2

积分
81
MiguSlatte 发表于 2017-10-29 19:50:34 | 显示全部楼层
Cephalexin And Tendons Levitra 5 Mg Preis  levitra non prescription Discount Fedex Stendra Overseas  
回复 支持 反对

使用道具 举报

13

主题

24

帖子

81

积分

注册会员

Rank: 2

积分
81
MiguSlatte 发表于 2017-10-29 19:51:06 | 显示全部楼层
Best Place To Buy Viagara Levitra Medicament 20mg Fda Approved Canadian Pharmacies  levitra online Amitiptyline Without Prescription In Uk Levitra Free Coupon  
回复 支持 反对

使用道具 举报

0

主题

276

帖子

556

积分

高级会员

Rank: 4

积分
556
chenyingying 发表于 2017-11-3 13:52:20 | 显示全部楼层
north face jackets
burberry scarves
mbt outlet
ugg outlet
moncler outlet
giuseppe zanotti sneakers
christian louboutin uk
cheap jordan shoes
soccer jerseys
michael kors uk
cheap jordan shoes
ugg schweiz
carrera sunglasses
nike uk
ugg boots
uggs classic boots
coach factory online
moncler dunjacka
coach outlet
north face jackets
tory burch outlet
kate spade outlet
d&g sunglasses
coach wallets
christian louboutin outlet
cheap nhl jerseys
hermes birkin bag
ugg boots
ugg outlet
cheap nfl jerseys
ugg outlet store
coach outlet
nike running uk
ugg boots
coach bags
ray ban sunglasses outlet
ralph lauren polo shirts
michael kors outlet
canada goose outlet
doudoune canada goose
coach factory outlet
cheap jordans
fitflops shoes
hermes belt outlet
kate spade outlet online
chicago blackhawks jersey
cheap ray ban sunglasses
manolo blahnik outlet
uggs outlet
true religion jeans
oakley sunglasses cheap
tory burch outlet
coach outlet online 70% off
michael kors
cheap oakley sunglasses
adidas outlet clearance
polo ralph lauren
montblanc pen
ray ban sunglasses
cheap nfl jerseys
fitflops sale clearance
coach factory outlet online
longchamp handbags
oakley sunglasses outlet
burberry scarf
cheap ray ban sunglasses
canada goose outlet
ugg outlet
michael kors outlet clearance
coach outlet online
ralph lauren outlet
canada goose nederland
nike jordans
coach outlet 70% off
nike air max
uggs uk
ugg factory outlet
nike nfl jerseys
longchamp bags
adidas wings
ugg outlet
north face outlet
air jordan pas cher
coach outlet online
ugg sale
louis vuitton
pandora charms
air max thea
air max 90
canada goose jackets
coach outlet
michael kors outlet clearance
nike store
converse shoes
longchamp outlet store
cheap ugg boots
north face clearance
ugg outlet online
ugg boots
oakley vault
chenyingying20171103
回复 支持 反对

使用道具 举报

70

主题

82

帖子

306

积分

中级会员

Rank: 3Rank: 3

积分
306
HaroImpera 发表于 2017-11-17 05:54:43 | 显示全部楼层
Amoxicillin Uses Diarrhea Discount Propecia Without A Prescription Best Non Prescription Viagra  buy viagra online Mark Levin Viagra Secure Ordering Bentyl  
回复 支持 反对

使用道具 举报

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

本版积分规则

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