Domanda

I have a RRD database that I am trying to create, and I have a couple loops written to build the command, which works fine, and produces the expected output. The problem arises when I actually try to run the rrdtool.create command in Python. This loop produces a string, we will call it rrdStr, containing the following:

'"0x04.rrd", "--step","5",
"DS:TEMP:GAUGE:10:0:100",
"DS:HUMIDITY:GAUGE:10:0:100",
"DS:LIGHT:GAUGE:10:0:1024",
"DS:POT:GAUGE:10:0:1024",
"RRA:AVERAGE:0.5:1:17142",
"RRA:MIN:0.5:1:17142",
"RRA:MAX:0.5:1:17142",
"RRA:AVERAGE:0.5:12:7200",
"RRA:MIN:0.5:12:7200",
"RRA:MAX:0.5:12:7200",
"RRA:AVERAGE:0.5:60:8640",
"RRA:MIN:0.5:60:8640",
"RRA:MAX:0.5:60:8640",
"RRA:AVERAGE:0.5:360:17532",
"RRA:MIN:0.5:360:17532",
"RRA:MAX:0.5:360:17532"'

All the quotes and newline characters are escaped correctly as far as I can tell.

If i pass the rrdtool.create the string variable like this: rrdtool.create(rrdStr), I get the output

rrdtool.error: you must define at least one Round Robin Archive

But, if I copy and paste the above output directly into the rrdtool.create() function, it works like it is supposed to, and creates the database.

Any idea what causes this and how to fix it?

È stato utile?

Soluzione

So I finally figured it out. Rather than creating one long string that contains all of the commands correctly formatted, you must create a list, each line of the rrd command is added to the list as the command is generated.

The command above becomes:

rrdStr = ["0x04.rrd", "--step","5"]
rrdStr += ["DS:TEMP:GAUGE:10:0:100"]
rrdStr += ["DS:HUMIDITY:GAUGE:10:0:100"]
rrdStr += ["DS:LIGHT:GAUGE:10:0:1024"]
rrdStr += ["DS:POT:GAUGE:10:0:1024"]
rrdStr += ["RRA:AVERAGE:0.5:1:17142"]
rrdStr += ["RRA:MIN:0.5:1:17142"]
rrdStr += ["RRA:MAX:0.5:1:17142"]
rrdStr += ["RRA:AVERAGE:0.5:12:7200"]
rrdStr += ["RRA:MIN:0.5:12:7200"]
rrdStr += ["RRA:MAX:0.5:12:7200"]
rrdStr += ["RRA:AVERAGE:0.5:60:8640"]
rrdStr += ["RRA:MIN:0.5:60:8640"]
rrdStr += ["RRA:MAX:0.5:60:8640"]
rrdStr += ["RRA:AVERAGE:0.5:360:17532"]
rrdStr += ["RRA:MIN:0.5:360:17532"]
rrdStr += ["RRA:MAX:0.5:360:17532"]

You can then pass the list as the only command rrdtool.create(rrdStr) The same command that failed before will then run successfully

Altri suggerimenti

use rrdtool.create(*rrdStr) on python2.6 rrdtool-python-1.3.8-6.el6.x86_64

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top