blob: c71857e7ffe187d816ee17c4fa3af428ad948519 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/usr/bin/php
<?php
$listen = 0;
$jiffies_count = 0;
$date_count = 0;
$rx_count = 0;
$tx_count = 0;
$rxb_count = 0;
$txb_count = 0;
$total_packets = 0;
$total_bytes= 0;
while (($line = fgets(STDIN)) !== FALSE)
{
if (preg_match("/^eth/", $line))
$listen = 1;
else if (preg_match("/^lo/", $line))
$listen = 0;
else if (preg_match("/^Jiffies ([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*)/", $line, $matches))
{
if ($jiffies_count++ == 0)
$previous_jiffies = $matches;
else
{
echo "Jiffies";
for ($i = 1; $i <= 4; $i++)
echo " " . ($matches[$i] - $previous_jiffies[$i]);
echo "\n";
}
}
else if (preg_match("/^[^ ].* ([0-9]*):([0-9]*):([0-9]*)/", $line, $matches))
{
if ($date_count++ == 0)
$previous_date = $matches;
else
{
$elapsed = ($matches[3] - $previous_date[3]);
$elapsed += 60 * ($matches[2] - $previous_date[2]);
$elapsed += 3600 * ($matches[1] - $previous_date[1]);
echo "Elapsed clock time: " . $elapsed . "\n";
}
}
else if ($listen == 1)
{
if (preg_match("/RX packets:([0-9]*)/", $line, $matches))
{
if ($rx_count++ == 0)
$previous_rx = $matches;
else
{
echo "RX packets " . ($matches[1] - $previous_rx[1]) . "\n";
$total_packets += ($matches[1] - $previous_rx[1]);
}
}
else if (preg_match("/TX packets:([0-9]*)/", $line, $matches))
{
if ($tx_count++ == 0)
$previous_tx = $matches;
else
{
echo "TX packets " . ($matches[1] - $previous_tx[1]) . "\n";
$total_packets += ($matches[1] - $previous_tx[1]);
}
}
else if (preg_match("/RX bytes:([0-9]*).*TX bytes:([0-9]*)/", $line, $matches))
{
if ($rxb_count++ == 0)
$previous_rxb = $matches;
else
{
echo "RX bytes " . ($matches[1] - $previous_rxb[1]) . "\n";
$total_bytes += ($matches[1] - $previous_rxb[1]);
echo "TX bytes " . ($matches[2] - $previous_rxb[2]) . "\n";
$total_bytes += ($matches[2] - $previous_rxb[2]);
echo "Total packets: " . $total_packets . "\n";
echo "Total bytes: " . $total_bytes. "\n";
}
}
}
}
?>
|