标签:alt pytho filename print 使用率 ofo zha itemid add
说明:
#/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import xlsxwriter
import time
host_list = [‘192.168.164.131‘,
‘192.168.164.132‘
]
def sql_login(ip):
conn = MySQLdb.connect(host=‘192.168.164.131‘ ,port=3306, user=‘root‘, passwd=‘123456‘, db=‘zabbix‘)
cur = conn.cursor()
sql_context = "select itemid, FROM_UNIXTIME(clock, ‘%Y-%m-%d %H:%i:%S‘), value " "from history_uint where itemid = (select itemid from items where items.key_ = ‘tcpconn‘ " "and items.hostid = (select hostid from hosts where host = ‘" + ip + "‘)) and clock >= UNIX_TIMESTAMP(‘2016-04-22 18:00:00‘) and clock < UNIX_TIMESTAMP(‘2016-04-24 00:00:00‘)"
reCount = cur.execute(sql_context)
nRet = cur.fetchall()
cur.close()
conn.close()
print (reCount)
#print nRet
perfix = time.strftime(‘%y%m%d%H%M%S‘)
xfilename = "./data/" + ip + "_conn_" + perfix + ".xlsx"
workbook = xlsxwriter.Workbook(xfilename)
worksheet1 = workbook.add_worksheet()
worksheet1.write(‘A1‘, u‘主机地址‘)
worksheet1.write(‘B1‘, u‘时间‘)
worksheet1.write(‘C1‘, u‘TCP连接数‘)
row = 1
for i in nRet:
print( i[0], i[1], i[2])
worksheet1.write(row, 0, ip)
worksheet1.write(row, 1, i[1])
worksheet1.write(row, 2, i[2])
row += 1
if row == reCount:
break
workbook.close()
def run():
for ip in host_list:
sql_login(ip)
if __name__ == ‘__main__‘:
run()
我需要的数据比较简单:
主机IP地址 CPU最大值 CPU最小值 内存使用率最大值 内存使用率最小值 磁盘/使用率
接下里开始分析zabbix表结构,拿到最比较老的版本zabbix表结构说明,
https://blog.csdn.net/zhangxueleishamo/article/details/94400572
开始测试。
标签:alt pytho filename print 使用率 ofo zha itemid add
原文地址:https://blog.51cto.com/12785714/2506218