-
Notifications
You must be signed in to change notification settings - Fork 10
/
functions.inc.php
224 lines (182 loc) · 5.53 KB
/
functions.inc.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
219
220
221
222
223
224
<?php
/*########################################################
SIMPLE CGMINER REMOTE MONITORING SCRIPT WITH ALERTS
Created by: p4xil
Version: 2.1.1
If you like it please support it with donating:
LTC : LdQ1UHiRy24Tvmm8NHbhAdHL3Qf3JqrUbG
BTC : 1EA8UrpifP9hi7LZHjJphCJQ6Hh45mb5pP
########################################################*/
/*--------------
# SETUP MINERS #
--------------*/
// Change YOUR_RIG_REMOTE_IP to your rig REMOTE IP (NOT local IP!)
// To get your remote IP go to http://www.whatismyip.com/
// Uncomment (remove //) if you want to add more miners.
$r[0]['name'] = 'MINER1';
$r[0]['ip'] = 'YOUR_RIG_REMOTE_IP';
$r[0]['port'] = '4001';
$r[0]['alert'] = TRUE; //set FALSE if you don't want to send alerts for this rig
//$r[1]['name'] = 'MINER2';
//$r[1]['ip'] = 'YOUR_RIG_REMOTE_IP';
//$r[1]['port'] = '4002';
//$r[1]['alert'] = TRUE; //set FALSE if you don't want to send alerts for this rig
//$r[2]['name'] = 'MINER3';
//$r[2]['ip'] = 'YOUR_RIG_REMOTE_IP';
//$r[2]['port'] = '4003';
//$r[2]['alert'] = TRUE; //set FALSE if you don't want to send alerts for this rig
//$r[3]['name'] = 'MINER3';
//$r[3]['ip'] = 'YOUR_RIG_REMOTE_IP';
//$r[3]['port'] = '4004';
//$r[3]['alert'] = TRUE; //set FALSE if you don't want to send alerts for this rig
/*--------------
# SETUP SCRIPT #
--------------*/
// URL to the script
// Change WEBSERVER_IP to your Webserver IP or Webserver Domain if you have it.
define('SCRIPT_URL', 'http://WEBSERVER_IP/monitoring/');
// Time in Seconds to Auto Refresh the script
define('SCRIPT_REFRESH', 20);
// Show Pool and User name
define('SHOW_POOLS', TRUE);
/*--------------
# SETUP ALERTS #
--------------*/
// E-Mail for Alerts
define('ALERT_EMAIL', '[email protected]');
// Maximum allowed GPU Temperature before Alert is sent
define('ALERT_TEMP', 75);
// Maximum allowed difference in percentage (%) between 5s MH/s and (avg) MH/s before Alert is sent.
// Formula : DIFFERENCE = 100 - ((5s / avg) * 100)
//
// e.g. If (avg) is 500 and 5s drops to 400 the difference will be:
// DIFFERENCE = 100 - ((400 / 500) * 100) = 20%
// If ALERT_MHS is set to 20, Alert will be sent.
define('ALERT_MHS', 20);
// Maximum allowed stales percentage (%). If crossed it won't send Email, just color it red on dashboard.
define('ALERT_STALES', 5);
/*#####################################################################################*/
/*# DO NOT EDIT BELOW THIS LINE #######################################################*/
/*#####################################################################################*/
/* Connection Timeout in Seconds */
define('SOCK_TIMEOUT', '3');
ini_set('default_socket_timeout', SOCK_TIMEOUT);
/* Script Allowed Execution Time */
set_time_limit(0);
function getsock($addr, $port)
{
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false || $socket === null)
{
$error = socket_strerror(socket_last_error());
$msg = "socket create(TCP) failed";
//echo "ERR: $msg '$error'\n";
return null;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => SOCK_TIMEOUT, 'usec' => 0));
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => SOCK_TIMEOUT, 'usec' => 0));
$res = socket_connect($socket, $addr, $port);
if ($res === false)
{
$error = socket_strerror(socket_last_error());
$msg = "socket connect($addr,$port) failed";
//echo "ERR: $msg '$error'\n";
socket_close($socket);
return null;
}
return $socket;
}
function readsockline($socket)
{
$line = '';
while (true)
{
$byte = socket_read($socket, 1);
if ($byte === false || $byte === '')
break;
if ($byte === "\0")
break;
$line .= $byte;
}
return $line;
}
function request($cmd, $ip, $port)
{
$socket = getsock($ip, $port);
if ($socket != null)
{
socket_write($socket, $cmd, strlen($cmd));
$line = readsockline($socket);
socket_close($socket);
if (strlen($line) == 0)
{
//echo "WARN: '$cmd' returned nothing\n";
return $line;
}
if (substr($line,0,1) == '{')
return json_decode($line, true);
$data = array();
$objs = explode('|', $line);
foreach ($objs as $obj)
{
if (strlen($obj) > 0)
{
$items = explode(',', $obj);
$item = $items[0];
$id = explode('=', $items[0], 2);
if (count($id) == 1 or !ctype_digit($id[1]))
$name = $id[0];
else
$name = $id[0].$id[1];
if (strlen($name) == 0)
$name = 'null';
if (isset($data[$name]))
{
$num = 1;
while (isset($data[$name.$num]))
$num++;
$name .= $num;
}
$counter = 0;
foreach ($items as $item)
{
$id = explode('=', $item, 2);
if (count($id) == 2)
$data[$name][$id[0]] = $id[1];
else
$data[$name][$counter] = $id[0];
$counter++;
}
}
}
return $data;
}
return null;
}
function seconds_to_time($input_seconds)
{
$seconds_in_minute = 60;
$seconds_in_hour = 60 * $seconds_in_minute;
$seconds_in_day = 24 * $seconds_in_hour;
// extract days
$days = floor($input_seconds / $seconds_in_day);
// extract hours
$hour_seconds = $input_seconds % $seconds_in_day;
$hours = floor($hour_seconds / $seconds_in_hour);
// extract minutes
$minute_seconds = $hour_seconds % $seconds_in_hour;
$minutes = floor($minute_seconds / $seconds_in_minute);
// extract the remaining seconds
$remaining_seconds = $minute_seconds % $seconds_in_minute;
$seconds = ceil($remaining_seconds);
// return the final array
$obj = array(
'd' => (int)$days,
'h' => sprintf('%02d', (int)$hours),
'm' => sprintf('%02d', (int)$minutes),
's' => sprintf('%02d', (int)$seconds)
);
return $obj;
}
?>