Initial upload v3.4.7

This commit is contained in:
Jay D Dee
2016-09-22 13:16:18 -04:00
parent a3c8079774
commit a35039bc05
480 changed files with 211015 additions and 3 deletions

197
api/index.php Normal file
View File

@@ -0,0 +1,197 @@
<?php
/* cpuminer API sample UI */
$host = 'http://localhost/api/'; // 'http://'.$_SERVER['SERVER_NAME'].'/api/';
$configs = array(
'LOCAL'=>'local-sample.php',
//'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */
);
// 3 seconds max.
set_time_limit(3);
error_reporting(0);
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 ignoreField($key)
{
$ignored = array('API','VER','GPU','CARD','GPUS','CPU');
return in_array($key, $ignored);
}
function translateField($key)
{
$intl = array();
$intl['NAME'] = 'Software';
$intl['VER'] = 'Version';
$intl['ALGO'] = 'Algorithm';
$intl['GPUS'] = 'GPUs';
$intl['CPUS'] = 'Threads';
$intl['KHS'] = 'Hash rate (kH/s)';
$intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn';
$intl['REJ'] = 'Rejected';
$intl['DIFF'] = 'Difficulty';
$intl['UPTIME'] = 'Miner up time';
$intl['TS'] = 'Last update';
$intl['TEMP'] = 'T°c';
$intl['FAN'] = 'Fan %';
$intl['FREQ'] = 'Freq.';
$intl['PST'] = 'P-State';
if (isset($intl[$key]))
return $intl[$key];
else
return $key;
}
function translateValue($key,$val,$data=array())
{
switch ($key) {
case 'UPTIME':
$min = floor(intval($val) / 60);
$sec = intval($val) % 60;
$val = "${min}mn${sec}s";
if ($min > 180) {
$hrs = floor($min / 60);
$min = $min % 60;
$val = "${hrs}h${min}mn";
}
break;
case 'NAME':
$val = $data['NAME'].'&nbsp;'.$data['VER'];
break;
case 'FREQ':
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
break;
case 'TS':
$val = strftime("%H:%M:%S", (int) $val);
break;
}
return $val;
}
function displayData($data)
{
$htm = '';
$totals = array();
foreach ($data as $name => $stats) {
$htm .= '<table id="tb_'.$name.'" class="stats">'."\n";
$htm .= '<tr><th class="machine" colspan="2">'.$name."</th></tr>\n";
if (!empty($stats)) {
$summary = (array) $stats['summary'];
foreach ($summary as $key=>$val) {
if (!empty($val) && !ignoreField($key))
$htm .= '<tr><td class="key">'.translateField($key).'</td>'.
'<td class="val">'.translateValue($key, $val, $summary)."</td></tr>\n";
}
if (isset($summary['KHS']))
@ $totals[$summary['ALGO']] += floatval($summary['KHS']);
foreach ($stats['threads'] as $g=>$gpu) {
$card = isset($gpu['CARD']) ? $gpu['CARD'] : '';
$htm .= '<tr><th class="gpu" colspan="2">'.$g." $card</th></tr>\n";
foreach ($gpu as $key=>$val) {
if (!empty($val) && !ignoreField($key))
$htm .= '<tr><td class="key">'.translateField($key).'</td>'.
'<td class="val">'.translateValue($key, $val)."</td></tr>\n";
}
}
}
$htm .= "</table>\n";
}
// totals
if (!empty($totals)) {
$htm .= '<div class="totals"><h2>Total Hash rate</h2>'."\n";
foreach ($totals as $algo => $hashrate) {
$htm .= '<li><span class="algo">'.$algo.":</span>$hashrate kH/s</li>\n";
}
$htm .= '</div>';
}
return $htm;
}
$data = getdataFromPears();
?>
<html>
<head>
<title>cpuminer rig api sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="refresh" content="10">
<style type="text/css">
body {
color:#cccccc; background:#1d1d1d; margin:30px 30px 0px 30px; padding:0px;
font-size:.8em; font-family:Arial,Helvetica,sans-serif;
}
a { color:#aaaaaa; text-decoration: none; }
a:focus { outline-style:none; }
.clear { clear: both; }
div#page, div#header, div#footer {
margin: auto;
width: 950px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
div#page {
padding-top: 8px;
background: #252525;
min-height: 820px;
}
div#header {
background: rgba(65, 65, 65, 0.85);
height: 50px;
margin-bottom: 24px;
padding-left: 8px;
}
div#footer {
background: rgba(25, 25, 25, 0.85);
height: 0px;
margin-bottom: 40px;
text-align: center;
color: #666666;
text-shadow: rgba(0, 0, 0, 0.8) 0px 1px 0px;
}
#header h1 { padding: 12px; font-size: 20px; }
#footer p { margin: 12px 24px; }
table.stats { width: 280px; margin: 4px 16px; display: inline-block; }
th.machine { color: darkcyan; padding: 16px 0px 0px 0px; text-align: left; border-bottom: 1px solid gray; }
th.gpu { color: white; padding: 3px 3px; font: bolder; text-align: left; background: rgba(65, 65, 65, 0.85); }
td.key { width: 99px; max-width: 180px; }
td.val { width: 40px; max-width: 100px; color: white; }
div.totals { margin: 16px; padding-bottom: 16px; }
div.totals h2 { color: darkcyan; font-size: 16px; margin-bottom: 4px; }
div.totals li { list-style-type: none; font-size: 16px; margin-left: 4px; margin-bottom: 8px; }
li span.algo { display: inline-block; width: 100px; max-width: 180px; }
</style>
</head>
<body>
<div id="header">
<h1>cpuminer monitoring API RIG sample</h1>
</div>
<div id="page">
<?=displayData($data)?>
</div>
<div id="footer">
<p>&copy; 2014 <a href="http://github.com/tpruvot/cpuminer-multi">tpruvot@github</a></p>
</div>
</body>
</html>

137
api/local-sample.php Normal file
View File

@@ -0,0 +1,137 @@
<?php
/**
* Sample Request API to ccminer
*/
defined('API_HOST') || define('API_HOST', '127.0.0.1');
defined('API_PORT') || define('API_PORT', 4048);
// 2 seconds max.
set_time_limit(2);
function getsock($port)
{
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false || $socket === null) {
$error = socket_strerror(socket_last_error());
$msg = "socket create($port) failed";
echo "ERR: $msg '$error'\n";
return NULL;
}
socket_set_nonblock($socket);
$res = socket_connect($socket, API_HOST, $port);
$timeout = 50;
while ($res === false && $timeout > 0) {
$err = socket_last_error($socket);
echo ".";
if ($timeout > 1 && ($err == 115 || $err == 114)) {
$timeout--;
usleep(50);
$res = socket_connect($socket, API_HOST, $port);
continue;
}
$error = socket_strerror($err);
$msg = "socket connect($port) failed";
echo "ERR: $msg '$error'\n";
socket_close($socket);
return NULL;
}
socket_set_block($socket);
return $socket;
}
function readsockline($socket)
{
$line = '';
while (true) {
$byte = socket_read($socket, 1);
if ($byte === false || $byte === '')
break;
if ($byte === "\0")
break;
$line .= $byte;
}
return $line;
}
function request($cmd)
{
$socket = getsock(API_PORT);
if ($socket == null)
return NULL;
socket_write($socket, $cmd, strlen($cmd));
$line = readsockline($socket);
socket_close($socket);
if (strlen($line) == 0) {
echo "WARN: '$cmd' returned nothing\n";
return $line;
}
echo "$cmd returned '$line'\n";
$data = array();
$objs = explode('|', $line);
foreach ($objs as $obj)
{
if (strlen($obj) > 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();
error_reporting(0);
$summary = request('summary');
$threads = request('threads');
$histo = request('histo');
ob_end_clean(); /* swap to debug */
//echo ob_get_clean()."\n";
header("Content-Type: application/json");
echo json_encode(compact('summary', 'threads', 'histo'))."\n";
?>

69
api/websocket.htm Normal file
View File

@@ -0,0 +1,69 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<title>Simple WebSocket call sample</title>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script type="text/javascript">
function displayData(ip, data) {
$('#container').html($("<div></div>").html(data));
}
function getData(ip, port) {
if ("WebSocket" in window) {
var ws = new WebSocket('ws://'+ip+':'+port+'/summary','text');
ws.onmessage = function (evt) {
var html = '';
var now = new Date();
var ts = Math.round(now/1000);
var data = evt.data.split('|');
for (n in data) {
var map = data[n].split(';');
var cpu = 0;
for (k in map) {
var kv = map[k].split('=');
if (kv.length == 1)
continue;
html = html + kv[0]+' = '+kv[1] + '<br/>';
// console.log('Data received: #CPU'+cpu+': '+kv[0]+' = '+kv[1]);
}
}
displayData(ip, html);
};
ws.onerror = function (evt) {
var w = evt.target;
console.log('Error! readyState=' + w.readyState); //log errors
$('#container').html('Error! Unable to get WebSocket data from '+ip); //log errors
return false;
};
ws.onclose = function() {
// websocket is closed.
};
} else {
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
var to = 0;
/* ajax auto refresh */
function refreshData() {
clearTimeout(to);
getData('192.168.0.110', 4048);
//getData('localhost', 4048);
to = setTimeout('refreshData()', 2000);
}
$(function () {
refreshData();
});
</script>
</body>
</html>