public static function addDS2RRDFile($rrdFileName, $newDS) { //Get Existing Datasources $datassources = self::getDSFromRRDFile($rrdFileName); //Add New DataSources $datassources[] = $newDS; //Create array with DS Options $dsoptions = array(); foreach ($datassources as $ds) { $dsoptions[] = RRD::getDSOption($ds); } //get RRD Options $rrdOptions = RRD::getRRDFileOptions($dsoptions); //Move OriginalFile to /tmp $tmpFileName = "/tmp/tmp.rrd"; rename($rrdFileName, $tmpFileName); //add source options $rrdOptions[] = "-r"; $rrdOptions[] = $tmpFileName; echo "\n\nUPDATE RRD\n\n"; print_r($rrdOptions); echo "\n\n+++++++++++\n\n"; echo $rrdFileName; echo "\n\n###########\n\n"; //create new RRDFile //RRD::createRRDFile($rrdFileName,$rrdOptions); $cmd = "rrdcreate " . $rrdFileName . " " . implode(" ", $rrdOptions); echo $cmd; echo "\n"; shell_exec($cmd); }