Add throttling recovery metrics
This commit is contained in:
@@ -120,6 +120,8 @@ function dmesg_log(): array
|
||||
function throttled_event_status(?int $flags, string $raw, int $activeBit, int $seenBit, string $statePath): array
|
||||
{
|
||||
$now = time();
|
||||
$windowSeconds = 600;
|
||||
$recoverySeconds = 300;
|
||||
$active = $flags !== null && (bool)($flags & $activeBit);
|
||||
$seen = $flags !== null && (bool)($flags & $seenBit);
|
||||
|
||||
@@ -134,6 +136,7 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
'last_cleared_at' => null,
|
||||
'last_duration_seconds' => 0,
|
||||
'updated_at' => null,
|
||||
'events' => [],
|
||||
];
|
||||
|
||||
$fp = @fopen($statePath, 'c+');
|
||||
@@ -145,6 +148,10 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
if (is_array($decoded)) {
|
||||
$state = array_merge($state, array_intersect_key($decoded, $state));
|
||||
}
|
||||
$state['events'] = array_values(array_filter(
|
||||
is_array($state['events'] ?? null) ? $state['events'] : [],
|
||||
static fn($event): bool => is_array($event) && is_numeric($event['start'] ?? null)
|
||||
));
|
||||
|
||||
$wasActive = !empty($state['active']);
|
||||
$activeSince = is_numeric($state['active_since'] ?? null) ? (int)$state['active_since'] : null;
|
||||
@@ -154,6 +161,11 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
if (!$wasActive || $activeSince === null) {
|
||||
$activeSince = $now;
|
||||
$state['last_detected_at'] = $now;
|
||||
$state['events'][] = [
|
||||
'start' => $now,
|
||||
'end' => null,
|
||||
'duration_seconds' => 0,
|
||||
];
|
||||
}
|
||||
$state['active'] = true;
|
||||
$state['active_since'] = $activeSince;
|
||||
@@ -161,11 +173,32 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
if ($wasActive && $activeSince !== null) {
|
||||
$state['last_cleared_at'] = $now;
|
||||
$state['last_duration_seconds'] = max(0, $now - $activeSince);
|
||||
$lastIndex = count($state['events']) - 1;
|
||||
if ($lastIndex >= 0 && empty($state['events'][$lastIndex]['end'])) {
|
||||
$state['events'][$lastIndex]['end'] = $now;
|
||||
$state['events'][$lastIndex]['duration_seconds'] = $state['last_duration_seconds'];
|
||||
} else {
|
||||
$state['events'][] = [
|
||||
'start' => $activeSince,
|
||||
'end' => $now,
|
||||
'duration_seconds' => $state['last_duration_seconds'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$state['active'] = false;
|
||||
$state['active_since'] = null;
|
||||
}
|
||||
|
||||
$keepAfter = $now - 86400;
|
||||
$state['events'] = array_slice(array_values(array_filter(
|
||||
$state['events'],
|
||||
static function ($event) use ($keepAfter, $now): bool {
|
||||
$start = (int)($event['start'] ?? 0);
|
||||
$end = is_numeric($event['end'] ?? null) ? (int)$event['end'] : $now;
|
||||
return $start > 0 && max($start, $end) >= $keepAfter;
|
||||
}
|
||||
)), -200);
|
||||
|
||||
$state['updated_at'] = $now;
|
||||
ftruncate($fp, 0);
|
||||
rewind($fp);
|
||||
@@ -189,6 +222,39 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
? date('Y-m-d H:i:s', (int)$ts)
|
||||
: null;
|
||||
|
||||
$windowStart = $now - $windowSeconds;
|
||||
$recentCount = 0;
|
||||
$recentActiveSeconds = 0;
|
||||
$events = is_array($state['events'] ?? null) ? $state['events'] : [];
|
||||
foreach ($events as $event) {
|
||||
if (!is_array($event) || !is_numeric($event['start'] ?? null)) {
|
||||
continue;
|
||||
}
|
||||
$start = (int)$event['start'];
|
||||
$end = is_numeric($event['end'] ?? null) ? (int)$event['end'] : $now;
|
||||
if ($end < $windowStart || $start > $now) {
|
||||
continue;
|
||||
}
|
||||
$overlapStart = max($start, $windowStart);
|
||||
$overlapEnd = min(max($end, $overlapStart), $now);
|
||||
if ($overlapEnd > $overlapStart) {
|
||||
$recentCount++;
|
||||
$recentActiveSeconds += $overlapEnd - $overlapStart;
|
||||
}
|
||||
}
|
||||
|
||||
$lastClearedAt = is_numeric($state['last_cleared_at'] ?? null) ? (int)$state['last_cleared_at'] : null;
|
||||
$recovering = !$active && $lastClearedAt !== null && ($now - $lastClearedAt) <= $recoverySeconds;
|
||||
$repeated = $recentCount >= 2;
|
||||
$stateLabel = 'normal';
|
||||
if ($active) {
|
||||
$stateLabel = 'active';
|
||||
} elseif ($repeated) {
|
||||
$stateLabel = 'repeated';
|
||||
} elseif ($recovering) {
|
||||
$stateLabel = 'recovering';
|
||||
}
|
||||
|
||||
return [
|
||||
'available' => $flags !== null,
|
||||
'raw' => $raw,
|
||||
@@ -201,6 +267,14 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
|
||||
'duration_seconds' => $duration,
|
||||
'last_duration_seconds' => (int)($state['last_duration_seconds'] ?? 0),
|
||||
'updated_at' => $dateValue($state['updated_at'] ?? null),
|
||||
'state_label' => $stateLabel,
|
||||
'recovering' => $recovering,
|
||||
'repeated_recently' => $repeated,
|
||||
'recovery_window_seconds' => $recoverySeconds,
|
||||
'recent_window_seconds' => $windowSeconds,
|
||||
'recent_event_count' => $recentCount,
|
||||
'recent_active_seconds' => $recentActiveSeconds,
|
||||
'recent_active_percent' => round($recentActiveSeconds / $windowSeconds * 100, 1),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+44
-4
@@ -24,9 +24,11 @@
|
||||
statusLowVoltage: $('#statusLowVoltage'),
|
||||
statusLowVoltageLast: $('#statusLowVoltageLast'),
|
||||
statusLowVoltageDuration: $('#statusLowVoltageDuration'),
|
||||
statusLowVoltageRecent: $('#statusLowVoltageRecent'),
|
||||
statusThrottling: $('#statusThrottling'),
|
||||
statusThrottlingLast: $('#statusThrottlingLast'),
|
||||
statusThrottlingDuration: $('#statusThrottlingDuration'),
|
||||
statusThrottlingRecent: $('#statusThrottlingRecent'),
|
||||
statusBatteryVoltage: $('#statusBatteryVoltage'),
|
||||
statusBatterySoc: $('#statusBatterySoc'),
|
||||
statusBatteryRemaining: $('#statusBatteryRemaining'),
|
||||
@@ -98,19 +100,27 @@
|
||||
lowVoltage: 'Low Voltage',
|
||||
lowVoltageLast: 'Last Low Voltage',
|
||||
lowVoltageDuration: 'LV Duration',
|
||||
lowVoltageRecent: 'LV 10m',
|
||||
lowVoltageActive: 'Active',
|
||||
lowVoltageNormal: 'Normal',
|
||||
lowVoltageRecovering: 'Recovering',
|
||||
lowVoltageRepeated: 'Repeated',
|
||||
lowVoltageSeen: 'seen since boot',
|
||||
lowVoltageNotSeen: 'not seen since boot',
|
||||
throttling: 'Throttling',
|
||||
throttlingLast: 'Last Throttling',
|
||||
throttlingDuration: 'Throttle Duration',
|
||||
throttlingRecent: 'Throttle 10m',
|
||||
throttlingActive: 'Throttling',
|
||||
throttlingNormal: 'Normal',
|
||||
throttlingRecovering: 'Recovering',
|
||||
throttlingRepeated: 'Repeated',
|
||||
throttlingSeen: 'seen since boot',
|
||||
throttlingNotSeen: 'not seen since boot',
|
||||
currentEpisode: 'current',
|
||||
lastEpisode: 'last',
|
||||
recentCount: 'events',
|
||||
recentActive: 'active',
|
||||
batteryV: 'Battery V',
|
||||
batterySoc: 'Battery SOC',
|
||||
sensorHistory: 'Sensor History',
|
||||
@@ -247,19 +257,27 @@
|
||||
lowVoltage: '저전압',
|
||||
lowVoltageLast: '최근 저전압',
|
||||
lowVoltageDuration: '저전압 지속',
|
||||
lowVoltageRecent: '저전압 10분',
|
||||
lowVoltageActive: '감지 중',
|
||||
lowVoltageNormal: '정상',
|
||||
lowVoltageRecovering: '복구 중',
|
||||
lowVoltageRepeated: '반복 발생',
|
||||
lowVoltageSeen: '부팅 후 이력 있음',
|
||||
lowVoltageNotSeen: '부팅 후 이력 없음',
|
||||
throttling: '스로틀링',
|
||||
throttlingLast: '최근 스로틀링',
|
||||
throttlingDuration: '스로틀링 지속',
|
||||
throttlingRecent: '스로틀링 10분',
|
||||
throttlingActive: '감지 중',
|
||||
throttlingNormal: '정상',
|
||||
throttlingRecovering: '복구 중',
|
||||
throttlingRepeated: '반복 발생',
|
||||
throttlingSeen: '부팅 후 이력 있음',
|
||||
throttlingNotSeen: '부팅 후 이력 없음',
|
||||
currentEpisode: '현재',
|
||||
lastEpisode: '최근',
|
||||
recentCount: '발생',
|
||||
recentActive: '감지',
|
||||
batteryV: '배터리 전압',
|
||||
batterySoc: '배터리 SOC',
|
||||
sensorHistory: '센서 이력',
|
||||
@@ -804,16 +822,36 @@
|
||||
return formatDhms(parseWifiDurationSeconds(value)) || value;
|
||||
}
|
||||
|
||||
function eventStateText(eventState, activeKey, normalKey, seenKey, notSeenKey) {
|
||||
function eventStateText(eventState, activeKey, normalKey, recoveringKey, repeatedKey, seenKey, notSeenKey) {
|
||||
if (!eventState || eventState.available === false) {
|
||||
return t('na');
|
||||
}
|
||||
|
||||
const stateText = eventState.active ? t(activeKey) : t(normalKey);
|
||||
let stateText = t(normalKey);
|
||||
if (eventState.state_label === 'repeated') {
|
||||
stateText = t(repeatedKey);
|
||||
} else if (eventState.state_label === 'recovering') {
|
||||
stateText = t(recoveringKey);
|
||||
} else if (eventState.active) {
|
||||
stateText = t(activeKey);
|
||||
}
|
||||
const seenText = eventState.seen_since_boot ? t(seenKey) : t(notSeenKey);
|
||||
return `${stateText} (${seenText})`;
|
||||
}
|
||||
|
||||
function eventRecentText(eventState) {
|
||||
if (!eventState || eventState.available === false) {
|
||||
return t('na');
|
||||
}
|
||||
|
||||
const count = Number(eventState.recent_event_count ?? 0);
|
||||
const seconds = Number(eventState.recent_active_seconds ?? 0);
|
||||
const percent = Number(eventState.recent_active_percent ?? 0);
|
||||
const activeText = formatDhms(seconds) || '0s';
|
||||
|
||||
return `${count}${state.lang === 'ko' ? '회' : 'x'} / ${t('recentActive')} ${activeText} (${percent.toFixed(1)}%)`;
|
||||
}
|
||||
|
||||
function eventDurationText(eventState) {
|
||||
if (!eventState || eventState.available === false) {
|
||||
return t('na');
|
||||
@@ -826,11 +864,11 @@
|
||||
}
|
||||
|
||||
function lowVoltageStateText(lowVoltage) {
|
||||
return eventStateText(lowVoltage, 'lowVoltageActive', 'lowVoltageNormal', 'lowVoltageSeen', 'lowVoltageNotSeen');
|
||||
return eventStateText(lowVoltage, 'lowVoltageActive', 'lowVoltageNormal', 'lowVoltageRecovering', 'lowVoltageRepeated', 'lowVoltageSeen', 'lowVoltageNotSeen');
|
||||
}
|
||||
|
||||
function throttlingStateText(throttling) {
|
||||
return eventStateText(throttling, 'throttlingActive', 'throttlingNormal', 'throttlingSeen', 'throttlingNotSeen');
|
||||
return eventStateText(throttling, 'throttlingActive', 'throttlingNormal', 'throttlingRecovering', 'throttlingRepeated', 'throttlingSeen', 'throttlingNotSeen');
|
||||
}
|
||||
|
||||
function timeAgo(seconds) {
|
||||
@@ -877,9 +915,11 @@
|
||||
setText(els.statusLowVoltage, lowVoltageStateText(lowVoltage));
|
||||
setText(els.statusLowVoltageLast, lowVoltage.last_detected_at || '-');
|
||||
setText(els.statusLowVoltageDuration, eventDurationText(lowVoltage));
|
||||
setText(els.statusLowVoltageRecent, eventRecentText(lowVoltage));
|
||||
setText(els.statusThrottling, throttlingStateText(throttling));
|
||||
setText(els.statusThrottlingLast, throttling.last_detected_at || '-');
|
||||
setText(els.statusThrottlingDuration, eventDurationText(throttling));
|
||||
setText(els.statusThrottlingRecent, eventRecentText(throttling));
|
||||
setText(els.statusBatteryVoltage, battery.voltage === null || battery.voltage === undefined ? '-' : `${Number(battery.voltage).toFixed(3)} V`);
|
||||
setText(els.statusBatterySoc, battery.percent === null || battery.percent === undefined ? '-' : `${Number(battery.percent).toFixed(2)}%`);
|
||||
setText(els.statusBatteryRemaining, battery.remaining?.display || '-');
|
||||
|
||||
+3
-1
@@ -203,9 +203,11 @@ html[data-theme="light"] .btn.secondary{background:#d9e2ef;color:#172033}html[da
|
||||
<div class="status-row"><div class="status-key" data-i18n="lowVoltage">Low Voltage</div><div class="status-value" id="statusLowVoltage">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="lowVoltageLast">Last Low Voltage</div><div class="status-value" id="statusLowVoltageLast">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="lowVoltageDuration">LV Duration</div><div class="status-value" id="statusLowVoltageDuration">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="lowVoltageRecent">LV 10m</div><div class="status-value" id="statusLowVoltageRecent">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="throttling">Throttling</div><div class="status-value" id="statusThrottling">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="throttlingLast">Last Throttling</div><div class="status-value" id="statusThrottlingLast">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="throttlingDuration">Throttle Duration</div><div class="status-value" id="statusThrottlingDuration">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="throttlingRecent">Throttle 10m</div><div class="status-value" id="statusThrottlingRecent">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="batteryV">Battery V</div><div class="status-value" id="statusBatteryVoltage">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="batterySoc">Battery SOC</div><div class="status-value" id="statusBatterySoc">-</div></div>
|
||||
<div class="status-row"><div class="status-key" data-i18n="remaining">Remaining</div><div class="status-value" id="statusBatteryRemaining">-</div></div>
|
||||
@@ -322,7 +324,7 @@ html[data-theme="light"] .btn.secondary{background:#d9e2ef;color:#172033}html[da
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/app.js?v=20260618_throttling1"></script>
|
||||
<script src="/assets/app.js?v=20260618_throttling2"></script>
|
||||
<script src="/assets/wakelock.js?v=20260607_prefs1"></script>
|
||||
<script src="/push_subscribe.js?v=20260607_prefs1"></script>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user