[rrd-users] Python 2.6 and rrdtool.graph()

Miroslav Chlasták chlastak at fialka.cz
Sat Oct 30 11:29:56 CEST 2010


Hi all,

   I have one python script, that works on python 2.5, but not on python 
2.6.

Here is a snip of code:

[snip]
         graph_attr = [ '-n', 
'DEFAULT:7:%s/fonts/DejaVuSansMono-Roman.ttf' % __dir__,'--imgformat', 
'PNG', '-h', '100', '-w', '392', '--title', 'Wireless signal of MAC %s' 
% urldata['mac'], '-s', '%s' % graph_from, '-e', '%s' % graph_to ]

rrdtool.graph(path,graph_attr,"-c","MGRID#ee0000aa","-c","GRID#a0a0a0aa","-l","-90","--vertical-label=Signal","DEF:signal=%s:signal:AVERAGE" 
% rrdfile,"DEF:txrate=%s:txrate:AVERAGE" % 
rrdfile,"VDEF:signal_max=signal,MAXIMUM","VDEF:signal_average=sign
al,AVERAGE","VDEF:signal_last=signal,LAST","VDEF:txrate_max=txrate,MAXIMUM","VDEF:txrate_average=txrate,AVERAGE","VDEF:txrate_last=txrate,LAST",'AREA:signal#00FF00: 
Signal \\t(max/avg/cur)\\t','GPRINT:signal_max:%2.2lf 
%SdBm\\t','GPRINT:signal_average:%2.2lf
  %SdBm\\t',"GPRINT:signal_last:%2.2lf %SdBm\\n",'LINE1:txrate#0000FF: 
TX Rate \\t(max/avg/cur)\\t','GPRINT:txrate_max: %2.2lf 
%SMb\\t','GPRINT:txrate_average: %2.2lf %SMb\\t','GPRINT:txrate_last: 
%2.2lf %SMb\\n')

[snip]

On python 2.6 i get error:

   File "/home/www/loginportal/deviceapi/grapher/signal_graph.py", line 61, in index
     rrdtool.graph(path,graph_attr,"-c","MGRID#ee0000aa","-c","GRID#a0a0a0aa","-l","-90","--vertical-label=Signal","DEF:signal=%s:signal:AVERAGE" % rrdfile,"DEF:txrate=%s:txrate:AVERAGE" % rrdfile,"VDEF:signal_max=signal,MAXIMUM","VDEF:signal_average=signal,AVERAGE","VDEF:signal_last=signal,LAST","VDEF:txrate_max=txrate,MAXIMUM","VDEF:txrate_average=txrate,AVERAGE","VDEF:txrate_last=txrate,LAST",'AREA:signal#00FF00: Signal \\t(max/avg/cur)\\t','GPRINT:signal_max:%2.2lf %SdBm\\t','GPRINT:signal_average:%2.2lf %SdBm\\t',"GPRINT:signal_last:%2.2lf %SdBm\\n",'LINE1:txrate#0000FF: TX Rate \\t(max/avg/cur)\\t','GPRINT:txrate_max: %2.2lf %SMb\\t','GPRINT:txrate_average: %2.2lf %SMb\\t','GPRINT:txrate_last: %2.2lf %SMb\\n')

TypeError: argument 1 must be string


How can I get this working? I try modify code like this:

[snip]

graph_attr = [ '-n', 'DEFAULT:7:%s/fonts/DejaVuSansMono-Roman.ttf' % 
__dir__,'--imgformat', 'PNG', '-h', '100', '-w', '392', '--title', 
'Wireless signal of MAC %s' % urldata['mac'], '-s', '%s' % graph_from, 
'-e', '%s' % graph_to ]

rrdtool.graph(path,str('"'+string.join(graph_attr,'","')+'"'),"-c","MGRID#ee0000aa","-c","GRID#a0a0a0aa","-l","-90","--vertical-label=Signal","DEF:signal=%s:signal:AVERAGE" 
% rrdfile,"DEF:txrate=%s:txrate:AVERAGE" % 
rrdfile,"VDEF:signal_max=signal,MA
XIMUM","VDEF:signal_average=signal,AVERAGE","VDEF:signal_last=signal,LAST","VDEF:txrate_max=txrate,MAXIMUM","VDEF:txrate_average=txrate,AVERAGE","VDEF:txrate_last=txrate,LAST",'AREA:signal#00FF00: 
Signal \\t(max/avg/cur)\\t','GPRINT:signal_max:%2.2lf %SdBm\\
t','GPRINT:signal_average:%2.2lf %SdBm\\t',"GPRINT:signal_last:%2.2lf 
%SdBm\\n",'LINE1:txrate#0000FF: TX Rate 
\\t(max/avg/cur)\\t','GPRINT:txrate_max: %2.2lf 
%SMb\\t','GPRINT:txrate_average: %2.2lf %SMb\\t','GPRINT:txrate_last: 
%2.2lf %SMb\\n')

[snip]

And then i get:

   File "/home/www/loginportal/deviceapi/grapher/signal_graph.py", line 61, in index
     rrdtool.graph(path,str('"'+string.join(graph_attr,'","')+'"'),"-c","MGRID#ee0000aa","-c","GRID#a0a0a0aa","-l","-90","--vertical-label=Signal","DEF:signal=%s:signal:AVERAGE" % rrdfile,"DEF:txrate=%s:txrate:AVERAGE" % rrdfile,"VDEF:signal_max=signal,MAXIMUM","VDEF:signal_average=signal,AVERAGE","VDEF:signal_last=signal,LAST","VDEF:txrate_max=txrate,MAXIMUM","VDEF:txrate_average=txrate,AVERAGE","VDEF:txrate_last=txrate,LAST",'AREA:signal#00FF00: Signal \\t(max/avg/cur)\\t','GPRINT:signal_max:%2.2lf %SdBm\\t','GPRINT:signal_average:%2.2lf %SdBm\\t',"GPRINT:signal_last:%2.2lf %SdBm\\n",'LINE1:txrate#0000FF: TX Rate \\t(max/avg/cur)\\t','GPRINT:txrate_max: %2.2lf %SMb\\t','GPRINT:txrate_average: %2.2lf %SMb\\t','GPRINT:txrate_last: %2.2lf %SMb\\n')

error: Could not make sense out of '"-n","DEFAULT:7:/home/www/loginportal/deviceapi/grapher/fonts/DejaVuSansMono-Roman.ttf","--imgformat","PNG","-h","100","-w","392","--title","Wireless signal of MAC 00:0A:59:F3:57:42","-s","1285888680","-e","1288307880","-x","WEEK:1:MONTH:1:WEEK:1:604800:Week %V"'


It's possible to use array in rrdtool.graph() function in python 2.6?

-- 
Mira Chlastak



More information about the rrd-users mailing list