-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
48 lines (40 loc) · 1.51 KB
/
api.php
File metadata and controls
48 lines (40 loc) · 1.51 KB
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
<?php
/**
* Lightweight JSON API for real-time miner stats polling.
* Returns current hashrate, power, fans, efficiency, and wattage for each miner.
*/
header('Content-Type: application/json');
header('Cache-Control: no-cache');
require_once __DIR__ . '/functions.php';
$config = load_config();
$miners = $config['miners'];
$total_wattage = 0;
$total_hashrate = 0;
$results = [];
foreach ($miners as $miner) {
query_miner($miner, $config);
$total_wattage += $miner['current_miner_consumption'];
$total_hashrate += $miner['hashrate_5m'];
$eff = ($miner['hashrate_5m'] > 0)
? round($miner['current_miner_consumption'] / $miner['hashrate_5m'], 2)
: 0;
$results[] = [
'name' => $miner['name'],
'connection' => $miner['connection'],
'hashrate_5m' => round($miner['hashrate_5m'], 2),
'power' => (int)$miner['current_miner_consumption'],
'wattage' => (int)$miner['current_wattage'],
'fans' => (int)$miner['current_fans'],
'efficiency' => round($eff, 2),
'online' => ($miner['current_wattage'] != 0),
];
}
$fleet_efficiency = ($total_hashrate > 0) ? round($total_wattage / $total_hashrate, 2) : 0;
echo json_encode([
'fleet' => [
'total_wattage' => (int)$total_wattage,
'total_hashrate' => round($total_hashrate, 2),
'efficiency' => round($fleet_efficiency, 2),
],
'miners' => $results,
], JSON_UNESCAPED_SLASHES);