Python rrdtool.ERROR:无效的x-grid格式

Python rrdtool.ERROR:无效的x-grid格式,python,rrdtool,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"

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-grid格式

如何解决此问题?

这是错误:

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

从:

X轴

[-x |--x-grid全球技术手册:商品及服务税:中期技术手册:中期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册:长期技术手册

x轴标签的配置相当复杂。如果你没有足够的时间 特殊需求可能最好依靠自动配置来实现 把这个弄对。可以指定字符串“无”以抑制栅格 和标签

通过在TM中指定一定的时间量来定义网格 位置。您可以选择秒、分钟、小时、天、周、月 或者一年。然后,您定义其中有多少应该在每个 线条或标签。需要为底座指定这对(?TM:?ST) 网格(G??),主网格(M??)和标签(L??)。对于标签 您还必须定义LPR中的精度和strftime格式字符串 在LFM中。LPR定义每个标签的放置位置。如果是零, 标签将放置在相应行的正下方(有用 时间、日期等等)。如果在此处指定秒数 标签以该间隔为中心(适用于1月1日星期一) 等等)

如您所见,您的x-grid选项太短,因为您忽略了标签间隔:

“--x-grid”,“分钟:12:HOUR:1:0:%H”,

改为试试这个,每4小时贴一次标签:


“--x-grid”,“分钟:12:HOUR:1:HOUR:4:0:%H

当我尝试此方法时,它每4h标记一次:“--x-grid”,“分钟:12:HOUR:1:HOUR:4:0:%H”,然后我执行“python-graph.py”。它报告错误:回溯(最近一次调用):文件“graph.py”,第31行,“GPRINT:outbits:MIN:Out-traffic\:%6.21f%Sbps\\r“”)rrdtool.OperationalError:“平均流量:%6.21f%sbps”中的GPRINT格式错误。如何解决此问题?这是一个单独的错误,看起来您有
%6.21f
,而您可能打算有
%6.2lf
。正如错误所述,这是GRPRINT格式字符串中的错误。