Skip to content

Commit

Permalink
api: update sample php ui with pool
Browse files Browse the repository at this point in the history
and report pstate in hwinfo only
  • Loading branch information
tpruvot committed Nov 26, 2014
1 parent 6ae2816 commit 1032f19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
10 changes: 2 additions & 8 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ static void gpustatus(int thr_id)
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
int gpuid = cgpu->gpu_id;
char buf[512]; *buf = '\0';
char pstate[8];
char* card;

#ifdef USE_WRAPNVML
cgpu->has_monitoring = true;
cgpu->gpu_bus = gpu_busid(cgpu);
cgpu->gpu_temp = gpu_temp(cgpu);
cgpu->gpu_fan = gpu_fanpercent(cgpu);
cgpu->gpu_pstate = gpu_pstate(cgpu);
#endif
gpu_clocks(cgpu);

Expand All @@ -153,16 +151,12 @@ static void gpustatus(int thr_id)

cgpu->khashes = stats_get_speed(cgpu->gpu_id, 0.0) / 1000.0;

memset(pstate, 0, sizeof(pstate));
if (cgpu->gpu_pstate != -1)
snprintf(pstate, sizeof(pstate), "P%hu", cgpu->gpu_pstate);

card = device_name[gpuid];

snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;"
"TEMP=%.1f;FAN=%d;FREQ=%d;PST=%s;KHS=%.2f;HWF=%d;I=%d|",
"TEMP=%.1f;FAN=%d;FREQ=%d;KHS=%.2f;HWF=%d;I=%d|",
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp, cgpu->gpu_fan,
cgpu->gpu_clock, pstate, cgpu->khashes,
cgpu->gpu_clock, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity);

// append to buffer for multi gpus
Expand Down
51 changes: 49 additions & 2 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function translateField($key)
$intl['ALGO'] = 'Algorithm';
$intl['GPUS'] = 'GPUs';
$intl['CPUS'] = 'Threads';
$intl['KHS'] = 'Hash rate (kH/s)';
$intl['KHS'] = 'Hash rate';
$intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn';
$intl['REJ'] = 'Rejected';
Expand All @@ -59,6 +59,12 @@ function translateField($key)
$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
Expand Down Expand Up @@ -87,15 +93,44 @@ function translateValue($key,$val,$data=array())
case 'TS':
$val = strftime("%H:%M:%S", (int) $val);
break;
case 'KHS':
$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)) {
Expand All @@ -107,6 +142,17 @@ function displayData($data)
}
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";
Expand All @@ -133,7 +179,6 @@ function displayData($data)
$data = getdataFromPeers();

?>

<html>
<head>
<title>ccminer rig api sample</title>
Expand Down Expand Up @@ -186,6 +231,8 @@ function displayData($data)
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>
Expand Down
4 changes: 2 additions & 2 deletions api/local-sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ function request($cmd)

$summary = request('summary');
$threads = request('threads');
$histo = request('histo');
$pool = request('pool');

ob_end_clean(); /* swap to debug */
//echo ob_get_clean()."\n";

header("Content-Type: application/json");
echo json_encode(compact('summary', 'threads', 'histo'))."\n";
echo json_encode(compact('summary', 'threads', 'pool'))."\n";
?>

0 comments on commit 1032f19

Please sign in to comment.