Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c33577bb9 |
No files matched your search
@@ -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)
|
||||||
@@ -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 |
Reference in new issue
Block a user