1
0
mirror of https://github.com/GOSTSec/ccminer synced 2025-01-09 14:28:15 +00:00
ccminer/api/index.php
Tanguy Pruvot bbd2c704f9 multipool: Squashed commit (v2)
commit a9d3c1ffdb71d2a4985749acba3d424161154ab4
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Thu May 21 05:39:24 2015 +0200

    multipool: last changes before squashed merge

    and fix net diff on wallets.. was longpoll specific

commit a63f0024f3f1fb52d2c4369518bf87c33a9e16ae
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Thu May 21 05:02:27 2015 +0200

    update api sample for the protocol 1.5

commit adda14b22edde6485932be56550166478f6f00dd
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Thu May 21 04:43:25 2015 +0200

    stats: store pool number in scanlog

commit e1a0274b01c29409ce16f9096b9985a35cf78ba7
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Thu May 21 03:36:15 2015 +0200

    api: switchpool and new pool stats variables (API v1.5)

    add accepted/rej by pool, wait time on conditional, net diff and rate

    also add scantime per pool config option and do some pool cleanup..

commit 1a30450ad2a5e068983531b9d2a96629b970c1e8
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Wed May 20 06:39:09 2015 +0200

    prevent concurrent pool switching

    and limit condtionnal wait messages to the first thread/device

commit e3922c7a331a3ad2730bc83082fcd6b2547542f5
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Wed May 20 05:39:45 2015 +0200

    add some pool rotate options, like pool time-limit

    update sample pools.conf for time rotation

commit 312bd905412d49fd5a9f9e7ff2bc72b23edf38ed
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Wed May 20 04:31:19 2015 +0200

    do not try to restart threads from threads

    Start inconditionally the stratum and longpoll threads,
    these threads are just waiting a tq_push() if unused...

    so add some checks to know if vars are set for the right pool

commit d4a9428fefdd9e9d70c3c8231f10961e7cd41760
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Wed May 20 01:06:31 2015 +0200

    pools: add name and removed attributes

    also increase max defined pools to 8

    to be tested on windows..

commit d840d683ecb2cc4767f0a0612b8359c52d4bad29
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Tue May 19 22:33:11 2015 +0200

    parse json config file pools array

commit d6c29b1f7f6b786c56e1f0cb8a90305f06cc7aec
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Tue May 19 03:29:30 2015 +0200

    multi-pools: prepare storage/switch of credentials

    for the moment:
    - allow the storage of multiple -o params (and user/pass)
    - allow a failover pool on connection failed
    - switch to the next pool with the "seturl" api remote command
    - longpoll to stratum switch (reverse to check...)

    todo: mix stratum/getwork, new api commands, json config...

commit 2d6b3fddf6631d7df1ac6ca74eee91c33a3c09ee
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Fri May 22 08:26:40 2015 +0200

    multipool: increase stability, but not 100% perfect

    several problems fixed:
    - submit to the pool set in work (source pool)
    - longpoll curl timeout could be too high and could lock the switch
    - mutexes cant be copied on windows (stratum global var to fully remove later)

    I linked the -T timeout option to curl and tried to remove all fixed timeout values

commit 6fd935c369cf33949dab98c8b09b2ca8cab3e7ea
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Fri May 22 11:23:07 2015 +0200

    stratum: remove last rpc_ vars in stratum thread

commit ee9c821525be303282e5dab512ffd2ae81ad524f
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Sat May 23 03:53:50 2015 +0200

    stratum: do not alloc empty merkle tree

commit 69852a2874bd18c4ed1daa9180a10d12976424dc
Author: Tanguy Pruvot <tanguy.pruvot@gmail.com>
Date:   Sat May 23 04:25:12 2015 +0200

    stratum: properly free jobs on disconnect

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-05-23 05:28:12 +02:00

260 lines
6.7 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/* ccminer API sample UI (API 1.5) */
$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 getdataFromPeers()
{
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','BUS','POOLS',
'CARD','GPUS','CPU','TS',
);
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';
$intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn';
$intl['REJ'] = 'Rejected';
$intl['DIFF'] = 'Difficulty';
$intl['NETKHS'] = 'Net Rate';
$intl['UPTIME'] = 'Miner up time';
$intl['TS'] = 'Last update';
$intl['THR'] = 'Throughput';
$intl['WAIT'] = 'Wait time';
$intl['H'] = 'Bloc height';
$intl['I'] = 'Intensity';
$intl['HWF'] = 'Failures';
$intl['POOLS'] = 'Pools';
$intl['TEMP'] = 'T°c';
$intl['FAN'] = 'Fan %';
$intl['FREQ'] = 'Freq.';
$intl['PST'] = 'P-State';
// pool infos
$intl['POOL'] = 'Pool';
$intl['PING'] = 'Ping (ms)';
$intl['DISCO'] = 'Disconnects';
$intl['USER'] = 'User';
if (isset($intl[$key]))
return $intl[$key];
else
return $key;
}
function translateValue($key,$val,$data=array())
{
switch ($key) {
case 'UPTIME':
case 'WAIT':
$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;
case 'KHS':
case 'NETKHS':
$val = '<span class="bold">'.$val.'</span> kH/s';
break;
case 'NAME':
case 'POOL';
case 'USER':
// long fields
$val = '<span class="elipsis">'.$val.'</span>';
break;
}
return $val;
}
function filterPoolInfos($stats)
{
$keys = array('USER','H','PING','DISCO');
$data = array();
$pool = array_pop($stats);
// simplify URL to host only
$data['POOL'] = $pool['URL'];
if (strstr($pool['URL'],'://')) {
$parts = explode(':', $pool['URL']);
$data['POOL'] = substr($parts[1],2);
}
foreach ($pool as $key=>$val) {
if (in_array($key, $keys))
$data[$key] = $val;
}
return $data;
}
function displayData($data)
{
$htm = '';
$totals = array();
foreach ($data as $name => $stats) {
if (!isset($stats['summary']))
continue;
$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']);
if (isset($stats['pool']) && !empty($stats['pool']) ) {
$pool = filterPoolInfos($stats['pool']);
$htm .= '<tr><th class="gpu" colspan="2">POOL</th></tr>'."\n";
foreach ($pool 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";
}
}
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 = getdataFromPeers();
?>
<html>
<head>
<title>ccminer 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; }
span.bold { color: #bb99aa; }
span.elipsis { display: inline-block; max-width: 130px; overflow: hidden; }
</style>
</head>
<body>
<div id="header">
<h1>ccminer monitoring API RIG sample</h1>
</div>
<div id="page">
<?=displayData($data)?>
</div>
<div id="footer">
<p>&copy; 2014-2015 <a href="http://github.com/tpruvot/ccminer">tpruvot@github</a></p>
</div>
</body>
</html>