Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/api/index.php
1201 views
1
<?php
2
/* cpuminer API sample UI */
3
4
$host = 'http://localhost/api/'; // 'http://'.$_SERVER['SERVER_NAME'].'/api/';
5
$configs = array(
6
'LOCAL'=>'local-sample.php',
7
//'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */
8
);
9
10
// 3 seconds max.
11
set_time_limit(3);
12
error_reporting(0);
13
14
function getdataFromPears()
15
{
16
global $host, $configs;
17
$data = array();
18
foreach ($configs as $name => $conf) {
19
20
$json = file_get_contents($host.$conf);
21
22
$data[$name] = json_decode($json, TRUE);
23
}
24
return $data;
25
}
26
27
function ignoreField($key)
28
{
29
$ignored = array('API','VER','GPU','CARD','GPUS','CPU');
30
return in_array($key, $ignored);
31
}
32
33
function translateField($key)
34
{
35
$intl = array();
36
$intl['NAME'] = 'Software';
37
$intl['VER'] = 'Version';
38
39
$intl['ALGO'] = 'Algorithm';
40
$intl['GPUS'] = 'GPUs';
41
$intl['CPUS'] = 'Threads';
42
$intl['KHS'] = 'Hash rate (kH/s)';
43
$intl['ACC'] = 'Accepted shares';
44
$intl['ACCMN'] = 'Accepted / mn';
45
$intl['REJ'] = 'Rejected';
46
$intl['DIFF'] = 'Difficulty';
47
$intl['UPTIME'] = 'Miner up time';
48
$intl['TS'] = 'Last update';
49
50
$intl['TEMP'] = 'T°c';
51
$intl['FAN'] = 'Fan %';
52
$intl['FREQ'] = 'Freq.';
53
$intl['PST'] = 'P-State';
54
55
if (isset($intl[$key]))
56
return $intl[$key];
57
else
58
return $key;
59
}
60
61
function translateValue($key,$val,$data=array())
62
{
63
switch ($key) {
64
case 'UPTIME':
65
$min = floor(intval($val) / 60);
66
$sec = intval($val) % 60;
67
$val = "${min}mn${sec}s";
68
if ($min > 180) {
69
$hrs = floor($min / 60);
70
$min = $min % 60;
71
$val = "${hrs}h${min}mn";
72
}
73
break;
74
case 'NAME':
75
$val = $data['NAME'].'&nbsp;'.$data['VER'];
76
break;
77
case 'FREQ':
78
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
79
break;
80
case 'TS':
81
$val = strftime("%H:%M:%S", (int) $val);
82
break;
83
}
84
return $val;
85
}
86
87
function displayData($data)
88
{
89
$htm = '';
90
$totals = array();
91
foreach ($data as $name => $stats) {
92
$htm .= '<table id="tb_'.$name.'" class="stats">'."\n";
93
$htm .= '<tr><th class="machine" colspan="2">'.$name."</th></tr>\n";
94
if (!empty($stats)) {
95
$summary = (array) $stats['summary'];
96
foreach ($summary as $key=>$val) {
97
if (!empty($val) && !ignoreField($key))
98
$htm .= '<tr><td class="key">'.translateField($key).'</td>'.
99
'<td class="val">'.translateValue($key, $val, $summary)."</td></tr>\n";
100
}
101
if (isset($summary['KHS']))
102
@ $totals[$summary['ALGO']] += floatval($summary['KHS']);
103
foreach ($stats['threads'] as $g=>$gpu) {
104
$card = isset($gpu['CARD']) ? $gpu['CARD'] : '';
105
$htm .= '<tr><th class="gpu" colspan="2">'.$g." $card</th></tr>\n";
106
foreach ($gpu as $key=>$val) {
107
if (!empty($val) && !ignoreField($key))
108
$htm .= '<tr><td class="key">'.translateField($key).'</td>'.
109
'<td class="val">'.translateValue($key, $val)."</td></tr>\n";
110
}
111
}
112
}
113
$htm .= "</table>\n";
114
}
115
// totals
116
if (!empty($totals)) {
117
$htm .= '<div class="totals"><h2>Total Hash rate</h2>'."\n";
118
foreach ($totals as $algo => $hashrate) {
119
$htm .= '<li><span class="algo">'.$algo.":</span>$hashrate kH/s</li>\n";
120
}
121
$htm .= '</div>';
122
}
123
return $htm;
124
}
125
126
$data = getdataFromPears();
127
128
?>
129
<html>
130
<head>
131
<title>cpuminer rig api sample</title>
132
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
133
<meta http-equiv="refresh" content="10">
134
<style type="text/css">
135
body {
136
color:#cccccc; background:#1d1d1d; margin:30px 30px 0px 30px; padding:0px;
137
font-size:.8em; font-family:Arial,Helvetica,sans-serif;
138
}
139
a { color:#aaaaaa; text-decoration: none; }
140
a:focus { outline-style:none; }
141
.clear { clear: both; }
142
143
div#page, div#header, div#footer {
144
margin: auto;
145
width: 950px;
146
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
147
}
148
div#page {
149
padding-top: 8px;
150
background: #252525;
151
min-height: 820px;
152
}
153
div#header {
154
background: rgba(65, 65, 65, 0.85);
155
height: 50px;
156
margin-bottom: 24px;
157
padding-left: 8px;
158
}
159
div#footer {
160
background: rgba(25, 25, 25, 0.85);
161
height: 0px;
162
margin-bottom: 40px;
163
text-align: center;
164
color: #666666;
165
text-shadow: rgba(0, 0, 0, 0.8) 0px 1px 0px;
166
}
167
#header h1 { padding: 12px; font-size: 20px; }
168
#footer p { margin: 12px 24px; }
169
170
table.stats { width: 280px; margin: 4px 16px; display: inline-block; }
171
th.machine { color: darkcyan; padding: 16px 0px 0px 0px; text-align: left; border-bottom: 1px solid gray; }
172
th.gpu { color: white; padding: 3px 3px; font: bolder; text-align: left; background: rgba(65, 65, 65, 0.85); }
173
td.key { width: 99px; max-width: 180px; }
174
td.val { width: 40px; max-width: 100px; color: white; }
175
176
div.totals { margin: 16px; padding-bottom: 16px; }
177
div.totals h2 { color: darkcyan; font-size: 16px; margin-bottom: 4px; }
178
div.totals li { list-style-type: none; font-size: 16px; margin-left: 4px; margin-bottom: 8px; }
179
li span.algo { display: inline-block; width: 100px; max-width: 180px; }
180
181
</style>
182
</head>
183
<body>
184
<div id="header">
185
<h1>cpuminer monitoring API RIG sample</h1>
186
</div>
187
188
<div id="page">
189
<?=displayData($data)?>
190
</div>
191
192
<div id="footer">
193
<p>&copy; 2014 <a href="http://github.com/tpruvot/cpuminer-multi">tpruvot@github</a></p>
194
</div>
195
196
</body>
197
</html>
198
199