Browse Source

api: update sample php ui with pool

and report pstate in hwinfo only
master
Tanguy Pruvot 10 years ago
parent
commit
1032f191bf
  1. 10
      api.cpp
  2. 51
      api/index.php
  3. 4
      api/local-sample.php

10
api.cpp

@ -124,7 +124,6 @@ static void gpustatus(int thr_id)
struct cgpu_info *cgpu = &thr_info[thr_id].gpu; struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
int gpuid = cgpu->gpu_id; int gpuid = cgpu->gpu_id;
char buf[512]; *buf = '\0'; char buf[512]; *buf = '\0';
char pstate[8];
char* card; char* card;
#ifdef USE_WRAPNVML #ifdef USE_WRAPNVML
@ -132,7 +131,6 @@ static void gpustatus(int thr_id)
cgpu->gpu_bus = gpu_busid(cgpu); cgpu->gpu_bus = gpu_busid(cgpu);
cgpu->gpu_temp = gpu_temp(cgpu); cgpu->gpu_temp = gpu_temp(cgpu);
cgpu->gpu_fan = gpu_fanpercent(cgpu); cgpu->gpu_fan = gpu_fanpercent(cgpu);
cgpu->gpu_pstate = gpu_pstate(cgpu);
#endif #endif
gpu_clocks(cgpu); gpu_clocks(cgpu);
@ -153,16 +151,12 @@ static void gpustatus(int thr_id)
cgpu->khashes = stats_get_speed(cgpu->gpu_id, 0.0) / 1000.0; 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]; card = device_name[gpuid];
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;" 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, 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); cgpu->hw_errors, cgpu->intensity);
// append to buffer for multi gpus // append to buffer for multi gpus

51
api/index.php

@ -42,7 +42,7 @@ function translateField($key)
$intl['ALGO'] = 'Algorithm'; $intl['ALGO'] = 'Algorithm';
$intl['GPUS'] = 'GPUs'; $intl['GPUS'] = 'GPUs';
$intl['CPUS'] = 'Threads'; $intl['CPUS'] = 'Threads';
$intl['KHS'] = 'Hash rate (kH/s)'; $intl['KHS'] = 'Hash rate';
$intl['ACC'] = 'Accepted shares'; $intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn'; $intl['ACCMN'] = 'Accepted / mn';
$intl['REJ'] = 'Rejected'; $intl['REJ'] = 'Rejected';
@ -59,6 +59,12 @@ function translateField($key)
$intl['FREQ'] = 'Freq.'; $intl['FREQ'] = 'Freq.';
$intl['PST'] = 'P-State'; $intl['PST'] = 'P-State';
// pool infos
$intl['POOL'] = 'Pool';
$intl['PING'] = 'Ping (ms)';
$intl['DISCO'] = 'Disconnects';
$intl['USER'] = 'User';
if (isset($intl[$key])) if (isset($intl[$key]))
return $intl[$key]; return $intl[$key];
else else
@ -87,15 +93,44 @@ function translateValue($key,$val,$data=array())
case 'TS': case 'TS':
$val = strftime("%H:%M:%S", (int) $val); $val = strftime("%H:%M:%S", (int) $val);
break; 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; 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) function displayData($data)
{ {
$htm = ''; $htm = '';
$totals = array(); $totals = array();
foreach ($data as $name => $stats) { foreach ($data as $name => $stats) {
if (!isset($stats['summary']))
continue;
$htm .= '<table id="tb_'.$name.'" class="stats">'."\n"; $htm .= '<table id="tb_'.$name.'" class="stats">'."\n";
$htm .= '<tr><th class="machine" colspan="2">'.$name."</th></tr>\n"; $htm .= '<tr><th class="machine" colspan="2">'.$name."</th></tr>\n";
if (!empty($stats)) { if (!empty($stats)) {
@ -107,6 +142,17 @@ function displayData($data)
} }
if (isset($summary['KHS'])) if (isset($summary['KHS']))
@ $totals[$summary['ALGO']] += floatval($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) { foreach ($stats['threads'] as $g=>$gpu) {
$card = isset($gpu['CARD']) ? $gpu['CARD'] : ''; $card = isset($gpu['CARD']) ? $gpu['CARD'] : '';
$htm .= '<tr><th class="gpu" colspan="2">'.$g." $card</th></tr>\n"; $htm .= '<tr><th class="gpu" colspan="2">'.$g." $card</th></tr>\n";
@ -133,7 +179,6 @@ function displayData($data)
$data = getdataFromPeers(); $data = getdataFromPeers();
?> ?>
<html> <html>
<head> <head>
<title>ccminer rig api sample</title> <title>ccminer rig api sample</title>
@ -186,6 +231,8 @@ 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; } 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; } 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> </style>
</head> </head>
<body> <body>

4
api/local-sample.php

@ -127,11 +127,11 @@ error_reporting(0);
$summary = request('summary'); $summary = request('summary');
$threads = request('threads'); $threads = request('threads');
$histo = request('histo'); $pool = request('pool');
ob_end_clean(); /* swap to debug */ ob_end_clean(); /* swap to debug */
//echo ob_get_clean()."\n"; //echo ob_get_clean()."\n";
header("Content-Type: application/json"); header("Content-Type: application/json");
echo json_encode(compact('summary', 'threads', 'histo'))."\n"; echo json_encode(compact('summary', 'threads', 'pool'))."\n";
?> ?>

Loading…
Cancel
Save