From 3dcfa5d84f1fced31f6a03860b88aeec9f11a8b1 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 13 Nov 2014 21:07:14 +0100 Subject: [PATCH] api: add a sample rig web ui (php) --- README.txt | 4 +- api/index.php | 130 ++++++++++++++ api-example.php => api/local-sample.php | 230 ++++++++++++------------ 3 files changed, 247 insertions(+), 117 deletions(-) create mode 100644 api/index.php rename api-example.php => api/local-sample.php (95%) diff --git a/README.txt b/README.txt index 62a7e3c..dcdd6a4 100644 --- a/README.txt +++ b/README.txt @@ -156,8 +156,8 @@ features. >>> RELEASE HISTORY <<< Nov. 13th 2014 v1.4.9 - Add nvml unit to monitor nvidia cards (api) - API: small changes, bump v1.1 + Support of nvml and nvapi to monitor gpus + api: Fix multi gpus stats, bump API v1.1 Nov. 12th 2014 v1.4.8 Add a basic API and sample php json wrapper diff --git a/api/index.php b/api/index.php new file mode 100644 index 0000000..8ae6518 --- /dev/null +++ b/api/index.php @@ -0,0 +1,130 @@ +'local-sample.php', + //'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */ +); + +function getdataFromPears() +{ + global $host, $configs; + $data = array(); + foreach ($configs as $name => $conf) { + + $json = file_get_contents($host.$conf); + + $data[$name] = json_decode($json, TRUE); + } + return $data; +} + +function translateField($key) +{ + $intl = array(); + $intl['NAME'] = 'Software'; + $intl['VER'] = 'Version'; + + $intl['ALGO'] = 'Algorithm'; + $intl['KHS'] = 'Hashrate (kH/s)'; + $intl['ACC'] = 'Accepted shares'; + $intl['ACCMN'] = 'Accepted / mn'; + $intl['REJ'] = 'Rejected'; + $intl['UPTIME'] = 'Miner uptime'; + + $intl['TEMP'] = 'T°c'; + $intl['FAN'] = 'Fan %'; + + if (isset($intl[$key])) + return $intl[$key]; + else + return $key; +} + +function displayData($data) +{ + $htm = ''; + foreach ($data as $name => $stats) { + $htm .= ''."\n"; + $htm .= '\n"; + foreach ($stats['summary'] as $key=>$val) { + if (!empty($val)) + $htm .= ''. + '\n"; + } + foreach ($stats['stats'] as $g=>$gpu) { + $htm .= '\n"; + foreach ($gpu as $key=>$val) { + if (!empty($val)) + $htm .= ''. + '\n"; + } + } + $htm .= "
'.$name."
'.translateField($key).''.$val."
'.$g."
'.translateField($key).''.$val."
\n"; + } + return $htm; +} + +$data = getdataFromPears(); + +?> + + +ccminer rig api sample + + + + + +
+ +
+ + + + + diff --git a/api-example.php b/api/local-sample.php similarity index 95% rename from api-example.php rename to api/local-sample.php index 8459922..edf9df8 100644 --- a/api-example.php +++ b/api/local-sample.php @@ -1,115 +1,115 @@ - 0) - { - $items = explode(';', $obj); - $item = $items[0]; - $id = explode('=', $items[0], 2); - if (count($id) == 1) - $name = $id[0]; - else - $name = $id[0].$id[1]; - - if (strlen($name) == 0) - $name = 'null'; - - if (isset($data[$name])) { - $num = 1; - while (isset($data[$name.$num])) - $num++; - $name .= $num; - } - - $counter = 0; - foreach ($items as $item) - { - $id = explode('=', $item, 2); - if (count($id) == 2) - $data[$name][$id[0]] = $id[1]; - else - $data[$name][$counter] = $id[0]; - - $counter++; - } - - } - } - if ($cmd == 'summary') - return array_pop($data); - else - return $data; -} - -ob_start(); -$summary = request('summary'); -$stats = request('stats'); -ob_end_clean(); -//echo ob_get_clean()."\n"; - -header("Content-Type: application/json"); -echo json_encode(compact('summary', 'stats'))."\n"; -?> + 0) + { + $items = explode(';', $obj); + $item = $items[0]; + $id = explode('=', $items[0], 2); + if (count($id) == 1) + $name = $id[0]; + else + $name = $id[0].$id[1]; + + if (strlen($name) == 0) + $name = 'null'; + + if (isset($data[$name])) { + $num = 1; + while (isset($data[$name.$num])) + $num++; + $name .= $num; + } + + $counter = 0; + foreach ($items as $item) + { + $id = explode('=', $item, 2); + if (count($id) == 2) + $data[$name][$id[0]] = $id[1]; + else + $data[$name][$counter] = $id[0]; + + $counter++; + } + + } + } + if ($cmd == 'summary') + return array_pop($data); + else + return $data; +} + +ob_start(); +$summary = request('summary'); +$stats = request('stats'); +ob_end_clean(); +//echo ob_get_clean()."\n"; + +header("Content-Type: application/json"); +echo json_encode(compact('summary', 'stats'))."\n"; +?>