0

The code of graph.py is :

# -*- coding: utf-8 -*-
#!/usr/bin/python
import rrdtool
import time

# Define the headline above the chart

title="Server network traffic flow ("+time.strftime('%Y-%m-%d',time.localtime(time.time()))+")"

# Generate a Flow.png file

rrdtool.graph("Flow.png", "--start", "-1d", "--vertical-label=Bytes/s",\
"--x-grid", "MINUTE:12:HOUR:1:0:%H",\
"--width", "650", "--height", "230", "--title", title,
"DEF:inoctets=Flow.rrd:eth0_in:AVERAGE",      #Specify the NIC inflow data source DS and CF 
"DEF:outoctets=Flow.rrd:eth0_out:AVERAGE",    #Specify the network card outgoing traffic data source DS and CF
"CDEF:total=inoctets,outoctets,+",            #Combine the incoming and outgoing traffic through the CDEF to get the total traffic total

"LINE1:total#FF8833:Total traffic",           #Draw total flow in lines
"AREA:inoctets#00FF00:In traffic",            #Draw inflow in area
"LINE1:outoctets#0000FF:Out traffic",         #Draw outflow in lines
"HRULE:6144#FF0000:Alarm value\\r",           #Draw a horizontal line as an alarm line with a threshold of 6.1K
"CDEF:inbits=inoctets,8,*",                   #Convert incoming traffic to bit, ie *8, calculate the result to inbits
"CDEF:outbits=outoctets,8,*",                 #Convert the outgoing traffic to bit, ie *8, and calculate the result to outbits
"COMMENT:\\r",                                #Output a line break below the grid
"COMMENT:\\r",
"GPRINT:inbits:AVERAGE:Avg In traffic\: %6.21f %Sbps",  #Draw inflow average
"COMMENT:   ",
"GPRINT:inbits:MAX:Max In traffic\: %6.21f %Sbps",      #Draw inflow maximum
"COMMENT:   ",
"GPRINT:inbits:MIN:MIN In traffic\: %6.21f %Sbps\\r",   #Draw inflow minimum
"COMMENT:   ",
"GPRINT:outbits:AVERAGE:Avg Out traffic\: %6.21f %Sbps", #Draw outflow average
"COMMENT:   ",
"GPRINT:outbits:MAX:Max Out traffic\: %6.21f %Sbps",    #Draw outflow maximum
"COMMENT:   ",
"GPRINT:outbits:MIN:MIN Out traffic\: %6.21f %Sbps\\r")  #Draw outflow minimum

When I execute " python graph.py "

The error report :

Traceback (most recent call last):

File "graph.py", line 31, in

"GPRINT:outbits:MIN:MIN Out traffic\: %6.21f %Sbps\\r")

rrdtool.OperationalError: invalid x-grid format

How can I slove this problem ?

Andrew8460958
  • 147
  • 1
  • 10

1 Answers1

0

This is the error:

rrdtool.OperationalError: invalid x-grid format

From the RRDTool Manual:

X-Axis

[-x|--x-grid GTM:GST:MTM:MST:LTM:LST:LPR:LFM]

The x-axis label is quite complex to configure. If you don't have very special needs it is probably best to rely on the auto configuration to get this right. You can specify the string none to suppress the grid and labels altogether.

The grid is defined by specifying a certain amount of time in the ?TM positions. You can choose from SECOND, MINUTE, HOUR, DAY, WEEK, MONTH or YEAR. Then you define how many of these should pass between each line or label. This pair (?TM:?ST) needs to be specified for the base grid (G??), the major grid (M??) and the labels (L??). For the labels you also must define a precision in LPR and a strftime format string in LFM. LPR defines where each label will be placed. If it is zero, the label will be placed right under the corresponding line (useful for hours, dates etcetera). If you specify a number of seconds here the label is centered on this interval (useful for Monday, January etcetera).

As you can see, your x-grid option is too short as you have omitted the labelling intervals:

"--x-grid", "MINUTE:12:HOUR:1:0:%H",

Try this instead, which labels every 4h:

"--x-grid", "MINUTE:12:HOUR:1:HOUR:4:0:%H

Steve Shipway
  • 3,754
  • 3
  • 22
  • 39
  • When I Try this instead, which labels every 4h: "--x-grid", "MINUTE:12:HOUR:1:HOUR:4:0:%H" Then I execute " python graph.py " . It report error : Traceback (most recent call last): File "graph.py", line 31, in "GPRINT:outbits:MIN:MIN Out traffic\: %6.21f %Sbps\\r") rrdtool.OperationalError: bad format for GPRINT in 'Avg In traffic: %6.21f %sbps' . How can I slove this problem ? – Andrew8460958 Jul 10 '18 at 08:05
  • That is separate error, and looks like you have `%6.21f` where you probably meant to have `%6.2lf`. It is an error in the GRPRINT format string, as the error states. – Steve Shipway Jul 11 '18 at 09:00