Author SHA1 Message Date
Muse 1c33577bb9 monitor-apps/service-dashboard: Service Dashboard app (XMonitorGrid, 12 live dallas services)
One 1024x768 window: XMonitorGrid of XMonitorButton cells for the
real services on hot_dallas -- ports 22/80/443/81/2368/5000/5009/7888,
processes dockerd/containerd, units docker.service/ssh.service.
Live poll_all() on a 2 s GLib timer; green up / red down.
Screenshot verified: 12/12 up. Tests: 363 passed.
2026-12-05 19:55:15 +00:00
7 changed files with 186 additions and 169 deletions

No files matched your search

-30
View File
@@ -1,30 +0,0 @@
# CPU Dashboard — monitor (Python)
A btop-style CPU dashboard in one 1024x768 window, built only from
LightGUI XFrame monitor widgets:
- **XCoreGrid** — per-core mini history graphs
- **XTachometer** — big total-CPU % gauge (redline 80%)
- **XHistoryGraph** — total CPU % over the last 60 s
- **XLoadBadge** — load average 1/5/15 min + uptime
- **XUsageBar** — total CPU % bar
Live data comes from `/proc/stat` (per-core busy %, via
`XCoreGrid.refresh_cores()`) and `/proc/loadavg` (via
`XLoadBadge.refresh_load()`), sampled every 500 ms. Pushing live
samples starts fresh series, so the deterministic demo data is
replaced on the first live sample.
## Run
```sh
PYTHONPATH=. python3 examples/monitor_cpu_dashboard/main.py
```
Esc, `q`, or closing the window quits.
## Source
- App: `examples/monitor_cpu_dashboard/main.py`
- Widgets: `lightgui/xframe/monitor.py`
- Repo: https://github.com/cnmcdee/lightgui_python
-138
View File
@@ -1,138 +0,0 @@
#!/usr/bin/env python3
"""CPU Dashboard - monitor (Python).
A btop-style CPU dashboard in one 1024x768 window, built only from
LightGUI XFrame monitor widgets (XCoreGrid, XTachometer,
XHistoryGraph, XLoadBadge, XUsageBar). Live data from /proc/stat
(per-core busy %, via XCoreGrid.refresh_cores()) and /proc/loadavg
(via XLoadBadge.refresh_load()), sampled every 500 ms. The
deterministic demo data each widget draws with no data pushed is
replaced on the first live sample: push() / push_core() start fresh
series, and the histories are primed with the first live value.
Run with:
PYTHONPATH=/root/monitor-wt/cpu-dashboard/lightgui_python python3 \\
examples/monitor_cpu_dashboard/main.py
(or from the repo root with PYTHONPATH=. )
"""
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, GLib, Gtk # noqa: E402
from lightgui.xframe.core import create, parse_color # noqa: E402
_TITLE = "CPU Dashboard - monitor"
_DESIGN_SIZE = (1024, 768)
_BACKGROUND = ""
_WIDGETS = []
_AREA = []
_PRIMED = [False]
def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
badge = create("XLoadBadge", "LoadBadge_001", 16, 16, 320, 84)
badge.set_prop("label", "Load avg")
badge.refresh_load()
widgets.append(badge)
bar = create("XUsageBar", "UsageBar_001", 352, 16, 656, 84)
bar.set_prop("label", "Total CPU")
bar.set_prop("minimum", "0")
bar.set_prop("maximum", "100")
widgets.append(bar)
grid = create("XCoreGrid", "CoreGrid_001", 16, 116, 640, 300)
grid.set_prop("label", "CPU cores")
grid.set_prop("cores", "8")
widgets.append(grid)
tacho = create("XTachometer", "Tachometer_001", 672, 116, 336, 300)
tacho.set_prop("label", "CPU %")
tacho.set_prop("minimum", "0")
tacho.set_prop("maximum", "100")
tacho.set_prop("redline", "80")
tacho.set_prop("unit", "%")
widgets.append(tacho)
hist = create("XHistoryGraph", "HistoryGraph_001", 16, 432, 992, 320)
hist.set_prop("label", "Total CPU history")
hist.set_prop("window", "60")
hist.set_prop("minimum", "0")
hist.set_prop("maximum", "100")
hist.set_prop("series-names", "CPU")
widgets.append(hist)
return widgets
def _tick():
"""500 ms tick: feed live samples, then redraw."""
badge, bar, grid, tacho, hist = _WIDGETS
values = grid.refresh_cores()
if values:
total = sum(values) / len(values)
if not _PRIMED[0]:
# First live sample: prime the histories with it so no
# seeded demo data is visible (60 = window capacity).
for core, value in enumerate(values):
for _ in range(59):
grid.push_core(core, value)
for _ in range(60):
hist.push(total)
_PRIMED[0] = True
else:
hist.push(total)
tacho.set_value(total)
bar.set_value(total)
badge.refresh_load()
if _AREA:
_AREA[0].queue_draw()
return True
def _on_draw(area, cr):
bg = parse_color(_BACKGROUND, None)
if bg is None:
bg = (1.0, 1.0, 1.0)
cr.set_source_rgb(*bg)
cr.paint()
for widget in _WIDGETS:
widget.draw(cr)
return False
def _on_key_press(window, event):
if event.keyval in (Gdk.KEY_Escape, Gdk.KEY_q):
Gtk.main_quit()
return True
return False
def main():
window = Gtk.Window(title=_TITLE)
window.set_default_size(*_DESIGN_SIZE)
window.set_resizable(False)
window.connect("destroy", Gtk.main_quit)
window.connect("key-press-event", _on_key_press)
area = Gtk.DrawingArea()
area.set_hexpand(True)
area.set_vexpand(True)
area.connect("draw", _on_draw)
window.add(area)
_WIDGETS.extend(_build_widgets())
_AREA.append(area)
GLib.timeout_add(500, _tick)
window.show_all()
Gtk.main()
return 0
if __name__ == "__main__":
import sys
sys.exit(main())
Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

@@ -0,0 +1,55 @@
# Service Dashboard — monitor app (Python)
A service/port dashboard in one window (1024×768): a single
`XMonitorGrid` of illuminator buttons for the services that actually
run on this host (hot_dallas). Each button polls its live check every
2 seconds and glows green when up, red when down, dim when unknown.
Click anywhere on the grid to re-poll every cell now.
## What it monitors
| Button | Kind | Check |
| --- | --- | --- |
| SSH :22 | Port | TCP connect to localhost:22 |
| HTTP :80 | Port | TCP connect to localhost:80 (nginx) |
| HTTPS :443 | Port | TCP connect to localhost:443 (nginx) |
| NPM admin :81 | Port | TCP connect to localhost:81 |
| ThinkMelt :2368 | Port | TCP connect to localhost:2368 |
| Ghost :5000 | Port | TCP connect to localhost:5000 |
| lightgui.com :5009 | Port | TCP connect to localhost:5009 |
| Traffic stats :7888 | Port | TCP connect to localhost:7888 (GoAccess) |
| dockerd | Process | `/proc/<pid>/comm` == `dockerd` |
| containerd | Process | `/proc/<pid>/comm` == `containerd` |
| docker.service | Unit | `systemctl is-active docker.service` == `active` |
| ssh.service | Unit | `systemctl is-active ssh.service` == `active` |
No mock or static data: every cell is a live `XMonitorButton` check
(`poll_all()` on a 2 s `GLib.timeout_add` timer).
## Widgets used
- `XMonitorGrid` — the panel; one shared `poll_all()` timer.
- `XMonitorButton` — one cell per service (kinds port / process /
unit, via `set_monitors`).
## Build and run
```sh
# from the lightgui_python checkout
PYTHONPATH=/root/monitor-wt/service-dashboard/lightgui_python python3 examples/monitor_service_dashboard/main.py
```
## Tests
```sh
DISPLAY=:99 python3 -m unittest discover -s tests
```
## Source
- Python: `examples/monitor_service_dashboard/main.py` in
[lightgui_python](https://github.com/cnmcdee/lightgui_python)
- C++: `examples/monitor/service-dashboard/main.cpp` in
[lightgui](https://github.com/cnmcdee/lightgui)
- Rust: `crates/xframe-demo/examples/monitor_service_dashboard/main.rs`
in [lightgui_rust](https://github.com/cnmcdee/lightgui_rust)
+131
View File
@@ -0,0 +1,131 @@
#!/usr/bin/env python3
"""Service Dashboard -- monitor app.
One 1024x768 window holding a single XMonitorGrid of illuminator
buttons for the services that actually run on this host
(hot_dallas): TCP ports (sshd, nginx, NPM, ThinkMelt, Ghost blogs,
traffic stats), processes (dockerd, containerd) and systemd units
(docker.service, ssh.service). Every cell is a live check, re-polled
on a shared 2 s timer; green when up, red when down. Click a cell
to re-check it now.
Run with the LightGUI Python package on PYTHONPATH:
PYTHONPATH=/root/monitor-wt/service-dashboard/lightgui_python python3 examples/monitor_service_dashboard/main.py
"""
import sys
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, GLib, Gtk # noqa: E402
from lightgui.xframe.core import create, parse_color # noqa: E402
# (check_type, target, label) -- check_type is "port" (TCP connect to
# localhost), "process" (/proc/<pid>/comm match) or "unit"
# (systemctl is-active == active). All of these run on this host.
SERVICES = [
("port", "22", "SSH :22"),
("port", "80", "HTTP :80"),
("port", "443", "HTTPS :443"),
("port", "81", "NPM admin :81"),
("port", "2368", "ThinkMelt :2368"),
("port", "5000", "Ghost :5000"),
("port", "5009", "lightgui.com :5009"),
("port", "7888", "Traffic stats :7888"),
("process", "dockerd", "dockerd"),
("process", "containerd", "containerd"),
("unit", "docker.service", "docker.service"),
("unit", "ssh.service", "ssh.service"),
]
_DESIGN_SIZE = (1024, 768)
_BACKGROUND = ""
_WIDGETS = []
_LAST_SIZE = [None]
_AREA = []
def _build_widgets():
"""Create the grid and wire the real services (no demo data)."""
widgets = []
widget = create("XMonitorGrid", "ServiceGrid_001", 16, 16, 992, 736)
widget.set_prop("label", "Services -- hot_dallas")
# set_monitors replaces the grid cells wholesale (the widget
# starts with none); each cell is a live XMonitorButton check.
widget.set_monitors(SERVICES)
widget.poll_all()
widgets.append(widget)
return widgets
def _on_draw(area, cr):
bg = parse_color(_BACKGROUND, None)
if bg is None:
bg = (1.0, 1.0, 1.0)
cr.set_source_rgb(*bg)
cr.paint()
for widget in _WIDGETS:
widget.draw(cr)
return False
def _on_button_press(area, event):
# Click anywhere on the grid re-polls every cell now (the grid
# has no per-cell click API in Python; the 2 s timer does the
# same check anyway).
for widget in _WIDGETS:
widget.poll_all()
area.queue_draw()
return False
def _on_area_resize(area, allocation):
size = (allocation.width, allocation.height)
if size == _LAST_SIZE[0]:
return False
_LAST_SIZE[0] = size
for widget in _WIDGETS:
widget.move_to(16, 16)
widget.resize_to(max(100, size[0] - 32), max(100, size[1] - 32))
area.queue_draw()
return False
def _tick():
"""Shared 2 s poll: re-check every cell, then redraw."""
for widget in _WIDGETS:
widget.poll_all()
if _AREA:
_AREA[0].queue_draw()
return True
def main():
window = Gtk.Window(title="Service Dashboard - monitor")
window.set_default_size(1024, 768)
window.connect("destroy", Gtk.main_quit)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
window.add(vbox)
area = Gtk.DrawingArea()
area.set_hexpand(True)
area.set_vexpand(True)
area.add_events(
Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK
)
area.connect("draw", _on_draw)
area.connect("button-press-event", _on_button_press)
area.connect("size-allocate", _on_area_resize)
vbox.pack_start(area, True, True, 0)
_WIDGETS.extend(_build_widgets())
_AREA.append(area)
GLib.timeout_add(2000, _tick)
window.show_all()
Gtk.main()
return 0
if __name__ == "__main__":
sys.exit(main())
Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

-1
View File
@@ -1193,7 +1193,6 @@ class MonitorWidget(Widget):
ly = cy + (r - 26) * math.sin(ang) + 3
_wtext(cr, self, label, lx, ly, size=9, rgb=_TEXT,
align="center")
cr.restore()
# Peak-hold tick.
cr.save()
_rgb(cr, _WHITE)