Created
April 1, 2009 23:48
-
-
Save joshrendek/88951 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/env php | |
<?php | |
$host = "http://servly.com/rrd/update"; | |
error_reporting(E_NONE); | |
echo "\n"; | |
$mon = array(); | |
sleep(5); // so it reads properly | |
/* CPU Usage */ | |
$cpu = `sar 1 | awk 'END {print \$NF}'`; | |
$mon[cpu][free] = $cpu; | |
$mon[cpu][used] = 100-$mon[cpu][free]; | |
/* Load */ | |
$load = `uptime | awk -F"load average: " '{print \$2}' | awk '{print | |
\$1}' | awk -F"," '{print \$1}'`; | |
/* MEMORY USAGE */ | |
$memory = `sar -r 1 | tail -n 1`; | |
$mon[mem][free] = `echo "$memory" | awk '{print $2}'`; | |
$mon[mem][used] = `echo "$memory" | awk '{print $3}'`; | |
$mon[mem][buffers] = `echo "$memory" | awk '{print $5}'`; | |
$mon[mem][cached] = `echo "$memory" | awk '{print $6}'`; | |
$mon[mem][swapfree] = `echo "$memory" | awk '{print $7}'`; | |
$mon[mem][swapused] = `echo "$memory" | awk '{print $8}'`; | |
/* PROCESSES RUNNING */ | |
$mon[processes] = `ps ax | grep -c ""`; | |
/* NETWORK STATS */ | |
//$network = `sar -n DEV 1 -o | grep eth0 | tail -n 1`; | |
$network = `cat /proc/net/dev | grep eth0 | cut -d: -f2`; | |
$mon[net][tx] = `echo "$network" | awk '{print $9}'`; | |
$mon[net][rx] = `echo "$network" | awk '{print $1}'`; | |
/* DISK STATS */ | |
/* If you have logical volgroup's, change to : df | grep "/" | head -n 2 | tail -n 1*/ | |
$disk = `df | grep "/" | head -n 2 | tail -n 1`; | |
$mon[disk][size] = `echo "$disk" | awk '{print $1}'`; | |
$mon[disk][used] = `echo "$disk" | awk '{print $2}'`; | |
print_r($mon); | |
// lets send it to the host! | |
$post_data = array(); | |
$post_data['cpufree'] = | |
$mon[cpu][free]; | |
$post_data['freemem'] = | |
$mon[mem][free]; | |
$post_data['load'] = $load; | |
$post_data['mem_free'] = | |
$mon[mem][free]; | |
$post_data['mem_used'] = | |
$mon[mem][used]; | |
$post_data['mem_buffers'] = | |
$mon[mem][buffers]; | |
$post_data['mem_cached'] = | |
$mon[mem][cached]; | |
$post_data['net_tx'] = | |
$mon[net][tx]; | |
$post_data['net_rx'] = | |
$mon[net][rx]; | |
$post_data['procs'] = | |
$mon[processes]; | |
$post_data['disk_size'] = $mon[disk][size]; | |
$post_data['disk_used']= $mon[disk][used]; | |
$url = $host; | |
$o=""; | |
foreach ($post_data as | |
$k=>$v) | |
{ | |
$o.= | |
"$k=".utf8_encode($v)."&"; | |
} | |
$post_data=substr($o,0,-1); | |
$ch = curl_init(); | |
curl_setopt($ch, | |
CURLOPT_POST, 1); | |
curl_setopt($ch, | |
CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_URL, | |
$url); | |
curl_setopt($ch, | |
CURLOPT_POSTFIELDS, $post_data); | |
$result = curl_exec($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment