Created
February 29, 2012 14:08
-
-
Save vvuksan/1941115 to your computer and use it in GitHub Desktop.
Ganglia alert on trend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$rrd_file = "/var/lib/ganglia/rrds/Test Cluster/localhost.localdomain/load_one.rrd"; | |
$command = "/usr/bin/rrdtool xport --start '-600s' --end '-30s' "; | |
$command .= " --daemon unix:/tmp/rrdcached.limited.sock "; | |
$command .= "DEF:'sum'='" . $rrd_file . ":sum':AVERAGE XPORT:sum:metric_value VDEF:D2=sum,LSLSLOPE "; | |
$command .= "VDEF:H2=sum,LSLINT CDEF:avg2=sum,POP,D2,COUNT,*,H2,+ XPORT:avg2:trend"; | |
// Read in the XML | |
$fp = popen($command,"r"); | |
$string = ""; | |
while (!feof($fp)) { | |
$buffer = fgets($fp, 4096); | |
$string .= $buffer; | |
} | |
// Parse it | |
$xml = simplexml_load_string($string); | |
foreach ( $xml->data->row as $key => $objects ) { | |
$values = get_object_vars($objects); | |
$percent_diff = abs(100.0 * ( 1 - ( $values['v'][0] / $values['v'][1] ))); | |
print $percent_diff . "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment