elif len(DS) == 9: createsub.Item09(rrdname, startStamp, DS) elif len(DS) == 10: createsub.Item10(rrdname, startStamp, DS) elif len(DS) == 11: createsub.Item11(rrdname, startStamp, DS) elif len(DS) == 12: createsub.Item12(rrdname, startStamp, DS) elif len(DS) == 13: createsub.Item13(rrdname, startStamp, DS) elif len(DS) == 14: createsub.Item14(rrdname, startStamp, DS) elif len(DS) == 15: createsub.Item15(rrdname, startStamp, DS) elif len(DS) == 16: createsub.Item16(rrdname, startStamp, DS) elif len(DS) == 17: createsub.Item17(rrdname, startStamp, DS) elif len(DS) == 18: createsub.Item18(rrdname, startStamp, DS) elif len(DS) == 19: createsub.Item19(rrdname, startStamp, DS) elif len(DS) == 20: createsub.Item20(rrdname, startStamp, DS) elif len(DS) == 21: createsub.Item21(rrdname, startStamp, DS) elif len(DS) == 22: createsub.Item22(rrdname, startStamp, DS) elif len(DS) == 23: createsub.Item23(rrdname, startStamp, DS) elif len(DS) == 24: createsub.Item24(rrdname, startStamp, DS) def rrd_update(rrdfile, data): pass def hosts_get(): global zb zb = Zabbix() hostsName = zb.hostsid_get() return hostsName #遍历每台主机每张图的每个项目的最新10的值,后来考虑到api的压力改成每张图的最新值(减少了一个for循环变量items) def items_get(host): bashdir = "/opt/rrd/" graphsName = zb.hostgraph_get(host.keys()) for graph in graphsName: grapitem = zb.graphitems_get(graph['graphid']) rrdfile = bashdir + host.values()[0] + "/" + str(graph['graphid']) + '.rrd' if os.path.isfile(rrdfile): data = http://www.3lian.com/edu/2015/02-27/[] for item in grapitem: tmp = {'itemid':item['itemid'],'lastvalue':item['lastvalue']} data.append(tmp) rrd_update(rrdfile, data) print data else: grinfo = [] for item in grapitem: tmp = {'hostid': host.values()[0], 'graphid': graph['graphid'], 'itemid': item['itemid']} grinfo.append(tmp) rrd_create(grinfo) def main(): threads = [] keys = hosts_get() numkey = len(keys) loop = 0 for i in range(0, numkey, 16): nkeys = range(loop*16, (loop+1)*16, 1) for i in nkeys: if i >= numkey: break else: t = threading.Thread(target=items_get, args=(keys[i],)) threads.append(t) for i in nkeys: if i >= numkey: break else: threads[i].start() for i in nkeys: if i >= numkey: break threads[i].join() loop = loop + 1 if __name__ == "__main__": main() 上面还有更新数据的函数没有写完,用pass站位。过多的解释就不用了,对着相应的注释大家都应该看的懂。 |