Så här gjorde jag:
Kod: Markera allt
#!/usr/bin/php
<?php
$db=temp.rrd;
passthru("cp /special/termo/rrdb/$db /home");
passthru("rrdtool dump /special/termo/rrdb/$db >/tmp/temp.xml");
$infile = "/tmp/temp.xml";
$outfile= "/tmp/temp.xml.expanded";
$i=0;
$in = fopen($infile, "r");
$out = fopen($outfile, "w");
#headers
while ($i < 20){
fputs($out,fgets($in));
$i++;
}
#AVERAGE
$line = fgets($in);
while (!stristr($line, "</rrd>")) {
fputs($out,$line);
$line = fgets($in);
}
fclose($in);
$in = fopen($infile, "r");
$i = 0;
while ($i < 20){
fgets($in);
$i++;
}
$line = fgets($in);
while (!stristr($line, "</rrd>")) {
fputs($out,str_replace("AVERAGE","MIN",$line));
$line = fgets($in);
}
fclose($in);
$in = fopen($infile, "r");
$i = 0;
while ($i < 20){
fgets($in);
$i++;
}
$line = fgets($in);
while (!stristr($line, "</rrd>")) {
fputs($out,str_replace("AVERAGE","MAX",$line));
$line = fgets($in);
}
fclose($in);
fputs($out,"</rrd>");
fclose($out);
}
passthru("rrdtool restore /tmp/temp.xml.expanded /tmp/$db");
passthru("mv /tmp/$db /special/termo/rrdb");
}
?>
Kanske inte helt lätt att följa koden.
Men jag dumpar databasen till xml och skapar sedan en ny XML-fil med både MIN/MAX och AVERAGE utifrån AVERAGE-värdena. De historiska MIN/MAX är egentligen AVERAGE över 1h, men det går ju inte att få fram data som redan medelvärdesbildas.