zabbix server update监控

简介:

 用来衡量zabbix server和proxy的update 性能,在数据delay比较严重的时候,update percent会比较低。可以做成item用来监控性能。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import  MySQLdb
import  sys
import  time
class  dbUtil:
         def __init__(self,host,user,passwd,db):
                 self.host = host
                 self.user = user
                 self.passwd = passwd
                 self.db = db
         def db_connect(self):
                 self.conn = MySQLdb.connect(host=self.host,user=self.user,passwd=self.passwd,db=self.db)
                 self.cursor = self.conn.cursor()
         def db_fetch_one(self,sql):
                 self.cursor.execute(sql)
                 try :
                         result = float(self.cursor.fetchone()[ 0 ])
                 except:
                         result =  "-1"
                 return  result
         def db_close(self):
                 self.cursor.close()
                 self.conn.close()
def getData(sql):
         #print sql
         conn = dbUtil(ip,user,password,db)
         conn.db_connect()
         re = conn.db_fetch_one(sql)
         return  re
         conn.db_close()
def getPercent(hostname):
         if  hostname ==  "server_hostname" :
                 sql =  "" " select round(a.aa* 100 /b.bb, 2 ) from
       (select count(*)  as  aa from items
         where lastclock > UNIX_TIMESTAMP()- 1800  and delay <  900
             and hostid  in  (select hostid from hosts where status= 0 )
             and status =  0
       ) a,
       (select count(*)  as  bb from items
         where delay <  900  and status =  0
             and hostid  in  (select hostid from hosts where status= 0 )
        ) b "" "
                 print getData(sql)
         else :
                 hostsql=  "select hostid from hosts where host='%s'"  % (hostname)
                 hostid = getData(hostsql)
                 sql =  "" " select round(a.aa* 100 /b.bb, 2 ) from
       (select count(*)  as  aa from items
         where lastclock > UNIX_TIMESTAMP()- 1800  and delay <  900
             and hostid  in  (select hostid from hosts where status= 0  and proxy_hostid = %s)
             and status =  0
       ) a,
       (select count(*)  as  bb from items
         where delay <  900  and status =  0
             and hostid  in  (select hostid from hosts where status= 0  and proxy_hostid = %s)
        ) b "" " % (hostid,hostid)
                 print getData(sql)
if  __name__ ==  "__main__" :
         hostname = sys.argv[ 1 ]
         getPercent(hostname)


调用方法:

脚本 hostname.

监控配置文件:

UserParameter=zabbix_percent[*],python /apps/sh/zabbix_scripts/zabbix/zabbix_percent.py $1


本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1344832,如需转载请自行联系原作者
相关文章
|
3月前
|
存储 SQL 监控
修改Zabbix源码实现监控数据双写,满足业务需求!
虽然对接Elasticsearch后有诸多好处,但是它不往数据库写历史数据了,同时还不再计算趋势数据了。有这么一个场景...
修改Zabbix源码实现监控数据双写,满足业务需求!
|
4月前
|
数据采集 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
75 4
|
4月前
|
监控 关系型数据库 机器人
小白带你学习linux的监控平台zabbix
小白带你学习linux的监控平台zabbix
130 0
|
7月前
|
监控 安全 Shell
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
Zabbix Server trapper 命令注入漏洞,攻击者可通过特定Payload获取服务器执行权限。
100 1
|
7月前
|
监控 前端开发 JavaScript
Zabbix分布式监控Web监控
Zabbix分布式监控Web监控
76 0
|
6月前
|
监控 关系型数据库 MySQL
企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库
企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库
|
1月前
|
数据采集 监控 数据库
请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
【2月更文挑战第25天】请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
25 2
|
6月前
|
监控
zabbix如何添加自定义监控项
zabbix如何添加自定义监控项
247 0
|
2月前
|
监控 Cloud Native 关系型数据库
使用 Grafana 统一监控展示 - 对接 Zabbix
使用 Grafana 统一监控展示 - 对接 Zabbix
|
4月前
|
监控 Docker 容器
Zabbix【部署 03】zabbix-agent2安装配置使用(zabbix-agent2监控docker实例分享)
Zabbix【部署 03】zabbix-agent2安装配置使用(zabbix-agent2监控docker实例分享)
211 0

推荐镜像

更多