add viz diagnostic metrics to prometheus-exporter
- Viz writes stats to /tmp/viz-stats.json (frames_sent, frames_dropped, queue_depth) - Exporter reads viz-stats.json and exposes: - viz_frames_sent_total (counter) - viz_frames_dropped_total (counter) - viz_pending_queue (gauge) - viz_queue_full (gauge)
This commit is contained in:
@@ -15,6 +15,7 @@ ROWS = 8
|
||||
frame_interval = 1.0 / 30.0 # 30 FPS target
|
||||
next_frame_time = 0.0
|
||||
|
||||
STATS_FILE = "/tmp/viz-stats.json"
|
||||
_poll = select.poll()
|
||||
POLLIN = select.POLLIN
|
||||
POLLOUT = select.POLLOUT
|
||||
@@ -191,6 +192,29 @@ def main():
|
||||
frames_dropped += 1
|
||||
last_frame = frame
|
||||
|
||||
# Write stats periodically (every 2s)
|
||||
if now - _stats_last_write >= 2.0:
|
||||
_write_stats(frames_sent, frames_dropped, pending_frames)
|
||||
_stats_last_write = now
|
||||
|
||||
|
||||
_stats_last_write = 0.0
|
||||
|
||||
|
||||
def _write_stats(sent, dropped, pending):
|
||||
import json
|
||||
try:
|
||||
with open(STATS_FILE, "w") as f:
|
||||
json.dump({
|
||||
"frames_sent": sent,
|
||||
"frames_dropped": dropped,
|
||||
"pending_queue": len(pending),
|
||||
"queue_full": pending.full(),
|
||||
"ts": time.time()
|
||||
}, f)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user