Keeping alive the whimsy that had me pick webXcreta back up and get it working, I have returned to another old project: PyRRD. I had started work on this a couple years ago while adding functionality to CoyoteMonitoring, but had to put it on hold due to budget constraints.
In a nutshell, PyRRD is an object oriented interface (wrapper) for the RRDTool. python bindings (rrdtool). Where when using rrdtool you might see something like this:
rrdtool.graph(path,
'--imgformat', 'PNG',
'--width', '540',
'--height', '100',
'--start', "-%i" % YEAR,
'--end', "-1",
'--vertical-label', 'Downloads/Day',
'--title', 'Annual downloads',
'--lower-limit', '0',
'DEF:downloads=downloads.rrd:downloads:AVERAGE',
'AREA:downloads#990033:Downloads')
with PyRRD, you have this:
def1 = graph.GraphDefinition(vname='downloads', rrdfile='downloads.rrd',
ds_name='downloads', cdef='AVERAGE')
area1 = graph.GraphArea(value=def1.vname, color="#990033',
legend='Downloads', stack=True)
g = graph.Graph(path, imgformat='PNG', width=540, height=100,
start="-%i" % YEAR, end=-1, vertical_label='Downloads/Day',
title='Annual downloads', lower_limit=0)
g.data.append(def1)
g.data.append(area1)
g.write()
Optionally, you can use attributes (in combination with or to exclusion of parameters):
def1 = graph.GraphDefinition()
def1.vname='downloads'
def1.rrdfile='downloads.rrd'
def1.ds_name='downloads'
def1.cdef='AVERAGE'
And there are aliases for the classes so that you may use the more familiar names from RRDTool:
def = graph.DEF(vname='downloads', rrdfile='downloads.rrd',
ds_name='downloads', cdef='AVERAGE')
area = graph.AREA(value=def.vname, color="#990033', stack=True)
Not only is this object approach more aesthetically pleasing to me, but the interface is much easier to manipulate programmatically. That's insanely important to me because of how I use RRDTool in other projects. I do a great deal of data manipulation and graph representation, and using the regular RRDTool python bindings is simply a show-stopper.
Another neat thing about this wrapper is that the classes use __repr__() to present the complete value of the object as an RRDTool-ready string. This means that you are not limited to using the python bindings, but can also freely and easily interact with the command line tools, configuration values in files, etc.
When I've got a first release ready to go, I'll push it up to CheeseShop and post a notice here on the blog.
No comments:
Post a Comment