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网格格式
我怎样才能解决这个问题呢?
发布于 2018-07-10 05:02:10
这是错误:
rrdtool.OperationalError: invalid x-grid format
X轴
-x|--x-grid GTM:GST:MTM:MST:LTM:LST:LPR:LFM
X轴标签的配置相当复杂。如果您没有非常特殊的需求,最好是依靠自动配置来实现这一点。可以指定字符串none以同时禁止显示栅格和标签。
网格是通过在TM位置指定一定的时间来定义的。您可以选择秒、分钟、小时、日、周、月或年。然后,您可以定义每行或标签之间应该传递多少个这样的值。需要为基础网格(G??)、主网格(M??)指定此对(?TM:?ST)。和标签(L??)。对于标签,还必须在LPR中定义精度,在LFM中定义strftime格式字符串。LPR定义了每个标签的放置位置。如果它是零,标签将被放置在相应的行的正下方(适用于小时、日期等)。如果您在此处指定秒数,标签将以此间隔为中心(适用于星期一、一月等)。
如您所见,您的x-grid选项太短,因为您省略了标签间隔:
"--x-grid", "MINUTE:12:HOUR:1:0:%H",
试试这个,它每隔4小时标记一次:
"--x-grid", "MINUTE:12:HOUR:1:HOUR:4:0:%H
https://stackoverflow.com/questions/51242665
复制相似问题