#!/usr/bin/python #################### # RRDpipe-test.py # #################### # # Sample program illustrating the RRDpipe module. We create # a simple RRD database, perform 3 inserts, and generate a # graph in GIF87 format. # # Author: Franco Gasperino # # Create Date: 03/28/01 # # Revision: $Revision: 1.1.1.1 $ # Last Modified: $Date: 2001/04/22 22:58:33 $ # Last Committer: $Author: franco $ # # Copyright (C) 2001 Franco Gasperino # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 67 # Mass Ave, Cambridge, MA 02139, USA. # #################### # Imported Modules # #################### import os import time import RRDpipe ########### # Globals # ########### RRDTOOL = "/usr/bin/rrdtool" RRD_DB = "/var/tmp/rrddb.rrd" RRD_GIF = "/var/tmp/rrddb.gif" ######## # Main # ######## try: # create instance rrdpipe = RRDpipe.RRDpipe() rrdpipe.start(RRDTOOL) # create the graph print "Creating RRD database %s..\n" % (RRD_DB) rrdpipe.cmd("create %s --start now --step 1 DS:in:GAUGE:100:U:U RRA:AVERAGE:0.5:1:10" % (RRD_DB)) # issue 3 updates, each 1 second apart time.sleep(1) print "Updating RRD database %s (pass 1)..\n" % (RRD_DB) rrdpipe.cmd("update %s N:5" % (RRD_DB)) time.sleep(1) print "Updating RRD database %s (pass 2)..\n" % (RRD_DB) rrdpipe.cmd("update %s N:10" % (RRD_DB)) time.sleep(1) print "Updating RRD database %s (pass 3)..\n" % (RRD_DB) rrdpipe.cmd("update %s N:15" % (RRD_DB)) # graph the result print "Creating GIF image %s..\n" % (RRD_GIF) rrdpipe.cmd("graph %s --start -10 --title \"Test\" DEF:IN=%s:in:AVERAGE AREA:IN#0000FF:\"In Data\"" % (RRD_GIF, RRD_DB)) rrdpipe.end() rrdpipe = None except RRDpipe.Error, err: print "%s\n" % (err)