用来衡量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,如需转载请自行联系原作者