Python Forum
python rrdtool graph creation issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python rrdtool graph creation issue
#1
Hi All,

trying with below sample code, however i am getting error while running display graph script.

Graph Creation
import sys
import rrdtool

ret = rrdtool.create("net.rrd", "--step", "300", "--start", '0',
 "DS:input:COUNTER:600:U:U",
 "DS:output:COUNTER:600:U:U",
 "RRA:AVERAGE:0.5:1:600",
 "RRA:AVERAGE:0.5:6:700",
 "RRA:AVERAGE:0.5:24:775",
 "RRA:AVERAGE:0.5:288:797",
 "RRA:MAX:0.5:1:600",
 "RRA:MAX:0.5:6:700",
 "RRA:MAX:0.5:24:775",
 "RRA:MAX:0.5:444:797")

if ret:
 print rrdtool.error()
Graph Updattion

import sys
import time
import rrdtool
from easysnmp import Session
from rrdtool import update as rrd_update
session = Session(hostname='172.21.160.2', community='read', version=2)
total_input_traffic = 0
total_output_traffic = 0

while 1:
   traffic_in = session.get('.1.3.6.1.2.1.31.1.1.1.6.10111')
   in_traffic = traffic_in.value
   #print in_traffic
   traffic_out = session.get('.1.3.6.1.2.1.31.1.1.1.10.10111')
   out_traffic = traffic_out.value
   #print out_traffic
   #ret = rrdtool.update('net.rrd','N:in_traffic:out_traffic')
   ret = rrd_update('net.rrd', 'N:%s:%s' %(str(in_traffic),str(out_traffic)))
   if ret:
      print rrdtool.error()
   time.sleep(300)
Graph Dispay
import sys
import rrdtool

ret = rrdtool.graph("net.png", "--start", "-1d", "--vertical-label=Bytes/s",
 "DEF:inoctets=test1.rrd:input:AVERAGE",
 "DEF:outoctets=test1.rrd:output:AVERAGE",
 "AREA:inoctets#00FF00:In traffic",
 "LINE1:outoctets#0000FF:Out traffic\r",
 "CDEF:inbits=inoctets,8,*",
 "CDEF:outbits=outoctets,8,*",
 "COMMENT:\n",
 "GPRINT:inbits:AVERAGE:Avg In traffic: %6.2lf %Sbps",
 "COMMENT:  ",
 "GPRINT:inbits:MAX:Max In traffic: %6.2lf %Sbps\r",
 "GPRINT:outbits:AVERAGE:Avg Out traffic: %6.2lf %Sbps",
 "COMMENT: ",
 "GPRINT:outbits:MAX:Max Out traffic: %6.2lf %Sbps\r")
Error:
Traceback (most recent call last): File "displaygraph.py", line 17, in <module> "GPRINT:outbits:MAX:Max Out traffic: %6.2lf %Sbps\r") rrdtool.error: I don't understand ': %6.2lf %Sbps' in command: 'GPRINT:inbits:AVERAGE:Avg In traffic: %6.2lf %Sbps'.

Display graph script, changed with created rrd, same error in Python2.7 and Python 3.6



import sys
import rrdtool
 
ret = rrdtool.graph("net.png", "--start", "-1d", "--vertical-label=Bytes/s",
 "DEF:inoctets=net.rrd:input:AVERAGE",
 "DEF:outoctets=net.rrd:output:AVERAGE",
 "AREA:inoctets#00FF00:In traffic",
 "LINE1:outoctets#0000FF:Out traffic\r",
 "CDEF:inbits=inoctets,8,*",
 "CDEF:outbits=outoctets,8,*",
 "COMMENT:\n",
 "GPRINT:inbits:AVERAGE:Avg In traffic: %6.2lf %Sbps",
 "COMMENT:  ",
 "GPRINT:inbits:MAX:Max In traffic: %6.2lf %Sbps\r",
 "GPRINT:outbits:AVERAGE:Avg Out traffic: %6.2lf %Sbps",
 "COMMENT: ",
 "GPRINT:outbits:MAX:Max Out traffic: %6.2lf %Sbps\r")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python modules to extract data from a graph? bigmit37 5 14,785 Apr-09-2021, 02:15 PM
Last Post: TysonL
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 454 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  Python Matplotlib: How do I plot lines with different end point in the same graph? JaneTan 0 438 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  How to add an image to an existing facebook post using python graph API? Ascalon 0 711 Dec-01-2020, 08:33 PM
Last Post: Ascalon
  Python I/O: input a graph anata2047 4 1,063 Jun-19-2020, 01:02 PM
Last Post: deanhystad
  Graphing three database in one graph Python r_e 1 1,108 Jun-20-2019, 05:10 PM
Last Post: r_e
  python 2D array creation and print issue developerbrain 5 1,259 May-15-2019, 01:38 PM
Last Post: developerbrain
  Socket creation speed difference Python 2.7 / Python 3.7 PiAil 1 1,392 Feb-13-2019, 01:55 PM
Last Post: PiAil
  Working with turtle graphics in python and colour slices of a pie graph... netrate 1 2,816 Feb-03-2018, 08:41 PM
Last Post: Larz60+
  Python-Function object creation studnik2 2 1,945 Jul-28-2017, 08:34 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020