zabbix替代smokeping的解决方案
最近要部署smokeping,想使用nginx的fastcgi的方式来部署,结果perl的执行的效率真是大失所望,就想用zabbix来实现smokeping。
python 环境2.6
参考的zabbix 社区
https://www.zabbix.com/forum/showthread.php?t=31147
实现的原理使用zabbix_sender主动向zabbixserver发送数据,zabbix就能采集到数据啦
文件清单:
all create_graph.py create_other_screen.py define monitor.py zbxsmokepingprimary zbx_export_templates.xml
文件说明:
all: 所要监控ip地址池,这个文件monitor.py和create_graph.py都会在这里读取ip,create_graph.py是个多线程的脚本用于发送all的所有ip到zabbixserver,monitor.py去读取all文件的ip生成所需要监控的主
define: 定义客户的ip地址,这个文件会被create_create_other.py读取,create_other_screen.py实现读取define文件中的ip地址实现自动生成带客户screen,手动生成的话会该觉很头痛
zbxsmokepingprimary: 是外部的执行的脚本需要在zabbix_server设置
zbx_export_templates.xml 模版文件
设置的选项:
zabbix_server:
开启这个选项ExternalScripts=/usr/local/share/zabbix/externalscripts
zbxsmokepingprimary
ZBXSERVER:zabbix服务器的ip地址
FPING:fping的位置
ZBXSENDER:zabbix_sender的位置
zabbix主机监控有个类型为external check 选项会去执行 zbxsmokepingprimary这个脚本,这个脚本需要有执行的权限
monitor.py和create_other_screen.py需要修改的zabbix url地址,帐号和密码
create_graph.py:
num_threads=10 设置初始化的线程个数,ip多的话初始线程可以跟ip个数相等
软件包:
supervisor:python的程序,监控脚本,使之一直运行,supervisor需要执行的文件为create_graph.py,这个就相当于守护进程来使用
pyzabbix:python连接zabbix的api
monitor.py 代码:
#!/usr/bin/env pythonimport pyzabbixclass zabbix(object):def __init__(self):self.all=open('all')def _login(self):zapi= pyzabbix.ZabbixAPI('url') #your zabbix urlzapi.login('user','password') # you zabbix user and password the user have write privilegereturn zapidef _get_template(self):temp=self._login().template.get(output='extend',filter={'host':'Template_SmokePrimary'})return temp[0]['templateid']def _get_group(self):if not self._login().hostgroup.exists(name='ping_check'):self._login().hostgroup.create(name='ping_check')group=self._login().hostgroup.get(output='extend',filter={'name':'ping_check'})return group[0]['groupid']def _create_host(self):for x in self.all:if not self._login().host.exists(host=x.strip()):try:self._login().host.create(host=x.strip(),interfaces={"type":1, "main":1, "useip":1, "ip":"127.0.0.1","dns":"","port":"10050"},groups={"groupid":str(self._get_group())},templates={"templateid":str(self._get_template())},)except Exception,e:print edef main(self):
# self._get_group()
# self._get_template()self._create_host()if __name__ == '__main__':a=zabbix()a.main()
create_other_screen.py代码:
#!/usr/bin/env pythonimport pyzabbix
import reclass zabbix(object):def __init__(self):self.define=open('define')self.dynamic=0self.columns=2for x in self.define:self.name=x.strip()break #the first line is you screen's namedef _login(self):zapi= pyzabbix.ZabbixAPI('url') #you zabbix server urlzapi.login('admin','zabbix') #your zabbix user and passwordreturn zapidef _get_host(self):host_ids=[]for x in self.define:if not re.search('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',x.strip()):continueif self._login().host.exists(host=x.strip()):hosts=self._login().host.get(filter={'host':[x.strip()]})host_ids.append(hosts[0]['hostid'])return host_idsdef _get_graph(self):graph_ids=[]for x in self._get_host():graph=self._login().graph.get(hostids=x)graph_ids.append(graph[0]['graphid'])graph_list=[]x = 0y = 0 for graph in sorted(graph_ids):graph_list.append({"resourcetype":'0',"resourceid": graph,"width": "600","height": "100","x": str(x),"y": str(y),"colspan": "0","rowspan": "0","elements": "0","valign": "0","halign": "0","style": "0","url": "","dynamic": str(self.dynamic)})x += 1if x == int(self.columns):x = 0y += 1 return graph_list def _get_screen(self):id=self._login().screen.get(output='extend',filter={'name':self.name})return id[0]['screenid'] def _create_screen(self): if self._login().screen.exists(name=self.name):self._login().screen.delete(str(self._get_screen()))#return 0graphids=self._get_graph()columns = int(self.columns)if len(graphids) % self.columns == 0:vsize = len(graphids) / self.columnselse:vsize = (len(graphids) / self.columns) + 1self._login().screen.create(name=self.name,hsize=self.columns,vsize=vsize,screenitems=graphids) def main(self):
# self._get_graph()
# self._get_screen()self._create_screen()if __name__ == '__main__':a=zabbix()a.main()
create_graph.py 代码
#!/usr/bin/env pythonimport subprocess
from threading import Thread
from Queue import Queue
import timef=open('all')
d=[]
for x in f:d.append('/usr/local/share/zabbix/externalscripts/zbxsmokepingprimary %s 10 1000 32 %s' % (x.strip(),x.strip()))queue=Queue()
def do(i,q):while True:a=q.get()ret=subprocess.call(a,shell=True)q.task_done()num_threads=10 #init thread numberfor i in range(num_threads):worker = Thread(target=do,args=(i,queue))worker.setDaemon(True)worker.start()for x in d:queue.put(x)queue.join()time.sleep(3)
我这边对于主机在screen中没有排序,每个人的需求可能不同
下面附上脚本文件,软件包需要自己去下载。。。。。
下面是我在百度和163域名解析到的ip地址生成的图片
转载于:https://blog.51cto.com/8831068/1416320
zabbix替代smokeping的解决方案相关推荐
- Zabbix通过Smokeping检测网络质量并告警
(一)Smokeping概述 smokeping是rrdtool的作者TobiOetiker的作品,用Perl语言写的,主要是监视网络性能,如:延时,丢包率,是否BGP多线等.它在图形显示方面有很大优 ...
- zabbix 企业级网络监控解决方案
Zabbix是一个基于WEB界面的提供分布式系统监控以及网络监控功能的企业级的开源解决方案zabbix能监控各种网络参数,保证服务器系统的安全运营,并提供灵活的通知机制以让系统管理员快速定位/解决存在 ...
- 海外反欺诈解决方案专家ADVANCE.AI与印度尼西亚第一家替代信用评分提供商SDB达成战略合作
海外反欺诈解决方案专家ADVANCE.AI 与Tokopedia 旗下的创新信用评分 (ICS) 服务提供商 Semangat Digital Bangsa (SDB) 签署战略合作协议. 通过此次合 ...
- MKS上游和下游集成式压力控制器的技术分析及其替代解决方案
摘要:目前的MKS系列集成式压力控制器本质上是一种流量调节和测量装置,无法直接用来进行准确的压力控制,而且MKS压力控制器还存在测量精度不高.压力控制范围有限和对工作介质洁净度要求很高的不足.为此,为 ...
- 从Zabbix到Prometheus,同程艺龙数据库监控系统的实践
来自:DBAplus社群 作者介绍 闫晓宇,同程艺龙数据库技术专家,具有多年互联网行业DB运维经验,在游戏.O2O及电商行业从事过DBA运维工作.2016年加入同程艺龙,目前在团队负责数据库架构设计及 ...
- linux监控平台介绍、zabbix监控介绍、安装zabbix
linux监控平台介绍 常见开源监控软件 cacti.nagios.zabbix.smokeping.open-falcon 等等. nagios和zabbix流行度很高. cacti.smokepi ...
- Linux监控平台搭建( zabbix监控)
2019独角兽企业重金招聘Python工程师标准>>> Linux监控平台搭建( zabbix监控) 一.Linux监控平台介绍 1.监控存在的原因 站点出了问题,没有人知道,等用户 ...
- zabbix监控部署
zabbix zabbix概念 对于运维人员来说,监控是非常重要的,想要保证线上业务整体能够稳定运行,那么我们就需要实时关注与其相关的各项指标是否正常.一个业务系统背后,往往存在着很多服务器.网络 ...
- 19.1 Linux监控平台介绍;19.2 zabbix监控介绍;19.3,19.4 安装zabbi
19.1 Linux监控平台介绍 常见开源监控软件: 1. cacti.nagios.zabbix.smokeping.open-falcon等等 2. cacti.smokeping偏向于基础监控, ...
最新文章
- 总结 | 一些关于 CPU 的基本知识
- oracle 分区表
- 开始学习RED HAT LINUX了
- 框架-.NET:Spring.Net
- linux安装的mysql没有密码_linux系统安装的mysql数据库root帐户密码忘记的两种处理方法...
- mysql 命令 不对齐,MySQL中自己不太常用的命令
- 16-CoreData之多表关联(存储自定义数据模型)
- Px4源码框架结构图
- 2019ICPC(银川) - Delivery Route(强连通缩点+分块最短路)
- Direct X 修复
- java file数组 初始化_Java之处理数组
- Win系统 - 开启 WIN10 隐藏的卓越性能模式
- 凌晨起来肝的一篇 Java 学习路线,保证学弟学妹们大三大四的时候顺利找到实习 Offer
- 对python random模块的认识_Python学习_random模块使用
- 数据结构算法之数组篇
- qrcode 生成二维码不显示图片解决办法
- Spring Boot电商项目57:订单模块六:【前台:生成支付二维码】接口;(支付url的拼凑;利用zxing生成二维码;二维码图片的存储;真实地址与可访问地址的转换;)
- Hive之——数据定义
- 【牛客】幸运数字II题解
- Mac 电脑安装putty