hotfix/1.0.1 #1

Merged
thepetric merged 2 commits from hotfix/1.0.1 into main 2025-11-09 15:06:03 +00:00
2 changed files with 55 additions and 4 deletions
Showing only changes of commit c5b9e6c4b2 - Show all commits

51
web/api/stats_rates.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
require __DIR__ . '/../lib/app.php';
auth_require();
header('Content-Type: application/json');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
$path = '/var/lib/torpanel/stats.json';
if (!is_readable($path)) { echo json_encode(['ok'=>true,'data'=>[]]); exit; }
$raw = file_get_contents($path);
$state = json_decode($raw, true);
if (!is_array($state) || !is_array($state['data'] ?? null)) {
echo json_encode(['ok'=>true,'data'=>[]]); exit;
}
usort($state['data'], function($a,$b){
return (int)($a['t'] ?? 0) <=> (int)($b['t'] ?? 0);
});
$out = [];
$prev = null;
foreach ($state['data'] as $s) {
$t = (int)($s['t'] ?? 0);
if ($t <= 0) continue;
$rx_total = (int)($s['read'] ?? ($s['bytes_read'] ?? ($s['rx'] ?? 0)));
$tx_total = (int)($s['written'] ?? ($s['bytes_written'] ?? ($s['tx'] ?? 0)));
$rx_mbps = 0.0; $tx_mbps = 0.0;
if ($prev) {
$dt = max(1, $t - $prev['t']);
$drx = max(0, $rx_total - $prev['rx_total']);
$dtx = max(0, $tx_total - $prev['tx_total']);
$rx_mbps = ($drx * 8) / $dt / 1_000_000.0;
$tx_mbps = ($dtx * 8) / $dt / 1_000_000.0;
}
$out[] = [
'ts' => $t * 1000,
'rx_mbps' => round($rx_mbps, 3),
'tx_mbps' => round($tx_mbps, 3),
'rx_total' => $rx_total,
'tx_total' => $tx_total,
];
$prev = ['t'=>$t, 'rx_total'=>$rx_total, 'tx_total'=>$tx_total];
}
if (count($out) > 1440) $out = array_slice($out, -1440);
echo json_encode(['ok'=>true,'data'=>$out]);

View File

@@ -87,14 +87,14 @@ auth_require();
<div class="col-md-4">
<div class="card p-3">
<div class="small">Read (total)</div>
<div class="small">RX (total)</div>
<div class="h4 mono" id="readTotal">—</div>
</div>
</div>
<div class="col-md-4">
<div class="card p-3">
<div class="small">Written (total)</div>
<div class="small">TX (total)</div>
<div class="h4 mono" id="writeTotal">—</div>
</div>
</div>
@@ -326,8 +326,8 @@ function setChartData(labels, rx, tx){
chart = new Chart(ctx, {
type: 'line',
data: { labels, datasets: [
{label:'Read/min', data: rx, tension:.3},
{label:'Written/min', data: tx, tension:.3}
{label:'RX/min', data: rx, tension:.3},
{label:'TX/min', data: tx, tension:.3}
]},
options: {
responsive:true,