-
Notifications
You must be signed in to change notification settings - Fork 0
/
desk-clock.php
84 lines (73 loc) · 2.81 KB
/
desk-clock.php
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
82
83
84
<?php
// Linux Interface statistics service for ESP8266
//
function formatBytes($bytes, $unit = "", $decimals = 2) {
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
if ($bytes > 0) {
// Generate automatic prefix by bytes
// If wrong prefix given
if (!array_key_exists($unit, $units)) {
$pow = floor(log($bytes)/log(1024));
$unit = array_search($pow, $units);
}
// Calculate byte value by prefix
$value = ($bytes/pow(1024,floor($units[$unit])));
}
// If decimals is not numeric or decimals is less than 0
// then set default value
if (!is_numeric($decimals) || $decimals < 0) {
$decimals = 2;
}
// Format output
return sprintf('%.' . $decimals . 'f '.$unit, $value);
}
//function speed($inf){
$ppp0rx1=file_get_contents('/sys/class/net/ppp0/statistics/rx_bytes');
$ppp0tx1=file_get_contents('/sys/class/net/ppp0/statistics/tx_bytes');
$sit1rx1=file_get_contents('/sys/class/net/sit1/statistics/rx_bytes');
$sit1tx1=file_get_contents('/sys/class/net/sit1/statistics/tx_bytes');
//sleep(1);
usleep(125000); //saniyenin 1/8
$ppp0rx2=file_get_contents('/sys/class/net/ppp0/statistics/rx_bytes');
$ppp0tx2=file_get_contents('/sys/class/net/ppp0/statistics/tx_bytes');
$sit1rx2=file_get_contents('/sys/class/net/sit1/statistics/rx_bytes');
$sit1tx2=file_get_contents('/sys/class/net/sit1/statistics/tx_bytes');
$ppp0rx = ($ppp0rx2-$ppp0rx1)*64;
$ppp0tx = ($ppp0tx2-$ppp0tx1)*64;
$sit1rx = ($sit1rx2-$sit1rx1)*64;
$sit1tx = ($sit1tx2-$sit1tx1)*64;
//}
function formatBytes2($bytes, $unit = "", $decimals = 2) {
$units = array('B' => 0, 'Kb' => 1, 'Mb' => 2, 'Gb' => 3, 'Tb' => 4, 'Pb' => 5, 'Eb' => 6, 'Zb' => 7, 'Yb' => 8);
$value = 0;
if ($bytes > 0) {
// Generate automatic prefix by bytes
// If wrong prefix given
if (!array_key_exists($unit, $units)) {
$pow = floor(log($bytes)/log(1024));
$unit = array_search($pow, $units);
}
// Calculate byte value by prefix
$value = ($bytes/pow(1024,floor($units[$unit])));
}
// If decimals is not numeric or decimals is less than 0
// then set default value
if (!is_numeric($decimals) || $decimals < 0) {
$decimals = 2;
}
// Format output
return sprintf('%.' . $decimals . 'f '.$unit, $value);
}
?>
{
"ppp0":{"down":"<?php echo formatBytes(file_get_contents('/sys/class/net/ppp0/statistics/rx_bytes'));?>",
"up":"<?php echo formatBytes(file_get_contents('/sys/class/net/ppp0/statistics/tx_bytes'));?>",
"rxs":"<?php echo formatBytes2($ppp0rx)?>",
"txs":"<?php echo formatBytes2($ppp0tx)?>"},
"sit1":{"down":"<?php echo formatBytes(file_get_contents('/sys/class/net/sit1/statistics/rx_bytes'));?>",
"up":"<?php echo formatBytes(file_get_contents('/sys/class/net/sit1/statistics/tx_bytes'));?>",
"rxs":"<?php echo formatBytes2($sit1rx)?>",
"txs":"<?php echo formatBytes2($sit1tx)?>"}
}