def updateCPUCoreRRD(cpu_cores, cpu_num): if not os.path.exists(CPUCoresRRDFile): core_DS=[] for i in range(cpu_num): core_DS.append("DS:core_" + str(i) + ":GAUGE:600:0:100") core_DS.append("DS:core_avg:GAUGE:600:0:100") ret = rrdtool.create(CPUCoresRRDFile, '--step', '300', core_DS, 'RRA:AVERAGE:0.5:1:864', 'RRA:AVERAGE:0.5:3:1344', 'RRA:AVERAGE:0.5:12:1488', 'RRA:AVERAGE:0.5:36:2960') if ret: print rrdtool.error() return False core_avg = sum(cpu_cores)/float(4) #update data core_data = "N" for i in range(cpu_num): core_data+= ":" + str(cpu_cores[i]) core_data+=":"+str(core_avg) ret = rrd_update(CPUCoresRRDFile, core_data); if ret: print rrdtool.error() return False return True
def update(self, filename, time, value, step=10): if (not os.path.exists(filename)): self.create(filename, time, step) time = time / step * step ret = rrdtool.update(filename, str(time)+":"+str(value)) if ret: print rrdtool.error()
def writeJson(consolidation,resolution): now=time.time() json_dict={} res=resolution end=int((now)/res)*res start=end-res #print now,start,end filename=CHARTPATH+consolidation+"values.json" try: ret = rrdtool.fetch('meteo.rrd',consolidation,"--start",str(start),"--end",str(end),"--resolution",str(res)); if ret: print rrdtool.error() #print ret mags=ret[1] values=ret[2][0] i=0 for mag in mags: #print mag,values[i] json_dict[mag]=int(values[i]*100)/100. i=i++1 #print consolidation,json_dict x = simplejson.dumps(json_dict) fi=open(filename,"w") fi.write(x) fi.close() except: os.remove(filename)
def update_rrd(Host, eth_in_oid, eth_out_oid, rrd_path, auth): eth_in_trffic = netsnmp.snmpget(eth_in_oid, Version=2, DestHost=Host, Community=auth)[0] eth_out_trffic = netsnmp.snmpget(eth_out_oid, Version=2, DestHost=Host, Community=auth)[0] ret = rrd_update(rrd_path, 'N:%s:%s' %(eth_in_trffic, eth_out_trffic)) if not ret: print rrdtool.error() print "update %s N:%s:%s" %(rrd_path, eth_in_trffic, eth_out_trffic)
def create_rrd(host, ds_name, step=300): cur_time = str(int(time.time())) rrd_name = '%s-%s.rrd' % (host, ds_name) ds_str = 'DS:' + ds_name + ':COUNTER:10:0:U' rrd = rrdtool.create( rrd_name, '--step', step, '--start', cur_time, ds_str, 'RRA:AVERAGE:0.5:1:600', 'RRA:AVERAGE:0.5:6:700', 'RRA:AVERAGE:0.5:24:775', 'RRA:AVERAGE:0.5:288:797', 'RRA:MAX:0.5:1:600', 'RRA:MAX:0.5:6:700', 'RRA:MAX:0.5:24:775', 'RRA:MAX:0.5:444:797', 'RRA:MIN:0.5:1:600', 'RRA:MIN:0.5:6:700', 'RRA:MIN:0.5:24:775', 'RRA:MIN:0.5:444:797', ) if rrd: print rrdtool.error() return
def update(self, dbname, values): if os.path.isfile(self.rrd_path + dbname + ".rrd"): error_status = rrdtool.update(self.rrd_path + dbname + ".rrd", values) if error_status: print rrdtool.error() else: print "Not database found"
def generarGraficas(interfaz, comunidad, host): while 1: total_input_traffic = int( parseResultAfterEquals( snmpGet(comunidad, host, OID_INPUT_TRAFFIC + str(interfaz)))) total_output_traffic = int( parseResultAfterEquals( snmpGet(comunidad, host, OID_OUTPUT_TRAFFIC + str(interfaz)))) # total_input_pkts = int(parseResultAfterEquals( # snmpGet(comunidad, host, # OID_INPUT_PKTS + str(interfaz)))) # total_output_pkts = int(parseResultAfterEquals( # snmpGet(comunidad, host, # OID_OUTPUT_PKTS + str(interfaz)))) valor = "N:" + str(total_input_traffic) + ':' + str( total_output_traffic) print valor rrdtool.update('practica1.rrd', valor) rrdtool.dump('practica1.rrd', 'practica1.xml') time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
def updateNetRRD(net, send, recv): NetRRDFile = RRDSDIR + "/" + "interface-%s.rrd" % (net) if not os.path.exists(NetRRDFile): ret = rrdtool.create( NetRRDFile, "--step", "300", "DS:send:DERIVE:600:0:U", "DS:recv:DERIVE:600:0:U", "RRA:AVERAGE:0.5:1:864", "RRA:AVERAGE:0.5:3:1344", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:36:2960", ) if ret: print(rrdtool.error()) return False # update data ret = rrd_update(NetRRDFile, "N:%s:%s" % (send, recv)) if ret: print(rrdtool.error()) return False return True
def owlReceived(self, address, msg): ip, port = address if ip != self.src: # drop out, bad source raise ValueError, 'Source address does not match for packet' # we are good. print msg # iterate channels sorted by channel name, and get their data chan_names = msg.channels.keys() chan_names.sort() o = ['N'] for channel in chan_names: o.append(str(msg.channels[channel].current_w.to_integral_value())) o.append(str(msg.channels[channel].daily_wh.to_integral_value())) o = ':'.join(o) # update database res = rrdtool.update(self.rrd, o) if res: print rrdtool.error()
def update(self, filename, time, value, step=10): if (not os.path.exists(filename)): self.create(filename, time, step) time = time / step * step ret = rrdtool.update(filename, str(time) + ":" + str(value)) if ret: print rrdtool.error()
def updateMemRRD(total, used, buf, cached, free): if not os.path.exists(MemRRDFile): ret = rrdtool.create( MemRRDFile, "--step", "300", "DS:total:GAUGE:600:0:U", "DS:used:GAUGE:600:0:U", "DS:buf:GAUGE:600:0:U", "DS:cached:GAUGE:600:0:U", "DS:free:GAUGE:600:0:U", "RRA:AVERAGE:0.5:1:864", "RRA:AVERAGE:0.5:3:1344", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:36:2960", ) if ret: print(rrdtool.error()) return False # update data ret = rrd_update(MemRRDFile, "N:%s:%s:%s:%s:%s" % (total, used, buf, cached, free)) if ret: print(rrdtool.error()) return False return True
def owlReceived(self, address, msg): ip, port = address if ip != self.src: # drop out, bad source raise ValueError, 'Source address does not match for packet' assert isinstance( msg, OwlElectricity), 'This only supports electricity messages.' # we are good. print msg # iterate channels sorted by channel name, and get their data chan_names = msg.channels.keys() chan_names.sort() o = ['N'] for channel in chan_names: o.append(str(msg.channels[channel].current_w.to_integral_value())) o.append(str(msg.channels[channel].daily_wh.to_integral_value())) o = ':'.join(o) # update database res = rrdtool.update(self.rrd, o) if res: print rrdtool.error()
def main(args): # Check if the the round robin file has been created if not os.path.exists(rrd_file): ret = rrdtool.create("rrd_file", "--step", "300", "--start", '0', "DS:input:COUNTER:600:U:U", "DS:output:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797") if ret: print rrdtool.error() return 42 # Update of database total_input_traffic = 0 total_output_traffic = 0 total_input_traffic += random.randrange(1000, 1500) total_output_traffic += random.randrange(1000, 3000) ret = rrdtool.update( 'rrd_file', 'N:' + ` total_input_traffic ` + ':' + ` total_output_traffic `) if ret: print rrdtool.error() return 42
def rrd1(): ret = rrdtool.create("practica1_1.rrd", "--start", 'N', "--step", '60', "DS:inoctets:COUNTER:600:U:U", "DS:outoctets:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:6:10") ret2 = rrdtool.create("practica1_2.rrd", "--start", 'N', "--step", '60', "DS:inpackets:COUNTER:600:U:U", "DS:outpackets:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:6:10") ret3 = rrdtool.create("practica1_3.rrd", "--start", 'N', "--step", '60', "DS:inpackets:COUNTER:600:U:U", "DS:outpackets:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:6:10") ret4 = rrdtool.create("practica1_4.rrd", "--start", 'N', "--step", '60', "DS:inpackets:COUNTER:600:U:U", "DS:outpackets:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:6:10") ret5 = rrdtool.create("practica1_5.rrd", "--start", 'N', "--step", '60', "DS:inpackets:COUNTER:600:U:U", "DS:outpackets:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:6:10") if ret or ret2 or ret3 or ret4 or ret5: print rrdtool.error()
def updateDiskRRD(name, rcount, wcount, rbytes, wbytes, rtime, wtime): DiskRRDFile = RRDSDIR +'/' +'hdd-%s.rrd' % (name) if not os.path.exists(DiskRRDFile): ret = rrdtool.create(DiskRRDFile, '--step', '300', 'DS:rcount:DERIVE:600:0:U', 'DS:wcount:DERIVE:600:0:U', 'DS:rbytes:DERIVE:600:0:U', 'DS:wbytes:DERIVE:600:0:U', 'DS:rtime:DERIVE:600:0:U', 'DS:wtime:DERIVE:600:0:U', 'RRA:AVERAGE:0.5:1:864', 'RRA:AVERAGE:0.5:3:1344', 'RRA:AVERAGE:0.5:12:1488', 'RRA:AVERAGE:0.5:36:2960') if ret: print rrdtool.error() return False #update data ret = rrd_update(DiskRRDFile, 'N:%s:%s:%s:%s:%s:%s' %(rcount, wcount, rbytes, wbytes, rtime, wtime)); if ret: print rrdtool.error() return False return True
def updatePartitionRRD(index, total, used, free, percent): MountRRDFile = RRDSDIR + "/" + "mount-%s.rrd" % (index) if not os.path.exists(MountRRDFile): ret = rrdtool.create( MountRRDFile, "--step", "300", "DS:total:GAUGE:600:0:U", "DS:used:GAUGE:600:0:U", "DS:free:GAUGE:600:0:U", "DS:percent:GAUGE:600:0:100", "RRA:AVERAGE:0.5:1:864", "RRA:AVERAGE:0.5:3:1344", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:36:2960", ) if ret: print(rrdtool.error()) return False # update data ret = rrd_update(MountRRDFile, "N:%s:%s:%s:%s" % (total, used, free, percent)) if ret: print(rrdtool.error()) return False return True
def updateDiskRRD(name, rcount, wcount, rbytes, wbytes, rtime, wtime): DiskRRDFile = RRDSDIR + "/" + "hdd-%s.rrd" % (name) if not os.path.exists(DiskRRDFile): ret = rrdtool.create( DiskRRDFile, "--step", "300", "DS:rcount:DERIVE:600:0:U", "DS:wcount:DERIVE:600:0:U", "DS:rbytes:DERIVE:600:0:U", "DS:wbytes:DERIVE:600:0:U", "DS:rtime:DERIVE:600:0:U", "DS:wtime:DERIVE:600:0:U", "RRA:AVERAGE:0.5:1:864", "RRA:AVERAGE:0.5:3:1344", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:36:2960", ) if ret: print(rrdtool.error()) return False # update data ret = rrd_update(DiskRRDFile, "N:%s:%s:%s:%s:%s:%s" % (rcount, wcount, rbytes, wbytes, rtime, wtime)) if ret: print(rrdtool.error()) return False return True
def executeSNMP(wlc,wlcIP,ObjectName,OID): global path_bin print "Consultar WLC: %s el OID: %s/ %s" % (wlc,ObjectName,OID) output = commands.getstatusoutput(path_bin + ' %s %s' % (wlcIP,OID)) tempResult = output[1] if "\n" in tempResult: tempResult = output[1].split("\n") i = 1 for result in tempResult: if "0.0.0" not in result: print "%d| %s" % (i,result) i += 1 if ObjectName in "CLIENT_IP": ###### UPDATE RDD print "TOTAL CLIENTES: %d" %(i-1) #if "talca" in wlc: ##UPDATE RDDFILE value = 'N:%d' %(i-1) print value ret = rrd_update('/home/mmoscoso/Documentos/workspace/python-scripts/wireless/%s.rrd' %(wlc),value); if ret: print rrdtool.error() time.sleep(5) else: print tempResult print "############################################################"
def create_rrd(rrd_file, step, rrd_counters): if os.path.isfile(rrd_file): return True argv = [] argv.append(rrd_file) argv.append('--step') argv.append(step) argv.append('--start') argv.append('0') for c in rrd_counters: argv.append("DS:%s:%s:300:U:U" % (c[0], c[1])) argv.append('RRA:AVERAGE:0.5:1:2880') argv.append('RRA:AVERAGE:0.5:5:2880') argv.append('RRA:AVERAGE:0.5:30:4320') argv.append('RRA:AVERAGE:0.5:360:5840') argv.append('RRA:MAX:0.5:1:2880') argv.append('RRA:MAX:0.5:5:2880') argv.append('RRA:MAX:0.5:30:4320') argv.append('RRA:MAX:0.5:360:5840') argv.append('RRA:MIN:0.5:1:2880') argv.append('RRA:MIN:0.5:5:2880') argv.append('RRA:MIN:0.5:30:4320') argv.append('RRA:MIN:0.5:360:5840') rc = rrdtool.create(argv) if rc: print rrdtool.error() return False else: return True
def updateCPURRD(ctemp, cusage, pids): if not os.path.exists(CpuRRDFile): ret = rrdtool.create( CpuRRDFile, "--step", "300", "DS:cputemp:GAUGE:600:0:100", "DS:cpuUsage:GAUGE:600:0:100", "DS:pids:GAUGE:600:0:U", "RRA:AVERAGE:0.5:1:864", "RRA:AVERAGE:0.5:3:1344", "RRA:AVERAGE:0.5:12:1488", "RRA:AVERAGE:0.5:36:2960", ) if ret: print(rrdtool.error()) return False # update data ret = rrd_update(CpuRRDFile, "N:%s:%s:%s" % (ctemp, cusage, pids)) if ret: print(rrdtool.error()) return False return True
def crearBasesLb(comunidad, ip, port, name): agentPath = lbPath + "/" try: os.makedirs(os.path.dirname(agentPath)) except OSError as exc: if exc.errno != errno.EEXIST: print("Error de directorios: Linea Base.") raise # 1 BD Trafico de RAM ret = rrdtool.create(agentPath + "RAM.rrd", "--start", 'N', "--step", '60', "DS:RAMusado:GAUGE:600:U:U", "DS:RAMtotal:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error()) # 2 BD Trafico de CPU ret = rrdtool.create(agentPath + "CPU.rrd", "--start", 'N', "--step", '60', "DS:CPUload:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error()) # 3 BD Trafico de HDD ret = rrdtool.create(agentPath + "HDD.rrd", "--start", 'N', "--step", '60', "DS:HDDusado:GAUGE:600:U:U", "DS:HDDtotal:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error())
def createGraph(self, whichGraph): """ Generate a given graph. """ # Add generic graph properties. graphSpec = self.__graphs[whichGraph] + self.__grphImgGen + [ "--watermark", "%s UTC" % datetime.datetime.utcnow() ] + config.graphSettings['formatting'] if whichGraph.find("cpsGeiger") == 0: # Add geiger counter graph properties. graphSpec = graphSpec + self.__cpsGeigerGen # What graph type do we have? elif whichGraph.find("geiger") == 0: # Add geiger counter graph properties. graphSpec = graphSpec + self.__geigerGen # What graph type do we have? elif whichGraph.find("enviro") == 0: # Add geiger counter graph properties. graphSpec = graphSpec + self.__enviroGen else: return # Try the thing. res = rrdtool.graph(graphSpec) if res: print rrdtool.error()
def main(args): netpng = "net.png" # Check if a hour has past now = time.time() one_hour_ago = now - 60 * 60 if True == True: ret = rrdtool.graph( net.png, "--start", "-1d", "--vertical-label=milliseconds", "DEF:inoctets=test1.rrd:input:AVERAGE", "DEF:outoctets=test1.rrd:output:AVERAGE", "AREA:inoctets#00FF00:In traffic", "LINE1:outoctets#0000FF:Out traffic\\r", "CDEF:inbits=inoctets,8,*", "CDEF:outbits=outoctets,8,*", "COMMENT:\\n", "GPRINT:inbits:AVERAGE:Avg In traffic\: %6.2lf %Sbps", "COMMENT: ", "GPRINT:inbits:MAX:Max In traffic\: %6.2lf %Sbps\\r", "GPRINT:outbits:AVERAGE:Avg Out traffic\: %6.2lf %Sbps", "COMMENT: ", "GPRINT:outbits:MAX:Max Out traffic\: %6.2lf %Sbps\\r") if ret: print rrdtool.error() sys.exit(42) # Put the files in my new site try: bahnhof = bahnHof() bahnhof.upload(netpng) except: pass
def updateCPUCoreRRD(cpu_cores, cpu_num): if not os.path.exists(CPUCoresRRDFile): core_DS = [] for i in range(cpu_num): core_DS.append("DS:core_" + str(i) + ":GAUGE:600:0:100") core_DS.append("DS:core_avg:GAUGE:600:0:100") ret = rrdtool.create(CPUCoresRRDFile, '--step', '300', core_DS, 'RRA:AVERAGE:0.5:1:864', 'RRA:AVERAGE:0.5:3:1344', 'RRA:AVERAGE:0.5:12:1488', 'RRA:AVERAGE:0.5:36:2960') if ret: print(rrdtool.error()) return False core_avg = sum(cpu_cores) / float(4) #update data core_data = "N" for i in range(cpu_num): core_data += ":" + str(cpu_cores[i]) core_data += ":" + str(core_avg) ret = rrd_update(CPUCoresRRDFile, core_data) if ret: print(rrdtool.error()) return False return True
def rrd_update(stats): res = rrdtool.update( rrdfile, 'N:' + stats['down_speed'] + ':' + stats['up_speed'] + ':' + stats['down_atten'] + ':' + stats['up_atten'] + ':' + stats['down_noise'] + ':' + stats['up_noise']) if res: print rrdtool.error()
def rrd_update(stats): res = rrdtool.update(rrdfile, 'N:' + stats['down_speed'] + ':' + stats['up_speed'] + ':' + stats['down_atten'] + ':' + stats['up_atten'] + ':' + stats['down_noise'] + ':' + stats['up_noise']) if res: print rrdtool.error()
def createRRD(computerName): computerName = computerName + ".rrd" ret = rrdtool.create(computerName, "--step", "300", "--start", '0', "DS:la:COUNTER:600:U:U", "RRA:MAX:0.5:1:288") if ret: print rrdtool.error()
def crearBases(name): agentPath = rrdPath + name + "/" try: os.makedirs(os.path.dirname(agentPath)) except OSError as exc: if exc.errno != errno.EEXIST: print("Error de directorios: Procesamiento.") raise #1 BD Trafico de interfaz ret = rrdtool.create( str(agentPath + name) + "Trafico.rrd", "--start", 'N', "--step", '60', "DS:InTraffic:COUNTER:600:U:U", "DS:OutTraffic:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:1:20") if ret: print(rrdtool.error()) #2 BD Estadisticas IP ret = rrdtool.create( str(agentPath + name) + "Estadisticaip.rrd", "--start", 'N', "--step", '60', "DS:InEstadisticaIP:COUNTER:600:U:U", "DS:OutEstadisticaIP:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:1:20") if ret: print(rrdtool.error()) #3 BD Estadisticas ICPM ret = rrdtool.create( str(agentPath + name) + "Estadisticaicmp.rrd", "--start", 'N', "--step", '60', "DS:InEstadisticaICMP:COUNTER:600:U:U", "DS:OutEstadisticaICMP:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:1:20") if ret: print(rrdtool.error()) #4 BD Estadisticas SNMP ret = rrdtool.create( str(agentPath + name) + "Estadisticasnmp.rrd", "--start", 'N', "--step", '60', "DS:InEstadisticaSNMP:COUNTER:600:U:U", "DS:OutEstadisticaSNMP:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:1:20") if ret: print(rrdtool.error()) #5 BD Estadisticas TCP ret = rrdtool.create( str(agentPath + name) + "Estadisticastpc.rrd", "--start", 'N', "--step", '60', "DS:InEstadisticaTCP:COUNTER:600:U:U", "DS:OutEstadisticaTCP:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:20", "RRA:AVERAGE:0.5:1:20") if ret: print(rrdtool.error())
def update_rrd_all(temperature, pressure, dht22temp, humidity, dewpoint, light): ret = rrdtool.update( 'climate.rrd', '--template', 'temperature:pressure:dht22temperature:humidity:dewpoint:light', 'N:' + str(temperature) + ':' + str(pressure) + ':' + str(dht22temp) + ':' + str(humidity) + ':' + str(dewpoint) + ":" + str(light)) if ret: print rrdtool.error()
def print_usage(): global flowPulses threading.Timer(10.0,print_usage).start() print flowPulses lgr.debug(flowPulses) rrdtool.update(rrdfile,'N:' + `flowPulses`) print rrdtool.error() update_graph() flowPulses = 0
def create_rrdb(): rrdb = rrdtool.create('rest.rrd', '--step', '60', '--start', '1369982786', 'DS:input:GAUGE:120:U:U', 'DS:output:GAUGE:120:U:U', 'RRA:LAST:0.5:1:600', 'RRA:AVERAGE:0.5:5:600', 'RRA:MAX:0.5:5:600', 'RRA:MIN:0.5:5:600') if rrdb: print rrdtool.error()
def createrrd(): ret = rrdtool.create(rrd_db, "--step", "10", "--start", '0', "DS:ph:GAUGE:600:U:U", "DS:temp:GAUGE:600:U:U", "DS:sump:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797") if ret: print rrdtool.error()
def createRRD(self, whichRRD): """ Create new blank RRD database. """ # Attempt to create the graph. res = rrdtool.create(self.__rrdCreate[whichRRD]) if res: print rrdtool.error()
def create(self): if os.path.isfile(self.rrdfile) is not True: print self.rrdfile self.rrd = rrdtool.create(self.rrdfile, '--step', '60', '--start',cur_time, 'DS:GCT_avg:GAUGE:120:0:U','DS:Eden_ratio:GAUGE:120:0:U','DS:S1_max:GAUGE:120:0:U','DS:S1_ratio:GAUGE:120:0:U', 'DS:Old_max:GAUGE:120:0:U', 'DS:Heap_max:GAUGE:120:0:U','DS:YGCT_avg:GAUGE:120:0:U','DS:FGCT_avg:GAUGE:120:0:U','DS:FGC:GAUGE:120:0:U', 'DS:Metadata_used:GAUGE:120:0:U','DS:Heap_used:GAUGE:120:0:U','DS:Eden_max:GAUGE:120:0:U','DS:Old_used:GAUGE:120:0:U','DS:Eden_used:GAUGE:120:0:U', 'DS:YGC:GAUGE:120:0:U', 'DS:YGCT:GAUGE:120:0:U','DS:S0_used:GAUGE:120:0:U', 'DS:Metadata_max:GAUGE:120:0:U','DS:FGCT:GAUGE:120:0:U','DS:Old_ratio:GAUGE:120:0:U','DS:Heap_ratio:GAUGE:120:0:U', 'DS:S0_ratio:GAUGE:120:0:U','DS:S1_used:GAUGE:120:0:U', 'DS:Metadata_ratio:GAUGE:120:0:U','DS:GCT:GAUGE:120:0:U','DS:S0_max:GAUGE:120:0:U', 'RRA:AVERAGE:0.5:1:2880','RRA:AVERAGE:0.5:30:672','RRA:AVERAGE:0.5:120:732','RRA:AVERAGE:0.5:720:1460', 'RRA:MIN:0.5:1:2880','RRA:MIN:0.5:30:672','RRA:MIN:0.5:120:732','RRA:MIN:0.5:720:1460','RRA:LAST:0.5:1:2880','RRA:LAST:0.5:30:672','RRA:LAST:0.5:120:732','RRA:LAST:0.5:720:1460', 'RRA:MAX:0.5:1:2880','RRA:MAX:0.5:30:672','RRA:MAX:0.5:120:732','RRA:MAX:0.5:720:1460') if self.rrd: print rrdtool.error() else: print "create success!" return self.rrd
def crearHW(nombre): print 'NOMBREEE ' + nombre ret = rrdtool.create(nombre, "--start", 'N', "--step", '60', "DS:outucastpkts:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:1209", "RRA:HWPREDICT:600:0.9:0.0035:172:3", "RRA:SEASONAL:172:0.9:2", "RRA:DEVSEASONAL:172:0.9:2", "RRA:DEVPREDICT:600:4", "RRA:FAILURES:172:7:9:4") if ret: print rrdtool.error()
def create_rrd(rrd_path): ret = rrdtool.create( rrd_path, "--step", "300", "--start", "0", "DS:eth_in:COUNTER:600:0:U", "DS:eth_out:COUNTER:600:0:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797", "RRA:MIN:0.5:1:600", "RRA:MIN:0.5:6:700", "RRA:MIN:0.5:24:775", "RRA:MIN:0.5:444:797") if not ret: print rrdtool.error()
def rrd_create(): ret = rrdtool.create("/var/ramdisk/var/net.rrd", "--step", "60", "--start", '0', "DS:temp:GAUGE:120:-15:120", "RRA:AVERAGE:0.5:1:60", "RRA:AVERAGE:0.5:5:288", "RRA:AVERAGE:0.5:10:1008", "RRA:AVERAGE:0.5:30:1440", "RRA:AVERAGE:0.5:60:8784") if ret: print rrdtool.error()
def primermodulo(comunidad, host): print("\n****************************************************") print("* = Inicio = *") print("****************************************************\n") SistemaOperativo = "" NumInterfaces = 0 try: SistemaOperativo = str( consultaSNMP(comunidad, host, '1.3.6.1.2.1.1.1.0')) print(" > Sistema Operativo del Servidor: " + SistemaOperativo) NumInterfaces = consultaSNMP(comunidad, host, '1.3.6.1.2.1.2.1.0') print(" > Numero de Interfaces: " + NumInterfaces) #Para ver cuantos procesadores hay #snmpwalk -v2c -c CarlaGonzalez4cv5 localhost 1.3.6.1.2.1.25.3.3.1.2 except: print("\n > Agente desactivado") try: # SE CREAN LAS BASES DE DATOS ret = rrdtool.create(rrdpath + "CpuLoad1.rrd", "--start", 'N', "--step", '60', "DS:CPUload1:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error()) ret = rrdtool.create(rrdpath + "CpuLoad2.rrd", "--start", 'N', "--step", '60', "DS:CPUload2:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error()) ret = rrdtool.create(rrdpath + "RAMUsed.rrd", "--start", 'N', "--step", '60', "DS:RAMUsed:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:24") if ret: print(rrdtool.error()) except: print("\n > Problemas para crear las BD") try: #VAMOS A INICIAR EL HILO threads = [] t = threading.Thread(target=worker, args=(comunidad, host)) threads.append(t) t.start() except: print("\n > Problemas para iniciar el hilo")
def crear(nombre): ret = rrdtool.create( nombre, "--start", '1537228800', "--step", '10', "DS:inoctets:COUNTER:600:U:U", "DS:outoctets:COUNTER:600:U:U", "DS:establishedtcpconn:GAUGE:600:U:U", "DS:intcpsegs:COUNTER:600:U:U", "DS:outtcpsegs:COUNTER:600:U:U", "DS:inicmpmsgs:COUNTER:600:U:U", "DS:outicmpmsgs:COUNTER:600:U:U", "DS:insnmpresponses:COUNTER:600:U:U", "DS:outsnmpresponses:COUNTER:600:U:U", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:1:600") if ret: print rrdtool.error()
def update_rrd(rrd_file, rrd_values): if not os.path.isfile(rrd_file): return False arg = 'N' for c in rrd_values: arg = arg + ':%s' % (c) rc = rrdtool.update(rrd_file, arg) if rc: print rrdtool.error() return False else: return True
def rrd_init(): res = rrdtool.create( rrdfile, "--step", "300", "--start", '0', "DS:down_speed:GAUGE:600:U:U", "DS:up_speed:GAUGE:600:U:U", "DS:down_atten:GAUGE:600:U:U", "DS:up_atten:GAUGE:600:U:U", "DS:down_noise:GAUGE:600:U:U", "DS:up_noise:GAUGE:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797") if res: print rrdtool.error()
def update_rrd(Host, eth_in_oid, eth_out_oid, rrd_path, auth): eth_in_trffic = netsnmp.snmpget(eth_in_oid, Version=2, DestHost=Host, Community=auth)[0] eth_out_trffic = netsnmp.snmpget(eth_out_oid, Version=2, DestHost=Host, Community=auth)[0] ret = rrd_update(rrd_path, 'N:%s:%s' % (eth_in_trffic, eth_out_trffic)) if not ret: print rrdtool.error() print "update %s N:%s:%s" % (rrd_path, eth_in_trffic, eth_out_trffic)
def updateRRD(rrdfile, data): updateString="N" templateString="" if data is not None: for key in data.keys(): updateString=updateString+":"+str(data[key]) if templateString: templateString += ":" templateString += key ret = rrdtool.update(rrdfile, "--template", templateString ,updateString); if ret: print rrdtool.error()
def rrd_generate(): res = rrdtool.graph( outdir + "/adsl-daily.png", "--start", "-1d", "--title=ADSL Sync Speed (Daily)", "--vertical-label=kilobytes/s", "DEF:down_speed=" + rrdfile + ":down_speed:AVERAGE", "DEF:up_speed=" + rrdfile + ":up_speed:AVERAGE", "LINE1:down_speed#00FF00:Downstream Sync Speed", "LINE1:up_speed#0000FF:Upstream Sync Speed\\r", "COMMENT:\\n", "GPRINT:down_speed:AVERAGE:Avg Down Speed\: %5.lfkbps", "COMMENT: ", "GPRINT:down_speed:MAX:Max Down Speed\: %5.lfkbps\\r", "GPRINT:up_speed:AVERAGE:Avg Up Speed\: %5.lfkbps", "COMMENT: ", "GPRINT:up_speed:MAX:Max Up Speed\: %5.lfkbps\\r") if res: print rrdtool.error()
def rrdCreateNew(): ret = rrdtool.create(rrdFile, "--step", "300", "--start", '0', "DS:input:COUNTER:600:U:U", "DS:output:COUNTER:600:U:U", "RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797") if ret: print rrdtool.error()
def actualizarHW(cadena,comunidad,host,puerto,rrd): print 'Entro actualizarHW ',cadena,comunidad,host,puerto,rrd total_input_traffic = 0 total_output_traffic = 0 rrdpath="./RRD_HW/" pngpath="./IMG_HW/" fname=rrd+".rrd" pngfname=rrd+".png" #Verifica que exista una rrd asociada al host, en caso de no existir crea una rrd nueva archivo_rrd = Path(rrdpath+fname) if archivo_rrd.is_file() == False: crearRRD.crearHW(rrdpath+fname) print "rrd HW Creada... en",rrdpath,fname else: print "Abriendo rrd HW..." endDate = rrdtool.last(rrdpath+fname) #ultimo valor del XML begDate = endDate - 3600 #Inicia proceso de adquisicion de datos HW while 1: total_input_traffic = int(consultaSNMP('public','10.100.71.100',1024,'1.3.6.1.2.1.2.2.1.18.1')) total_output_traffic = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.2.2.1.16.3')) '''total_tcp_established = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.9.0')) input_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.10.0')) output_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.11.0')) input_icmp_msgs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.1.0')) output_icmp_msgs = int( consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.14.0')) input_snmp_getReq = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.15.0')) output_snmp_getResp = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.28.0'))''' #valor = str(rrdtool.last(rrdpath+fname)+30) + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp) #valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp) valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic) print 'Valor: ',valor rrdtool.update(rrdpath+fname,valor) rrdtool.dump(rrdpath+fname,rrd+'.xml') #print "actualizar: ",rrdpath,fname, rrd rrdtool.tune(rrdpath+fname,'--alpha','0.1') #time.sleep(1) if ret: print rrdtool.error() time.sleep(300)
def create_database(file_name=rrd_file, interval_in_seconds="60"): error = rrdtool.create( file_name, "--step", interval_in_seconds, "DS:temperature:GAUGE:30:U:U", "DS:temperatureSetPoint:GAUGE:30:U:U", "DS:humidity:GAUGE:30:U:U", "DS:humiditySetPoint:GAUGE:30:U:U", "RRA:AVERAGE:0.2:1:1440", # 1 day of 1-minute accuracy averages "RRA:AVERAGE:0.2:5:8640", # 30 days of 5-minute accuracy averages "RRA:AVERAGE:0.2:15:8640", # 90 days 15 minute averages "RRA:AVERAGE:0.2:30:8640", # 180 days 30 minute averages "RRA:AVERAGE:0.2:60:8760", # 1 year 1 hour averages "RRA:AVERAGE:0.2:1440:1460", # 4 years 1 day averages "RRA:MAX:0.2:1:1440", # 1 day of 1-minute accuracy maximums "RRA:MAX:0.2:5:8640", # 30 days of 5-minute accuracy maximums "RRA:MAX:0.2:15:8640", # 90 days 15 minute maximums "RRA:MAX:0.2:30:8640", # 180 days 30 minute maximums "RRA:MAX:0.2:60:8760", # 1 year 1 hour maximums "RRA:MAX:0.2:1440:1460", # 4 years 1 day maximums "RRA:MIN:0.2:1:1440", # 1 day of 1-minute accuracy minimums "RRA:MIN:0.2:5:8640", # 30 days of 5-minute accuracy minimums "RRA:MIN:0.2:15:8640", # 90 days 15 minute minimums "RRA:MIN:0.2:30:8640", # 180 days 30 minute minimums "RRA:MIN:0.2:60:8760", # 1 year 1 hour minimums "RRA:MIN:0.2:1440:1460", # 4 years 1 day minimums ) if error: raise Exception(rrdtool.error())
def getStoreData(): fi = open('testData.txt','r') for line in fi: #generate data VAR1 = float(line) #see what we generated to determine if rrd data is correct print dataName1 + ': %f\n' % VAR1 #update rrd ret = rrdtool.update(name, "%d:%f" %(time.time(),VAR1)) #Error message. Error if time stamp is wrong if ret: print 'ERROR: ' + rrdtool.error() #set endtime for fetching data from rrd lastTimeStamp = rrdtool.last(name) #send data from RRDTool to server #CURRENTLY SENDS ALL CONTENTS OF RRD - to change replace startTime with 1 second ago... sendData(rrdtool.fetch(name, 'LAST', '--start', "%d" % (startTime) , '--end', '%d' % (lastTimeStamp))) #let me know if everything worked print 'client sleeping...\n' #sleep for 1 second time.sleep(1) fi.close()
def initialize(self): ''' Creates a Round Robin database to store ambient temperature, and light sensor readings. 1 day - 5 minuite resolution 1 week - 15 minuite resolution 1 month - 1 hour resolution 1 year - 6 hour resolution ''' for db in self.databases: logger.info('Initializing a blank {0}'.format(db)) ret = rrdtool.create(join('rrd', db), '--step', '300', '--start', '0', 'DS:input:GAUGE:600:U:U', 'RRA:MIN:0.5:1:288', 'RRA:MIN:0.5:3:672', 'RRA:MIN:0.5:12:744', 'RRA:MIN:0.5:72:1480', 'RRA:AVERAGE:0.5:1:288', 'RRA:AVERAGE:0.5:3:672', 'RRA:AVERAGE:0.5:12:744', 'RRA:AVERAGE:0.5:72:1480', 'RRA:MAX:0.5:1:288', 'RRA:MAX:0.5:3:672', 'RRA:MAX:0.5:12:744', 'RRA:MAX:0.5:72:1480',) if ret: logger.debug(rrdtool.error()) logger.info('{0} created'.format(db))
def init_rrd(self): if os.path.exists(self.path): self.logger.info("RRD file (%s) Exists", self.path) return True self.logger.info("RRD file (%s) doesn't exist. Creating new.", self.path) create_args = [self.path, "--step", "300", "--start", str(int(time.time()))] sk = self.conf.sensors.keys() sk.sort() for sensor in sk: create_args.append("DS:{}:GAUGE:600:U:U".format(sensor)) create_args.extend(["RRA:AVERAGE:0.5:1:600", "RRA:AVERAGE:0.5:6:700", "RRA:AVERAGE:0.5:24:775", "RRA:AVERAGE:0.5:288:797", "RRA:MAX:0.5:1:600", "RRA:MAX:0.5:6:700", "RRA:MAX:0.5:24:775", "RRA:MAX:0.5:444:797"]) # Not being able to create a new RRD is fatal if rrdtool.create(*create_args): self.logger.critical("Could not create new RRD File %s", self.path) self.logger.critical(rrdtool.error()) sys.exit(1) return True
def createDatabase(self): if os.path.isfile(self.fileName): return dataSources = [ BuildDataSourceString(rrdConstants.DS_MEMORY, rrdConstants.TYPE_GAUGE, sampleMin='0', sampleMax='100'), BuildDataSourceString(rrdConstants.DS_DISK, rrdConstants.TYPE_GAUGE, sampleMin='0', sampleMax='100'), BuildDataSourceString(rrdConstants.DS_CPU, rrdConstants.TYPE_GAUGE, sampleMin='0', sampleMax='100') ] errorCode = rrdtool.create(self.fileName, '--start', rrdConstants.NOW, '--step', rrdConstants.STEP, *dataSources, rrdConstants.RRA_DEFAULT_SETTINGS) if errorCode: logging.error('Error creating RRDTool file : %s', rrdtool.error()) raise
def create(self,rrdPath): if os.path.exists(rrdPath): return else: now=str(int(time.time())) rrd=rrdtool.create(rrdPath,'--step','60','--start',now, 'DS:maxThreads:GAUGE:600:0:U', 'DS:currentThreadsBusy:GAUGE:600:0:U', 'DS:currentThreadCount:GAUGE:600:0:U', 'DS:connectionCount:GAUGE:600:0:U', 'RRA:AVERAGE:0.5:1:10080', 'RRA:AVERAGE:0.5:5:2016', 'RRA:MAX:0.5:1:10080', 'RRA:MAX:0.5:5:2016') if rrd: print rrdtool.error()
def update(self): """ Update rrd file, if exists. Otherwise create new rrd """ if not self.vm: raise Exception('No VM specified') try: filesize = os.path.getsize(self.filepath) except Exception: filesize = 0 if(filesize == 0): self.create() else: # appropriate updating ret = rrdtool.update("%s" % (self.filepath), 'N:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d' % (int(self.vm['cpu_count']), int(self.vm['cpu_time']) / 100000000 / 10.0 / self.vm['cpu_count'], int(self.vm['rd_req']), int(self.vm['rd_bytes']), int(self.vm['wr_req']), int(self.vm['wr_bytes']), int(self.vm['rx_bytes']), int(self.vm['rx_packets']), int(self.vm['tx_bytes']), int(self.vm['tx_packets']), )) if ret: log.error(0, 'update error: %s' % (rrdtool.error()))
def create_rrd(rrd_file,m_type="None"): if m_type=="host": ret = rrdtool.create( rrd_file, "--step", str(STEP) ,"--start", str(int(time.time())), "DS:cpu:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:ram:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dw:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:rx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tmp:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:pwr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "RRA:MIN:0:1:200000", # Data stored for every five minute "RRA:AVERAGE:0.5:12:100", # Average data stored for every hour (300*12) "RRA:AVERAGE:0.5:288:50", # Average data stored for every day (300*288) "RRA:AVERAGE:0.5:8928:24", # Average data stored for every month (300*8928) "RRA:AVERAGE:0.5:107136:10")# Average data stored for every year (300*107136) else: ret = rrdtool.create( rrd_file, "--step", str(STEP) ,"--start", str(int(time.time())), "DS:cpu:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:ram:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dr:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:dw:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:tx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "DS:rx:GAUGE:%s:0:U" % str(TIME_DIFF_MS), "RRA:MIN:0:1:200000", # Data stored for every five minute "RRA:AVERAGE:0.5:12:100", # Average data stored for every hour (300*12) "RRA:AVERAGE:0.5:288:50", # Average data stored for every day (300*288) "RRA:AVERAGE:0.5:8928:24", # Average data stored for every month (300*8928) "RRA:AVERAGE:0.5:107136:10")# Average data stored for every year (300*107136) if ret: rrd_logger.warn(rrdtool.error())
def create(self,rrdPath): if os.path.exists(rrdPath): return else: now=str(int(time.time())) rrd=rrdtool.create(rrdPath,'--step','60','--start',now, 'DS:eden_space:GAUGE:600:0:U', 'DS:survivor_space:GAUGE:600:0:U', 'DS:tenured_gen:GAUGE:600:0:U', 'DS:code_cache:GAUGE:600:0:U', 'DS:perm_gen:GAUGE:600:0:U', 'RRA:AVERAGE:0.5:1:10080', 'RRA:AVERAGE:0.5:5:2016', 'RRA:MAX:0.5:1:10080', 'RRA:MAX:0.5:5:2016') if rrd: print rrdtool.error()
def rrd_update(stats, value, interval, ds_type): rrd_name = '%s.rrd' % stats interval = str(interval) interval_mins = float(interval) / 60 heartbeat = str(int(interval) * 20) value = value if not os.path.exists(rrd_name): rrdb = rrdtool.create(rrd_name, '--step', '%s' % interval, 'DS:ds:%s:%s:0:U' %(ds_type, heartbeat), 'RRA:LAST:0.5:1:600', 'RRA:AVERAGE:0.5:5:600', 'RRA:MAX:0.5:5:600', 'RRA:MIN:0.5:5:600') if rrdb: print rrdtool.error() else: up = rrdtool.updatev(rrd_name, 'N:%d' % value) print time.strftime('%Y/%m/%d %H:%M:%S', time.localtime()), stats, value