diff --git a/monitor.py b/monitor.py
index c525a5e..3d50550 100644
--- a/monitor.py
+++ b/monitor.py
@@ -659,6 +659,32 @@ class LinkStatsCollector:
# State for UniFi rate calculation (previous snapshot + timestamp)
self._prev_unifi: Dict[str, dict] = {}
self._prev_unifi_time: float = 0.0
+ # Per power unit: (its outlets' last readings, when they last changed)
+ self._outlet_readings: Dict[str, tuple] = {}
+
+ # Live readings from a loaded outlet change every poll (watts and amps to three decimals).
+ # When none of them has moved for this long, UniFi is serving a frozen snapshot: the USP PDU
+ # Pro can keep reporting one set of outlet readings for hours while its total stays live.
+ OUTLET_STALE_AFTER_S = 15 * 60
+
+ def _mark_stale_outlets(self, devices: Dict[str, dict], now: float) -> None:
+ """Mark each metered outlet 'stale' and set the device's 'outlets_stale_since' (UTC)
+ when a power unit's outlet readings have not changed for OUTLET_STALE_AFTER_S."""
+ for name, info in devices.items():
+ metered = [o for o in info.get('outlets') or [] if o.get('power_w') is not None]
+ if not metered:
+ continue
+ readings = tuple((o.get('index'), o.get('power_w'), o.get('current_a')) for o in metered)
+ prev = self._outlet_readings.get(name)
+ since = prev[1] if prev and prev[0] == readings else now
+ self._outlet_readings[name] = (readings, since)
+ # All-zero outlets legitimately read the same every time
+ loaded = any(o.get('power_w') for o in metered)
+ if loaded and now - since >= self.OUTLET_STALE_AFTER_S:
+ stamp = datetime.fromtimestamp(since, timezone.utc)
+ info['outlets_stale_since'] = stamp.strftime('%Y-%m-%d %H:%M:%S UTC')
+ for o in metered:
+ o['stale'] = True
# ------------------------------------------------------------------
# SSH collection (via Pulse worker)
@@ -929,6 +955,7 @@ class LinkStatsCollector:
logger.warning(f'UniFi switch port collection failed: {e}')
unifi_devices = (self.unifi.get_device_details() or {}) if self.unifi else {}
+ self._mark_stale_outlets(unifi_devices, time.time())
host_macs = self._resolve_neighbors(unifi_switches, unifi_devices, instance_map)
return {
diff --git a/static/device.js b/static/device.js
index c9afcb1..865d97a 100644
--- a/static/device.js
+++ b/static/device.js
@@ -292,10 +292,14 @@ function renderOutlets(d) {
|
#${esc(o.index)} |
${esc(o.name || '-')} |
- ${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W`} |
+ ${o.power_w === null || o.power_w === undefined ? '-' : `${o.power_w.toFixed(1)} W${o.stale ? ' stale' : ''}`} |
${o.auto_power_cycle ? 'auto power-cycle' : ''} |
`).join('');
- return section('Outlets', `
+ const since = d.info.outlets_stale_since;
+ const note = since
+ ? `The outlet readings have not changed since ${esc(since)}: UniFi is sending a frozen snapshot, so they are not live. The power draw total is live.
`
+ : '';
+ return section('Outlets', `${note}
PDU outlets
| State | Outlet | Name | Power | |
${rows}
`);
diff --git a/static/faceplates.js b/static/faceplates.js
index 682231b..debb02a 100644
--- a/static/faceplates.js
+++ b/static/faceplates.js
@@ -147,6 +147,18 @@ function outletFaceSvg(kind, w, h, idx) {
return `
`;
}
+ if (kind === 'usbc-h') {
+ return `
+ `;
+ }
+ if (kind === 'us-bare') {
+ // A US socket moulded straight into a white body (the SmartPower Strip): no face plate,
+ // just a shallow recess with the two blades over the round ground
+ return `
+
+
+ `;
+ }
const face = ``;
if (kind === 'horizontal') {
return `${face}
@@ -168,7 +180,7 @@ function outletTitle(o, data) {
if (data) {
if (data.name && data.name !== parts[0]) parts.push(data.name);
parts.push(data.on === false ? 'off' : 'on');
- if (data.power_w != null) parts.push(`${data.power_w.toFixed(1)} W`);
+ if (data.power_w != null) parts.push(`${data.power_w.toFixed(1)} W${data.stale ? ' (stale reading)' : ''}`);
if (data.auto_power_cycle) parts.push('auto power-cycle');
}
return lt.escHtml(parts.join(' · '));
@@ -566,6 +578,38 @@ const FACEPLATES = {
`;
},
},
+
+ // UniFi SmartPower Strip (USP-Strip), top face. Traced from the product render on Ubiquiti's
+ // datasheet (images.salsify.com/.../046c9c047ca057faf25eb38f48c598318c9ae699.pdf, page 1) and
+ // sized from its 229.5 x 111.5 mm footprint at 4 units per mm, plus the cord on the left.
+ // Six AC outlets in three facing pairs (1 over 2, 3 over 4, 5 over 6), and four USB-C ports
+ // that UniFi switches together as outlet 7, "USB Outlets".
+ UP6: {
+ width: 968, height: 446, frameClass: 'fp-desk', noBody: true,
+ label: 'SmartPower Strip',
+ legend: [['outlet-on', 'outlet on'], ['outlet-off', 'outlet off']],
+ ports: [],
+ outlets: [
+ ...[338, 502, 664].flatMap((cx, i) => [
+ { idx: 2 * i + 1, kind: 'us-bare', flip: true, x: cx - 33, y: 86, w: 66, h: 66, label: [cx - 16, 232] },
+ { idx: 2 * i + 2, kind: 'us-bare', x: cx - 33, y: 294, w: 66, h: 66, label: [cx + 22, 232] },
+ ]),
+ ...[84, 165, 250, 335].map((y, i) => ({
+ idx: 7, kind: 'usbc-h', x: 852, y: y - 7, w: 40, h: 14, label: i === 3 ? [872, y + 46] : null,
+ })),
+ ],
+ decor({ online }) {
+ const usbNums = [84, 165, 250, 335].map((y, i) =>
+ `${i + 1}`).join('');
+ return `
+
+
+
+
+ USB-C
+ ${usbNums}`;
+ },
+ },
};
function faceplateLegendSwatch(cls) {
diff --git a/static/style.css b/static/style.css
index e497169..9a723fc 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1030,6 +1030,13 @@ tr.device-row.is-selected { background: var(--bg-tertiary); box-shadow: inset 3p
.fp-usbc-tongue { fill: #b9bcc2; }
.fp-outlet-is-off .fp-outlet-face { fill: #5b5c60; }
.fp-outlet-is-off .fp-usbc { fill: #66676b; }
+.fp-outlet-bare { fill: #e6e6e8; stroke: #cfcfd2; stroke-width: 1; }
+.fp-outlet-is-off .fp-outlet-bare { fill: #b9babe; }
+.fp-cord { stroke: #d9d9db; stroke-width: 16; stroke-linecap: round; fill: none; }
+.fp-cord-boot { fill: #cfcfd2; }
+.fp-strip-logo { fill: none; stroke: #b9babe; stroke-width: 6; stroke-linecap: round; }
+.fp-strip-led { fill: #c9cacd; }
+.fp-strip-led-on { fill: #5ad7f0; filter: drop-shadow(0 0 4px #5ad7f0); }
.fp-outlet:hover .fp-hit { stroke: rgba(0,90,220,.55); }
.fp-outlet:focus-visible .fp-hit { stroke: #0058e0; fill: rgba(0,88,224,.14); }
.fp-outlet-state { fill: #8d8e93; }
@@ -1652,6 +1659,7 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
.tp-outlet-watts { font-family: var(--font); font-size: 24px; fill: #e0a400; }
.tp-outlet-free .tp-outlet-target { fill: var(--text-muted); font-style: italic; }
.tp-outlet-off .tp-outlet-watts, .tp-outlet-off .tp-outlet-target { fill: #ff6b5e; }
+.tp-outlet-stale .tp-outlet-watts { fill: var(--text-muted, #8a929c); font-style: italic; }
.tp-power-badge { font-family: var(--font); font-size: 26px; font-weight: 700; fill: #e0a400; }
.tp-power-off { fill: #ff6b5e; }
.tp-feeds { pointer-events: none; }
diff --git a/static/topology.js b/static/topology.js
index acef457..185e7ca 100644
--- a/static/topology.js
+++ b/static/topology.js
@@ -103,6 +103,12 @@ function problemsOf(data) {
out.push({ kind: 'node', id: n.id, severity: n.status === 'down' || n.severity === 'critical' ? 'bad' : 'warn',
text: `${n.name}: ${bits.join(', ')}` });
});
+ (data.power || []).forEach(src => {
+ if (src.stale_since) {
+ out.push({ kind: 'node', id: src.node, severity: 'warn',
+ text: `${src.node} outlet watts frozen since ${sinceText(src.stale_since)}; its total is live` });
+ }
+ });
(data.power || []).forEach(src => src.outlets.forEach(o => {
if (o.on || !o.target) return;
const down = (byId[o.target] || {}).status === 'down';
@@ -132,6 +138,17 @@ function problemsOf(data) {
return out;
}
+// "2026-11-14 22:48:00 UTC" as local time: just the time today, else the date and time
+function sinceText(utc) {
+ const d = new Date(String(utc).replace(' UTC', 'Z').replace(' ', 'T'));
+ if (Number.isNaN(d.getTime())) return String(utc);
+ const time = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
+ return d.toDateString() === new Date().toDateString() ? time : `${d.toLocaleDateString()} ${time}`;
+}
+
+const STALE_TIP = 'UniFi has been sending the same outlet readings for a long time, so these watts are not live. '
+ + 'The unit\'s total is still live.';
+
function speedClass(mbps) {
if (mbps >= 10000) return 'tp-s-10g';
if (mbps >= 1000) return 'tp-s-1g';
@@ -370,7 +387,7 @@ function artFor(node) {
case 'stub': return node.via && node.via.kind === 'patch_panel' ? patchPanelDrawing(node) : stubDrawing();
case 'group': return groupDrawing(node);
case 'ap': return apDrawing(node);
- case 'strip': return stripDrawing(node);
+ case 'strip': return spec ? faceplateDrawing(node, node.model, 1100) : stripDrawing(node);
default:
if (spec && DESK_FACEPLATES[node.model]) return deskFaceplate(node);
if (spec) return faceplateDrawing(node, node.model, 1100, { rack: node.kind === 'ups', crop: !node.power });
@@ -476,14 +493,15 @@ function cardFor(node, linksByIface) {
const y = CARD_H + i * ROW_H;
rows[o.index] = y + ROW_H / 2;
const what = o.target || (o.match === 'cleared' ? 'nothing' : 'unassigned');
- const cls = `tp-outlet-row${o.on ? '' : ' tp-outlet-off'}${o.target ? '' : ' tp-outlet-free'}`;
- const tip = `${node.name} outlet ${o.index}${o.name ? ` "${o.name}"` : ''} · ${o.on ? 'on' : 'off'}${o.power_w != null ? ` · ${wattText(o.power_w)}` : ''} · feeds ${what}${o.match === 'saved' ? ' (set here)' : o.match === 'name' ? ' (from its name)' : o.match === 'mac' ? ' (from the MAC in its name)' : ''}${TOPO_CAN_EDIT ? ' · click to change' : ''}`;
+ const cls = `tp-outlet-row${o.on ? '' : ' tp-outlet-off'}${o.target ? '' : ' tp-outlet-free'}${o.stale ? ' tp-outlet-stale' : ''}`;
+ const tip = `${node.name} outlet ${o.index}${o.name ? ` "${o.name}"` : ''} · ${o.on ? 'on' : 'off'}${o.power_w != null ? ` · ${wattText(o.power_w)}${o.stale ? ' (stale)' : ''}` : ''} · feeds ${what}${o.match === 'saved' ? ' (set here)' : o.match === 'name' ? ' (from its name)' : o.match === 'mac' ? ' (from the MAC in its name)' : ''}${TOPO_CAN_EDIT ? ' · click to change' : ''}`;
+ const staleTip = o.stale ? ` · ${STALE_TIP}` : '';
return `
- ${esc(tip)}
+ ${esc(tip + staleTip)}
${o.index}
${esc(what.length > 22 ? `${what.slice(0, 21)}…` : what)}
- ${o.on ? esc(wattText(o.power_w)) : 'off'}
+ ${!o.on ? 'off' : o.stale ? 'stale' : esc(wattText(o.power_w))}
`;
}).join('');
h = CARD_H + list.length * ROW_H + (list.length ? 16 : 0);
@@ -492,9 +510,12 @@ function cardFor(node, linksByIface) {
let badge = '';
if ((node.power_in || []).length) {
const off = node.power_in.some(f => !f.on);
+ const stale = node.power_in.some(f => f.stale);
const watts = node.power_in.reduce((t, f) => t + (f.power_w || 0), 0);
- const tip = node.power_in.map(f => `${f.source} outlet ${f.outlet}${f.on ? '' : ' (off)'}${f.power_w != null ? ` · ${wattText(f.power_w)}` : ''}`).join('; ');
- badge = `${esc(`Fed by ${tip}`)}⚡ ${off ? 'off' : esc(wattText(watts) || 'fed')}`;
+ const tip = node.power_in.map(f => `${f.source} outlet ${f.outlet}${f.on ? '' : ' (off)'}${f.power_w != null ? ` · ${wattText(f.power_w)}${f.stale ? ' (stale)' : ''}` : ''}`).join('; ');
+ // A frozen reading is not shown as if it were live
+ const text = off ? 'off' : stale ? 'fed' : (wattText(watts) || 'fed');
+ badge = `${esc(`Fed by ${tip}${stale ? `. ${STALE_TIP}` : ''}`)}⚡ ${esc(text)}`;
}
const maxChars = Math.floor((w - 130) / 27);
const name = node.name.length > maxChars ? `${node.name.slice(0, maxChars - 1)}…` : node.name;
@@ -1045,10 +1066,12 @@ function drawFeeds(id) {
const c = Math.max(160, Math.abs(from.x - B.x) * 0.4);
const d = `M${from.x} ${from.y} C${from.x - c} ${from.y} ${B.x + c} ${B.y} ${B.x} ${B.y}`;
const mx = (from.x + B.x) / 2, my = (from.y + B.y) / 2;
+ const text = `⚡ ${target} ${!o.on ? 'off' : o.stale ? '(watts stale)' : wattText(o.power_w)}`;
+ const tw = Math.max(300, text.length * 15 + 40);
return `
-
- ⚡ ${esc(target)} ${o.on ? esc(wattText(o.power_w)) : 'off'}`;
+
+ ${esc(text)}`;
}).join('');
// Everything at either end of a feed stays lit while the path is traced
return new Set(pairs.flatMap(p => [p.target, ...((state.data.power || []).filter(src => src.outlets.includes(p.o)).map(src => src.node))]));
diff --git a/tests/test_monitor.py b/tests/test_monitor.py
index 2e6882c..118e347 100644
--- a/tests/test_monitor.py
+++ b/tests/test_monitor.py
@@ -485,6 +485,52 @@ class TestWanIncident:
assert not mon.tickets.create.called and not mon.tickets.comment.called
+class TestStaleOutletReadings:
+ @staticmethod
+ def _pdu(w1=20.622, w2=0.0):
+ return {'RPDU': {'outlets': [
+ {'index': 1, 'power_w': w1, 'current_a': 0.322},
+ {'index': 2, 'power_w': w2, 'current_a': 0.0},
+ {'index': 3, 'power_w': None, 'current_a': None}, # USB: never metered
+ ]}}
+
+ def _collector(self):
+ c = monitor.LinkStatsCollector.__new__(monitor.LinkStatsCollector)
+ c._outlet_readings = {}
+ return c
+
+ def test_readings_frozen_past_the_limit_are_stale(self):
+ c = self._collector()
+ c._mark_stale_outlets(self._pdu(), 1000.0)
+ later = self._pdu()
+ c._mark_stale_outlets(later, 1000.0 + c.OUTLET_STALE_AFTER_S)
+ assert later['RPDU']['outlets_stale_since'] == '1970-01-01 00:16:40 UTC'
+ assert [o.get('stale') for o in later['RPDU']['outlets']] == [True, True, None]
+
+ def test_moving_readings_are_live(self):
+ c = self._collector()
+ c._mark_stale_outlets(self._pdu(), 1000.0)
+ c._mark_stale_outlets(self._pdu(w1=21.0), 1000.0 + c.OUTLET_STALE_AFTER_S - 1)
+ later = self._pdu(w1=21.0)
+ c._mark_stale_outlets(later, 1000.0 + c.OUTLET_STALE_AFTER_S + 60)
+ assert 'outlets_stale_since' not in later['RPDU']
+ assert not any(o.get('stale') for o in later['RPDU']['outlets'])
+
+ def test_idle_outlets_reading_zero_are_not_stale(self):
+ c = self._collector()
+ c._mark_stale_outlets(self._pdu(w1=0.0), 1000.0)
+ later = self._pdu(w1=0.0)
+ c._mark_stale_outlets(later, 1000.0 + 10 * c.OUTLET_STALE_AFTER_S)
+ assert 'outlets_stale_since' not in later['RPDU']
+
+ def test_unmetered_strip_is_left_alone(self):
+ c = self._collector()
+ strip = {'USP Strip': {'outlets': [{'index': 1, 'power_w': None}]}}
+ c._mark_stale_outlets(strip, 1000.0)
+ c._mark_stale_outlets(strip, 1000.0 + 10 * c.OUTLET_STALE_AFTER_S)
+ assert 'outlets_stale_since' not in strip['USP Strip'] and 'USP Strip' not in c._outlet_readings
+
+
class TestUnifiDeviceDetail:
def test_parses_string_stats_and_outlets(self):
d = monitor.UnifiClient._device_detail({
diff --git a/tests/test_topology.py b/tests/test_topology.py
index 946e7ce..69de108 100644
--- a/tests/test_topology.py
+++ b/tests/test_topology.py
@@ -403,9 +403,23 @@ class TestPower:
def test_devices_know_what_feeds_them(self):
g = self._graph()
- assert node(g, 'host-c')['power_in'] == [{'source': 'RPDU', 'outlet': 16, 'on': True, 'power_w': 131.7}]
+ assert node(g, 'host-c')['power_in'] == [{'source': 'RPDU', 'outlet': 16, 'on': True, 'power_w': 131.7,
+ 'stale': False}]
assert node(g, 'host-b')['power_in'] == []
+ def test_frozen_readings_are_passed_on_as_stale(self):
+ snapshot, link_stats, modem = network()
+ link_stats['unifi_devices']['RPDU']['outlets'] = [
+ dict(o, stale=True) if o.get('power_w') is not None else o for o in self.OUTLETS]
+ link_stats['unifi_devices']['RPDU']['outlets_stale_since'] = '2026-11-14 22:48:00 UTC'
+ link_stats['host_macs'] = {'02:00:5e:00:0a:01': ['host-c', 'nic0']}
+ g = topology.build_graph(snapshot, link_stats, modem, [], [], [], None, [])
+ src = next(s for s in g['power'] if s['node'] == 'RPDU')
+ assert src['stale_since'] == '2026-11-14 22:48:00 UTC'
+ assert src['outlets'][[o['index'] for o in src['outlets']].index(16)]['stale'] is True
+ assert node(g, 'host-c')['power_in'][0]['stale'] is True
+ assert next(s for s in g['power'] if s['node'] == 'UPS 2U Pro')['stale_since'] is None
+
def test_a_power_device_does_not_feed_itself(self):
out = self._outlets(self._graph(outlets=[{'index': 1, 'name': 'RPDU spare', 'on': True}]))
assert out[1]['target'] is None
diff --git a/topology.py b/topology.py
index cd5e7b3..5563d79 100644
--- a/topology.py
+++ b/topology.py
@@ -144,8 +144,9 @@ def build_power(nodes: Dict[str, dict], link_stats: dict, feeds: List[dict]) ->
In order: an assignment saved on the topology page (target '' means nothing), then the
outlet's name if it names a device ("storage-01", "Dream Machine Pro", or "AT&T Modem" for
the modem), then a MAC in its name that belongs to a host NIC or a UniFi device.
- Returns [{node, power_w, outlets: [{index, name, on, power_w, auto_power_cycle, target,
- match: saved|cleared|name|mac|none}]}].
+ Returns [{node, power_w, stale_since, outlets: [{index, name, on, power_w, stale,
+ auto_power_cycle, target, match: saved|cleared|name|mac|none}]}]. stale_since is set when
+ the monitor saw the unit's outlet readings stop changing (UniFi serving a frozen snapshot).
"""
known = {_norm(n['name']): n['name'] for n in nodes.values() if n['kind'] not in ('stub', 'internet')}
modem = next((n['name'] for n in nodes.values() if n['kind'] == 'modem'), None)
@@ -181,9 +182,11 @@ def build_power(nodes: Dict[str, dict], link_stats: dict, feeds: List[dict]) ->
target = macs.get(m.group(1).lower().replace('-', ':')) if m else None
how = 'mac' if target else 'none'
rows.append({'index': idx, 'name': text, 'on': o.get('on') is not False,
- 'power_w': o.get('power_w'), 'auto_power_cycle': bool(o.get('auto_power_cycle')),
+ 'power_w': o.get('power_w'), 'stale': bool(o.get('stale')),
+ 'auto_power_cycle': bool(o.get('auto_power_cycle')),
'target': target, 'match': how})
- sources.append({'node': node['name'], 'power_w': node.get('power_w'), 'outlets': rows})
+ sources.append({'node': node['name'], 'power_w': node.get('power_w'), 'outlets': rows,
+ 'stale_since': node.get('outlets_stale_since')})
return sources
@@ -289,6 +292,7 @@ def build_graph(snapshot: dict, link_stats: dict, modem: Optional[dict], events:
info = unifi_info.get(name) or {}
node['power_w'] = info.get('power_w')
node['outlets'] = info.get('outlets') or []
+ node['outlets_stale_since'] = info.get('outlets_stale_since')
node_alerts = alerts.get(name, [])
node['alerts'] = node_alerts[:10]
node['alert_count'] = len(node_alerts)
@@ -487,7 +491,8 @@ def build_graph(snapshot: dict, link_stats: dict, modem: Optional[dict], events:
for o in src['outlets']:
if o['target'] in nodes:
nodes[o['target']]['power_in'].append(
- {'source': src['node'], 'outlet': o['index'], 'on': o['on'], 'power_w': o['power_w']})
+ {'source': src['node'], 'outlet': o['index'], 'on': o['on'], 'power_w': o['power_w'],
+ 'stale': o['stale']})
if not switches:
warnings.append('No UniFi switch data yet: the monitor has not reported any ports')