-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex_monitor.php
218 lines (185 loc) · 6.45 KB
/
index_monitor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
require_once 'getConfig.php';
require_once 'jsonRPCClient.php';
$totalHashRate = 0;
$json = '';
// 3 seconds max.
set_time_limit(10);
error_reporting(0);
defined('API_HOST') || define('API_HOST', 'localhost');
defined('API_PORT') || define('API_PORT', 4048);
function getsock($host,$port,$cmd) {
$timeout = 3;
$socket = @stream_socket_client(
"tcp://$host:$port",
$errNo,
$errorMessage,
$timeout,
STREAM_CLIENT_CONNECT,
stream_context_create(array())
);
if ($socket === false) {
//throw new UnexpectedValueException("Failed to connect: $errorMessage");
$data = "error=Failed to connect: $errorMessage|";
}
else {
fwrite($socket, $cmd);
stream_set_timeout($socket, 1);
$data = stream_get_contents($socket);
$info = stream_get_meta_data($socket);
fclose($socket);
if ($info['timed_out']) {
$data = 'error=Connection timed out|';
}
}
$data = strToArray($data);
return $data;
}
function strToArray($sockData) {
$objs = explode('|', $sockData);
array_pop($objs);
$data = array();
$items = explode(';', $objs[0]);
foreach ($items as $item)
{
$id = explode('=', $item);
$data[$id[0]] = $id[1];
if($id[0] == 'KHS') $data['HM'] = $id[1]*60*1000; //cpuminer returns KHS so we add Hash/min for low hash devices. Need Fireworms latest to take advantage
}
return $data;
}
function getDataFromHost($host,$port)
{
$summary=getsock($host,$port,'summary');
if ($summary==false) return false;
return json_encode(array('summary'=>$summary));
}
function getdataFromPeers()
{
global $configs, $hostsFile;
$configs= file($hostsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = array();
foreach ($configs as $host) {
$conf = explode(':',$host);
$data[$host] = json_decode(getDataFromHost($conf[0],(isset($conf[1])) ? $conf[1] : API_PORT), TRUE);
}
return $data;
}
function ignoreField($key,$solo)
{
if($solo == TRUE){
$ignored = array('NAME','VER','ALGO','GPUS','SOLV','ACCMN','CPU','TS','API','GPU','CARD','FAN','REJ','DIFF','UPTIME');
}
else{
$ignored = array('NAME','VER','ALGO','GPUS','ACC','ACCMN','CPU','TS','API','GPU','CARD','FAN','REJ','DIFF','UPTIME');
}
return in_array($key, $ignored);
}
function translateField($key)
{
$intl = array();
$intl['NAME'] = 'Software';
$intl['VER'] = 'Version';
$intl['KHS'] = 'KH/S';
$intl['HM'] = 'H/M';
$intl['ALGO'] = 'Algorithm';
$intl['GPUS'] = 'GPUs';
$intl['CPUS'] = 'Threads';
$intl['H/m'] = 'Hash rate (H/m)';
$intl['SOLV'] = 'Shares Accepted';
$intl['ACC'] = 'Blocks found';
$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'] = 'CPU 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}m ${sec}s";
if ($min > 60) {
$hrs = floor($min / 60);
$min = $min % 60;
$val = "${hrs}h ${min}m";
}
break;
case 'NAME':
$val = $data['NAME'].'� '.$data['VER'];
break;
case 'FREQ':
$val = sprintf("%.1fGHz", floatval($val)/1000000);
break;
case 'TS':
$val = strftime("%H:%M:%S", (int) $val);
break;
}
return $val;
}
function displayData($data,$config_array)
{
global $totalHashRate, $totalBlocksFound;
$htm = '';
$totalHashRate = 0;
$totalBlocksFound = 0;
foreach ($data as $name => $stats) {
$htm .= '<table id="tb_'.$name.'" class="stats">'."\n";
$htm .= '<tr><th class="machine" colspan="2">'.$name."</th></tr>\n";
$summary = (array) $stats['summary'];
foreach ($summary as $key=>$val) {
if (!ignoreField($key,$config_array['solo'])) {
if ($key == 'error') {
$htm .= '<tr><td class="val" colspan="2">' . translateValue($key, $val, $summary) . "</td></tr>\n";
} else {
$htm .= '<tr><td class="key">' . translateField($key) . '</td>' .
'<td class="val">' . translateValue($key, $val, $summary) . "</td></tr>\n";
if ($key == 'KHS') {
$totalHashRate += $val;
} elseif ($key == 'ACC') {
$totalBlocksFound += $val;
}
}
}
}
$htm .= "</table>\n";
}
// totals for solo then pool
if ($config_array['solo'] == TRUE) {
$url = 'http://'.$config_array['walletuser'].':'.$config_array['walletpassword'].'@'.$config_array['walletaddress'].':33987';
$verium = new jsonRPCClient($url);
$balance = $verium->getbalance();
$mininginfo = $verium->getmininginfo();
#$blocktime=(-13.03*log($mininginfo['difficulty'])+180)/60;
$blocks_hr=60.0/$mininginfo['blocktime (min)'];
$network_vrm=$blocks_hr*$mininginfo['blockreward (VRM)'];
$vrm_day=$network_vrm*($totalHashRate*60)/$mininginfo['nethashrate (kH/m)']*24;
$totals = '<table class="totals"><tr><td class="totals">Total kH/M: '.number_format($totalHashRate*60,3).'</td>
<td class="totals">KH/S: '.number_format($totalHashRate,4).'</td>
<td class="totals">Network kH/M: '.number_format($mininginfo['nethashrate (kH/m)'],0).'</td>
<td class="totals">Blocks/hr: '.number_format($blocks_hr,2).'</td>
<td class="totals">Difficulty : '.number_format($mininginfo['difficulty'],4).'</td> </tr>
<tr><td class="totals">VRM Balance: '.number_format($balance,2).'</td>
<td class="totals">Block: '.$mininginfo['blocks'].'</td>
<td class="totals">Block Rewared: '.number_format($mininginfo['blockreward (VRM)'],2).'</td>
<td class="totals">VRM/day: '.number_format($vrm_day,2).'</td>
<td class="totals">Blocks Found: '.$totalBlocksFound.'</td></tr>
</table>'."\n";
} else {
$totals = '<div class="totals"><h2>Totals:'.$ini['solo'].'<br />KH/S: '.$totalHashRate.'<br />KH/M: '.($totalHashRate*60).'</h2></div>'."\n";
}
return $totals.$htm;
}
$data = getdataFromPeers();
?>
<?=displayData($data,$ini_array['CONFIG'])?>