Python rrdtool.OperationalError:无效的X网格格式

时间:2018-07-09 09:52:32

标签: python rrdtool

graph.py的代码是:

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

# 在图表上方定义标题

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

# 生成Flow.png文件

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

当我执行“ python graph.py”时

错误报告:

回溯(最近通话最近一次):

文件“ graph.py”,第31行,位于

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

rrdtool.OperationalError:无效的X网格格式

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是错误:

rrdtool.OperationalError: invalid x-grid format

来自RRDTool Manual

  

X轴

     

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

     

x轴标签的配置非常复杂。如果你没有   特殊需求可能最好依靠自动配置   得到这个权利。您可以指定字符串none抑制网格   和标签。

     

通过在?TM中指定一定的时间来定义网格   职位。您可以选择第二,分钟,小时,天,周,月   或YEAR。然后定义每个之间应通过多少个   线或标签。需要为基数指定这对(?TM:?ST)   网格(G25),主网格(M25)和标签(L25)。对于标签   您还必须定义LPR的精度和strftime格式的字符串   在LFM中。 LPR定义每个标签的放置位置。如果是零   标签将被放置在相应行的正下方(有用   时间,日期等)。如果您在此处指定秒数   标签以该间隔为中心(对一月星期一有效)   等)。

如您所见,您的x网格选项太短,因为您省略了标签间隔:

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

请尝试此操作,它每4小时贴一次标签:

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