-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
53 lines (43 loc) · 1.04 KB
/
api.php
File metadata and controls
53 lines (43 loc) · 1.04 KB
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
<?php
require("config.php");
header('Content-Type: application/json');
set_error_handler(function($errno, $errstr){
err($errstr);
});
function a($a){
$a = intval($a);
if($a==NULL)return NULL;
return sprintf("%02d", $a);
}
function parseChart($str){
$list = explode(".", $str);
if(sizeof($list)==2){
$a = a($list[0]);
if($a==NULL)return NULL;
$b = a($list[1]);
if($b==NULL)return NULL;
return $a.".".$b;
}else return NULL;
}
function err($msg){
$msg = array("ok"=>0, "Error"=>$msg);
exit(json_encode($msg));
}
if(!isset($_GET["chart"]))err("chart name not set");
$chart = parseChart($_GET["chart"]);
if($chart==NULL)err("Invalid chart name");
$content = file_get_contents($FOLDER."/".$chart.".txt");
$ret = [];
$ret["ok"] = 1;
$ret["time"] = [];
$ret["ram"] = [];
$ret["cpu"] = [];
foreach(explode("\n", $content) as $line){
if($line=="")break;
$s = explode(" ", $line);
array_push($ret["time"], $s[0]);
array_push($ret["ram"], $s[1]);
if(sizeof($s)==3)array_push($ret["cpu"], $s[2]); // temp
}
echo json_encode($ret);
?>