[rrd-users] rrdtool update()

Emily Chouinard cousin17 at msu.edu
Tue Jun 17 17:14:43 CEST 2008


Alright so I'm new to rrdtool and I was wondering how exactly you define 
the rrdtool update function, I am using it in my code, but I'm not sure 
what the value should be, I understand the time_t:value is what I need 
but what is time_t and where do I find the value?  here's a copy of my 
code, if someone can take a look at it and let me know what direction to 
head in I would really appreciate it.
import rrdtool
import os
import time


interval = 2
interval = str(interval)
interval_mins = float(interval) / 60
heartbeat = str(int(interval) * 2)

rrdtool.create('usr.rrd',
         'DS:usr_info:DERIVE:%s:U:U' % heartbeat,
      'RRA:AVERAGE:0.5:1:%s' % int(4000 / interval_mins),
     'RRA:AVERAGE:0.5:%d:800' % int(30 / interval_mins),
     'RRA:AVERAGE:0.5:%d:800' % int(120 / interval_mins),
           'RRA:AVERAGE:0.5:%d:800' % int(1440 / interval_mins))
rrdtool.create('sys.rrd',
     'DS:sys_info:DERIVE:%s:U:U' % heartbeat,
        'RRA:AVERAGE:0.5:1:%s' % int(4000 / interval_mins),
      'RRA:AVERAGE:0.5:%d:800' % int(30 / interval_mins),
    'RRA:AVERAGE:0.5:%d:800' % int(120 / interval_mins),
        'RRA:AVERAGE:0.5:%d:800' % int(1440 / interval_mins))   
rrdtool.create('idle.rrd',
        'DS:idle_info:DERIVE:%s:U:U' % heartbeat,
        'RRA:AVERAGE:0.5:1:%s' % int(4000 / interval_mins),
        'RRA:AVERAGE:0.5:%d:800' % int(30 / interval_mins),
        'RRA:AVERAGE:0.5:%d:800' % int(120 / interval_mins),
        'RRA:AVERAGE:0.5:%d:800' % int(1440 / interval_mins))
while True:
    infile= open('/proc/stat', 'r')
    #for x in range(0,1): #Reads first line only
    line = infile.readline()
    if line.startswith('cpu'): #Check to make sure in 1st line
    info = line.split()    #Returns a list of the words in the string
    usr_info = info[1]     #Index the three aspects of CPU Usuage
    rrdtool.update('usr.rrd','N:1')           
    sys_info = info[3]
    rrdtool.update('sys.rrd','N:1')
    idle_info = info[4]
    rrdtool.update('idle.rrd','N:1')      #str() because Python needs to 
have a string
        print  usr_info, sys_info, idle_info #Print out so you can see 
what's happening
    time.sleep(5)



More information about the rrd-users mailing list