-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeremiah Jester wrote:
> Is anyone on here using the python-rrdtool module for graphing and
> analysis? If so, do you have some sample scripts you could show me.
> There doesn't seem to be a lot out there as far as real world python
> examples.
> 
> Thanks,
> JJ

Actually, I was just playing around with the rrdtool library for python
last week.  It turns out that you basically just use the command line
options as options for the different method calls (like create()).  All
you really have to do is check out the man pages for rrdtool to have all
the documentation you need for the rrdtool python module.  You literally
pass in the command line opts just as they would appear on the command
line.  Here is a quick little script that I whipped up for playing purposes:
- ------------------------

#!/usr/bin/env python

import rrdtool , time , random

stime = int(time.time()) - 5 * 86400
dpoints = 1000
etime = stime + (dpoints * 300)
fname = 'test.rrd'
gfname = 'test.png'

rrdtool.create('test.rrd' ,
        '--start' , str(stime) ,
        'DS:speed:COUNTER:600:U:U' ,
        'RRA:AVERAGE:0.5:1:576' ,
        'RRA:AVERAGE:0.5:6:336'
)

ctime = stime
cmiles = 0
for i in xrange(dpoints):
    bump = random.randint(1 , 20)
    cmiles += bump
    ctime += 300
    rrdtool.update(fname , '%d:%d' % (ctime , cmiles))

rrdtool.graph(gfname ,
        '--start' , str(etime - (24 * 3600)) ,
        '--end' , str(etime) ,
        '--vertical-label' , 'Speed m/h' ,
        '--imgformat' , 'PNG' ,
        '--title' , 'Speeds' ,
        '--lower-limit' , '0' ,
        'DEF:myspeed=%s:speed:AVERAGE' % fname ,
        'CDEF:mph=myspeed,3600,*' ,
        'VDEF:msmax=mph,MAXIMUM' ,
        'VDEF:msavg=mph,AVERAGE' ,
        'VDEF:msmin=mph,MINIMUM' ,
        'VDEF:mspct=mph,95,PERCENT' ,
        'LINE1:mph#FF0000:My Speed' ,
        r'GPRINT:msmax:Max\: %6.1lf mph' ,
        r'GPRINT:msavg:Avg\: %6.1lf mph' ,
        r'GPRINT:msmin:Min\: %6.1lf mph\l' ,
        r'GPRINT:mspct:95th Perc\: %6.1lf mph\l'
)

- ------------------------

That, coupled with the rrdtool man pages (which are very good, complete
with examples) should be enough to get you started.

- --
Jay Deiman

\033:wq!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkk9YNwACgkQQ0lr+ZVKSBiWTQCgoBuzQVeRHBlrJ7GONQAL0RFT
qOwAn3cnbZot0q1qGf6mOFHS8QgQc53o
=h7CZ
-----END PGP SIGNATURE-----
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to