#!/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//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())