[rrd-users] Still trying to create a graph from multiple sources in RRDtool

Emily Chouinard cousin17 at msu.edu
Tue Jun 17 15:53:34 CEST 2008


Here is a copy of my combiled code, it works but when I display the 
graph, there are no lines or anything, so I was just wondering if 
someone would take a look at it and tell me when I'm going wrong! Thanks
import rrdtool
import os
import time
import string

interval = 10
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:12322')           
    sys_info = info[3]
    rrdtool.update('sys.rrd','N:12322')
    idle_info = info[4]
    rrdtool.update('idle.rrd','N:100000000')      #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)
 
    #cur_date=time.strftime('%m/%d/%Y %H\:%M\:%S', time.localtime())      
    rrdtool.graph('example.png',
        '--start','now-%s'%(60*60),
        '--end','now',
        '--width','400',
        '--height','150',
    '--base', '1000',
    '--vertical-label','CPU Usuage',
    '--title', 'EXAMPLE',
    'DEF:usr_info=usr.rrd:usr_info:AVERAGE',        #Defines all three 
aspects of the /proc/stat file
     'DEF:sys_info=sys.rrd:sys_info:AVERAGE:step=800',
     'DEF:idle_info=idle.rrd:idle_info:AVERAGE:step=800',
        'LINE2:usr_info#0000FF:"User CPU usuage"',      #Different 
Labels for each of the three ascp
        'LINE2:sys_info#00FF00:"System CPU usuage"',
        'LINE2:idle_info#FF0000:"Idle CPU usuage"')   



More information about the rrd-users mailing list