/
info2.sh
executable file
·117 lines (90 loc) · 3.67 KB
/
info2.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/php
<?php
/*
This is where all the PHP scripts are for nems-info.
These are called with the nems-info command, not direct.
*/
if (!isset($argv[1])) exit('Invalid usage. Please use the nems-info command.' . PHP_EOL);
switch($argv[1]) {
case 1: // temperature
if (file_exists('/var/log/nems/thermal.log')) {
echo file_get_contents('/var/log/nems/thermal.log');
} else {
echo 0 . PHP_EOL;
}
break;
case 2: // NEMS Version Branch (exclude microversion)
$ver = floatval(shell_exec('/usr/local/bin/nems-info nemsver'));
echo $ver . PHP_EOL;
break;
case 3: // Find the board platform ID number
if (!file_exists('/var/log/nems/hw_model')) shell_exec('/usr/local/share/nems/nems-scripts/hw_model.sh'); // try to detect
if (file_exists('/var/log/nems/hw_model')) { // was reporting 0 (pi 1) when file didn't exist
$tmp = file('/var/log/nems/hw_model');
if ( $tmp[0] == 0 && strtolower(substr($tmp[1],0,14)) == strtolower('Unknown Device') ) $tmp[0] = 98000; // Unknown
} else {
$tmp[0] = 98000; // NEMS' "unknown" ID
}
echo $tmp[0];
break;
case 4: // Load the platform data from the API
$platform['id'] = shell_exec('/usr/local/share/nems/nems-scripts/info.sh platform');
if (!file_exists('/tmp/platform_data')) {
if (file_exists('/var/log/nems/hw_model')) { // try to get it from the hw_model file
$tmp = file('/var/log/nems/hw_model');
$platform['data'] = new stdclass();
$platform['data']->name = trim($tmp[1]);
} else { // try to get it from the online API
$platform['data'] = @json_decode(@file_get_contents('https://nemslinux.com/api/platform/' . $platform['id']));
}
if (is_object($platform['data']) && strlen($platform['data']->name) > 0) {
file_put_contents('/tmp/platform_data',$platform['data']->name);
chmod('/tmp/platform_data',0444);
}
} else {
$platform['data']=new stdclass();
$platform['data']->name=file_get_contents('/tmp/platform_data');
}
if (isset($platform['data'])) {
echo $platform['data']->name;
} else {
echo '[API Did Not Respond]';
}
break;
case 6: // list scheduled downtime
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/nems-api/downtimes');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
break;
}
function monitorix($db) {
switch ($db) {
case 'apache':
return rrd_fetch( "/var/lib/monitorix/apache.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'fs':
return rrd_fetch( "/var/lib/monitorix/fs.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'int':
return rrd_fetch( "/var/lib/monitorix/int.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'kern':
return rrd_fetch( "/var/lib/monitorix/kern.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'net':
return rrd_fetch( "/var/lib/monitorix/net.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'raspberrypi':
return rrd_fetch( "/var/lib/monitorix/raspberrypi.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
case 'system':
return rrd_fetch( "/var/lib/monitorix/system.rrd", array( "AVERAGE", "--resolution", "60", "--start", "-1d", "--end", "start+1h" ) );
break;
}
}
?>