diff options
author | Filipp Lepalaan <filipp@mac.com> | 2010-08-19 22:51:19 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2010-08-19 22:51:19 +0300 |
commit | 40964f4747fadb7741113afb7551d584ea390052 (patch) | |
tree | 9b9af8160b4aec87427c48430a6328431c62ee9d /pingraph.php | |
parent | f9203a2f1efb3ead863616cdca3eac41da3b6575 (diff) | |
download | mtk-40964f4747fadb7741113afb7551d584ea390052.tar.gz mtk-40964f4747fadb7741113afb7551d584ea390052.tar.bz2 mtk-40964f4747fadb7741113afb7551d584ea390052.zip |
added pingraph
Diffstat (limited to 'pingraph.php')
-rwxr-xr-x | pingraph.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/pingraph.php b/pingraph.php new file mode 100755 index 0000000..62b2187 --- /dev/null +++ b/pingraph.php @@ -0,0 +1,60 @@ +<?php + +$interval = 3; +$infile = '/tmp/ping.out'; +$outfile = $infile.'.csv'; + +$ts = filemtime($infile); +$ifh = fopen($infile, 'r') or die('Failed to open ' . $infile); +$ofh = fopen($outfile, 'w+') or die('Failed to open ' . $outfile); + +$i = 0; +$offset = 0; +$data = array(); +$columns = array(); +$max_ping = 0; +$min_ping = 0; + +while (!feof($ifh)) { + $line = fgets($ifh, 4096); + preg_match('/from (\d+\.\d+\.\d+\.\d+) icmp_seq=(\d+) ttl=\d+ time=(\d+\.\d+)/', $line, $m); + if (!empty($m)) { + $ts += $interval; + $time = $m[2]; + if ($time > $max_ping) { + $max_ping = $time; + } + $data[] = sprintf('{%s}', $time); + $date = @date('U', $ts); + $columns[] = sprintf('"%s"', $date); + fwrite($ofh, "$date, $time\n"); + } + $i++; +} + +fclose($ifh); +fclose($ofh); + +// Keynote can't really handle more +if ($i > 100) { + exit(); +} + +$data = implode(',', $data); +$columns = implode(',', $columns); + +$as =<<<EOT + tell application "Keynote" + set theData to {{$data}} + set theSlide to (slide 1) of first slideshow + tell theSlide + add chart row names {{$columns}} column names {"ping"} ¬ + data theData type "line_2d" group by "column" + end tell + end tell +EOT; + +file_put_contents('/tmp/ping.scpt', $as); +`osascript /tmp/ping.scpt`; +echo "Max ping: $max_ping"; +?> |