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

Matthew M. Boedicker matthewm at boedicker.org
Mon Jun 16 20:20:14 CEST 2008


The argument it's probably complaining about is the 12332. Based on
http://oss.oetiker.ch/rrdtool/prog/rrdpython.en.html it looks like the
module expects strings for all arguments. Try making it str(12332). For the
usr.rrd you don't need to use str() if it's already a quoted string.

On Mon, Jun 16, 2008 at 02:08:06PM -0400, Emily Chouinard wrote:
> I tried that, (thanks again!!!!!!), and got this error Traceback (most 
> recent call last):   File "mult_rrd.py", line 35, in ?  
> rrdtool.update(str('usr.rrd'), 12332)   TypeError: argument 1 must be 
> string, so tried it with just the str() and that gives my the usr is 
> undefined...I'm really stuck and I know its right there in front of me
> 
> 
> Matthew M. Boedicker wrote:
> > It's the same issue with the rrd files needing quotes around them. Any time
> > you have bare unquoted strings in a Python source file it's going to interpret
> > it as part of the code and try to find a module or variable with that name
> > and that's where the error is coming from. You will need quotes where it says
> > example.png too.
> >
> > On Mon, Jun 16, 2008 at 01:25:53PM -0400, Emily Chouinard wrote:
> >   
> >> Alright so hang in with me guys I almost have this finished, but I can't 
> >> seem to get my rrd to update or graph, any suggestions? I'm not sure if 
> >> they should go in the while statement, or after the if, any help would 
> >> be appreciated, because right now when I compile I get an error File 
> >> "mult_rrd.py", line 39, in ?    rrdtool.update(str(usr.rrd))  NameError: 
> >> name 'usr' is not defined
> >>
> >> import rrdtool
> >> import os
> >> import time
> >>
> >> interval = 10
> >> interval = str(interval)
> >> interval_mins = float(interval) / 60
> >> heartbeat = str(int(interval) * 2)
> >>
> >> rrdtool.create('usr.rrd',
> >>       'DS:usr_info:COUNTER:%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:COUNTER:%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:COUNTER:%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]              # These 3 index the specific CPU usages
> >>     sys_info = info[3]
> >>     idle_info = info[4]
> >>     print  usr_info, sys_info, idle_info #Print out so you can see 
> >> what's happening
> >>     time.sleep(10)
> >>
> >> rrdtool.update(str(usr.rrd),12332) #str() because Python needs to have a string
> >> rrdtool.update(str(sys.rrd),12332)
> >> rrdtool.update(str(idle.rrd),12332)
> >>
> >> rrdtool.graph(example.png,
> >>     '--width','400',
> >>     '--height', '150',
> >>     '--start', 'now- %s' % (mins * 60),
> >>     '--end', 'now',
> >>     '--vertical-label', 'CPU Usuage',
> >>     '--title', 'EXAMPLE',
> >>     'COMMENT',time.strftime('%m/%d/%Y %H\:%M\:%S', time.localtime()), 
> >> #Give the current date and time on the graph
> >>     'DEF:ds0=usr.rrd:ds0:AVERAGE ',        #Defines all three aspects of 
> >> the /proc/stat file
> >>     'DEF:ds1=sys.rrd:ds1:AVERAGE:step=800',
> >>     'DEF:ds2=idle.rrd:ds2:AVERAGE:step=800',
> >>     'AREA:ds0#0000FF:"User CPU usuage"',      #Different Labels for each 
> >> of the three ascp
> >>     'AREA:ds1#00FF00:"System CPU usuage" ',
> >>     'AREA:ds2#FF0000:"Idle CPU usuage" ')   
> >>
> >>
> >>
> >>
> >> Matthew M. Boedicker wrote:
> >>     
> >>> It think it doesn't like the leading space in the arguments.
> >>>
> >>> It also expects each argument to a complete "part" (a complete DS, RRA, etc.),
> >>> like this:
> >>>
> >>> rrdtool.create('usr.rrd',
> >>>     'DS:usr_info:COUNTER:%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))
> >>>
> >>> Each part separated by spaces in the command line becomes an argument to the
> >>> Python method.
> >>>
> >>> On Mon, Jun 16, 2008 at 10:53:00AM -0400, Emily Chouinard wrote:
> >>>   
> >>>       
> >>>> Oh man do I feel silly, well that fixed that problem but now I get this 
> >>>> error
> >>>> # python mult_rrd.py
> >>>> 246304 98112 103618859
> >>>> Traceback (most recent call last):
> >>>>   File "mult_rrd.py", line 27, in ?
> >>>>     ' RRA:AVERAGE:0.5:', str(int(14400 / interval_mins)),':800')
> >>>> rrdtool.error: can't parse argument ' DS:usr_info:COUNTER:10:U:U'
> >>>>
> >>>> Matthew M. Boedicker wrote:
> >>>>     
> >>>>         
> >>>>> You will have to put the rrd filenames in quotes so Python will interpret
> >>>>> them as strings and not Python syntax.
> >>>>>
> >>>>> On Mon, Jun 16, 2008 at 10:12:09AM -0400, Emily Chouinard wrote:
> >>>>>   
> >>>>>       
> >>>>>           
> >>>>>> Alright so I've tried following everyone advice, thanks by the way, and 
> >>>>>> I've got this far and now I can't get the rrdcreate to work when I run 
> >>>>>> my code
> >>>>>>
> >>>>>> import rrdtool
> >>>>>> import os
> >>>>>> import time
> >>>>>>
> >>>>>> interval = 5
> >>>>>> interval = str(interval)
> >>>>>> interval_mins = float(interval) / 60 
> >>>>>> heartbeat = str(int(interval) * 2)
> >>>>>>
> >>>>>> 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]              # These 3 index the specific CPU usages
> >>>>>>     sys_info = info[3]
> >>>>>>     idle_info = info[4]
> >>>>>>     print  usr_info, sys_info, idle_info #Print out so you can see 
> >>>>>> what's happening
> >>>>>>    
> >>>>>>     rrdtool.create (usr.rrd,
> >>>>>>         ' DS:usr_info:COUNTER: %s:U:U % heartbeat', 
> >>>>>>         ' RRA:AVERAGE:0.5:1:', str(int(4000 / interval_mins)),
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(30 / interval_mins)), ':800',
> >>>>>>                ' RRA:AVERAGE:0.5:', str(int(120 / interval_mins)), ':800',
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(1440 / interval_mins)), ':800')
> >>>>>>    
> >>>>>>     rrdtool.create (sys.rrd,
> >>>>>>         ' DS:sys_info:COUNTER: %s:U:U % heartbeat',
> >>>>>>         ' RRA:AVERAGE:0.5:1:', str(int(4000 / interval_mins)),
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(30 / interval_mins)), ':800',
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(120 / interval_mins)), ':800',
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(1440 / interval_mins)), ':800')   
> >>>>>>    
> >>>>>>     rrdtool.create (idle.rrd,
> >>>>>>         ' DS:idle_info:COUNTER: %s:U:U % heartbeat', 
> >>>>>>         ' RRA:AVERAGE:0.5:1:', str(int(4000 / interval_mins)),
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(30 / interval_mins)), ':800',
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(120 / interval_mins)), ':800',
> >>>>>>             ' RRA:AVERAGE:0.5:', str(int(1440 / interval_mins)), ':800')
> >>>>>>      
> >>>>>> rrdtool.update (usr.rrd, 12322)
> >>>>>> rrdtool.update (sys.rrd,12322)
> >>>>>> rrdtool.update (idle.rrd,12322)
> >>>>>>
> >>>>>> rrdtool.graph(test.rrd.png,
> >>>>>>     ' --width','400',
> >>>>>>     ' --height', '150',
> >>>>>>     ' --start', 'now- %s' % (mins * 60),
> >>>>>>     ' --end', 'now',
> >>>>>>     ' --vertical-label', 'CPU Usuage',
> >>>>>>     ' --title', 'EXAMPLE',
> >>>>>>     ' COMMENT',time.strftime('%m/%d/%Y %H\:%M\:%S', time.localtime()),
> >>>>>>     ' DEF:ds0= usr.rrd:ds0:AVERAGE ',
> >>>>>>      ' DEF:ds1 = sys.rrd:ds1:AVERAGE:step=800',
> >>>>>>      ' DEF:ds2= idle.rrd:ds2:AVERAGE:step=800',
> >>>>>>         ' AREA:ds0#0000FF:"User CPU usuage"',
> >>>>>>         ' LINE1: ds1#00FF00:"System CPU usuage" ',
> >>>>>>         ' LINE1: ds2#FF0000:"Idle CPU usuage" ')
> >>>>>>
> >>>>>> I get this error   # python mult_rrd.py
> >>>>>> 246176 97876 103312642
> >>>>>> Traceback (most recent call last):
> >>>>>>   File "mult_rrd.py", line 21, in ?
> >>>>>>     rrdtool.create (usr.rrd,
> >>>>>> NameError: name 'usr' is not defined
> >>>>>>
> >>>>>> And this is where I am stuck, I'm not sure why it is giving me this 
> >>>>>> error, I thought the rrdtool.create defined the file usr.rrd if not let 
> >>>>>> me know what I should do to fix it, also let me know if you see other 
> >>>>>> things gone wrong in here (maybe take a peek at my rrdtool.update 
> >>>>>> commands), thanks!
> >>>>>>     Emily
> >>>>>>
> >>>>>>        
> >>>>>>
> >>>>>>
> >>>>>> Fabien Wernli wrote:
> >>>>>>     
> >>>>>>         
> >>>>>>             
> >>>>>>> On Fri, Jun 13, 2008 at 11:40:28AM -0400, Matthew M. Boedicker wrote:
> >>>>>>>   
> >>>>>>>       
> >>>>>>>           
> >>>>>>>               
> >>>>>>>> For CPU usage you might want to try GAUGE instead of COUNTER. For graphing
> >>>>>>>>     
> >>>>>>>>         
> >>>>>>>>             
> >>>>>>>>                 
> >>>>>>> no you don't: Emily is pulling /proc/stat values which _are_ counters
> >>>>>>> using GAUGE would produce endlessly growing values
> >>>>>>>
> >>>>>>> _______________________________________________
> >>>>>>> rrd-users mailing list
> >>>>>>> rrd-users at lists.oetiker.ch
> >>>>>>> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
> >>>>>>>
> >>>>>>>
> >>>>>>>   
> >>>>>>>       
> >>>>>>>           
> >>>>>>>               
> >>>>>> _______________________________________________
> >>>>>> rrd-users mailing list
> >>>>>> rrd-users at lists.oetiker.ch
> >>>>>> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
> >>>>>>     
> >>>>>>         
> >>>>>>             
> >>>>>   
> >>>>>       
> >>>>>           
> >>>> _______________________________________________
> >>>> rrd-users mailing list
> >>>> rrd-users at lists.oetiker.ch
> >>>> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
> >>>>     
> >>>>         
> >>>   
> >>>       
> >> _______________________________________________
> >> rrd-users mailing list
> >> rrd-users at lists.oetiker.ch
> >> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
> >>     
> >
> >
> >   
> 
> _______________________________________________
> rrd-users mailing list
> rrd-users at lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users



More information about the rrd-users mailing list