Skip to content

Add Grafana dashboard and display_name label to Prometheus metrics - #70

Merged
jantman merged 2 commits into
mainfrom
dashboard
Nov 30, 2025
Merged

Add Grafana dashboard and display_name label to Prometheus metrics#70
jantman merged 2 commits into
mainfrom
dashboard

Conversation

@jantman

@jantman jantman commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds a comprehensive Grafana dashboard for visualizing system metrics and enhances Prometheus metrics with human-friendly display names.

Changes

1. Grafana Dashboard (docs/source/grafana-dashboard.json)

  • Comprehensive monitoring dashboard with 29 panels across 5 sections
  • System Status: Server uptime, user/fob counts with trends, connectivity monitoring, lockout status
  • Machine Usage: Real-time relay states, RFID presence, oops button monitoring, relay timeline, time-since-checkin visualization
  • Machine Health: WiFi signal (% and dB), ESP32 temperature, controller uptime
  • Usage Analytics: Current session durations, 24h usage distribution, user presence indicators
  • Machine Details: Per-machine drill-down with template variable selector

Dashboard Features:

  • 24-hour default view with 5-second auto-refresh
  • Logarithmic scales on uptime and check-in graphs for better visibility across value ranges
  • Color-coded thresholds for connectivity health (green <60s, yellow 1-5min, orange 5-10min, red >10min)
  • Gray backgrounds for normal states, red for problems (follows "quiet good news, loud bad news" principle)

2. Prometheus Metrics Enhancement (src/dm_mac/views/prometheus.py)

  • Added display_name label to all 19 machine-based metrics
  • Preserves existing machine_name label for backward compatibility
  • display_name uses machine alias if configured, otherwise falls back to machine name
  • Enables human-friendly names in dashboards while maintaining technical identifiers for queries

3. Documentation

  • docs/source/admin.rst: Added Grafana Dashboard section with features overview, import instructions, and embedded JSON
  • docs/source/grafana-dashboard.md: Comprehensive 400+ line reference document covering:
    • All panel configurations and design decisions
    • Complete metrics reference table
    • Common modification guides
    • Troubleshooting tips
    • Future enhancement ideas

4. Test Updates (tests/views/test_prometheus.py)

  • Updated all Prometheus metric test expectations to include both labels
  • Tests verify "Metal Mill" shows proper alias in display_name
  • All 155 tests pass

Dashboard Design Highlights

Logarithmic Scales

Used on Machine Controller Uptime and Time Since Last Check-In to handle machines with vastly different value ranges (some run for weeks, others reboot frequently). Makes proportional changes visible across all machines.

Color Coding

  • Oops Button: Dark gray for normal (quiet), red for problems (attention-grabbing)
  • Connectivity: Time-based thresholds with color progression
  • Machine States: Blue for idle, green for active, red for errors

Time-Since-Checkin Graph

New visualization showing seconds since last machine check-in with:

  • Logarithmic scale for wide value range
  • Color-coded health thresholds
  • Easy identification of connectivity issues

Benefits

✅ Real-time visual monitoring of all machine states
✅ Historical trend analysis for capacity planning
✅ Quick identification of connectivity and health issues
✅ Human-friendly names (aliases) in dashboard legends
✅ Backward compatible - both labels available for filtering/querying
✅ Comprehensive documentation for future development

Testing

  • ✅ All 155 tests passing
  • ✅ Prometheus views have 100% test coverage
  • ✅ All pre-commit hooks pass (black, flake8, mypy, sphinx)
  • ✅ Dashboard JSON validated and importable into Grafana

Screenshots

Dashboard includes visualization of:

  • 6 system-level metrics (uptime, users, fobs, connectivity, lockouts)
  • 19 machine-specific metrics (relay, oops, RFID, WiFi, temperature, etc.)
  • Log-scale graphs for better visibility across value ranges
  • Color-coded health indicators

Related

Builds on PR #69 which added the display_name property to the Machine model.

jantman and others added 2 commits November 30, 2025 10:20
…zation

This commit introduces a pre-built Grafana dashboard that visualizes all
Prometheus metrics exposed by the /metrics endpoint. The dashboard provides
real-time monitoring and historical visualization of machine status, health,
connectivity, and usage patterns.

Dashboard Features:
- System Status: Server uptime, user/fob counts with trends, machine
  connectivity (5min check-in), lockout status overview
- Machine Usage: Real-time relay states, RFID presence, oops button
  monitoring, relay state timeline, time-since-checkin tracking
- Machine Health: WiFi signal strength (% and dB), ESP32 temperature,
  controller uptime with log scale
- Usage Analytics: Current session durations, 24h usage distribution,
  known user presence indicators
- Machine Details: Per-machine drill-down with selectable variable

Key Design Decisions:
- Logarithmic scales on uptime and check-in graphs to handle machines
  with vastly different value ranges (some run for weeks, others reboot
  frequently)
- Gray background for normal machine states, red for problems (oops
  button) following "quiet good news, loud bad news" principle
- Time-since-checkin visualization with color-coded thresholds (green
  <60s, yellow 1-5min, orange 5-10min, red >10min) for connectivity
  health monitoring
- 24-hour default view with 5-second auto-refresh
- Removed current draw panels as feature not currently implemented

Files Added:
- docs/source/grafana-dashboard.json: Complete dashboard definition with
  29 panels organized into 5 sections
- docs/source/grafana-dashboard.md: Comprehensive documentation covering
  all panels, metrics, design decisions, modification guides, and
  troubleshooting

Files Modified:
- docs/source/admin.rst: Added Grafana Dashboard section with features
  overview, import instructions, and embedded JSON using literalinclude
  directive for automatic doc updates

Dashboard Configuration:
- UID: dm-mac-dashboard
- Default time range: 24 hours (now-24h to now)
- Refresh rate: 5 seconds
- Description: GitHub URL for source reference
- Template variables: $machine selector for detailed views

The dashboard JSON is embedded in the Sphinx documentation so it stays
in sync with the actual file, and includes complete inline documentation
for future development work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…oard

This commit adds a display_name label to all machine-based Prometheus metrics,
in addition to the existing machine_name label. The display_name uses the
machine's alias if configured, otherwise falls back to the machine name. This
provides human-friendly names in dashboards and queries while preserving the
technical machine_name for filtering and querying.

Changes to Prometheus Metrics (src/dm_mac/views/prometheus.py):
- Added display_name label to all 19 machine-specific metrics
- Both machine_name and display_name labels are now present on all metrics
- Used m.display_name property which returns alias if set, otherwise name
- Labels are alphabetically sorted: display_name, machine_name

Test Updates (tests/views/test_prometheus.py):
- Updated all expected metric outputs to include both labels
- Metal Mill machine shows display_name="Metal Mill" (uses alias)
- Other machines show display_name equal to machine_name (no alias)
- LED metrics updated to include display_name in addition to led_attribute

Documentation Updates (docs/source/admin.rst):
- Updated all metric examples to show both labels
- Examples now reflect the display_name label in output
- Metal Mill consistently shows display_name="Metal Mill"

Grafana Dashboard Updates (docs/source/grafana-dashboard.json):
- Changed all legendFormat from {{machine_name}} to {{display_name}}
- Updated template variable query to use display_name
- Dashboard now shows human-friendly names (aliases) in legends and labels
- Machine selector dropdown uses display_name for better UX

Dashboard Documentation (docs/source/grafana-dashboard.md):
- Updated metrics table to show both labels for machine metrics
- Updated template variable description
- Clarified that display_name uses alias if present

Benefits:
- Dashboards show human-friendly "Metal Mill" instead of "metal-mill"
- Preserves machine_name for programmatic filtering/querying
- Backward compatible - both labels available for PromQL queries
- Consistent with existing display_name property from PR #69

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/dm_mac
   __init__.py690100% 
   cli_utils.py150100% 
   neongetter.py1860100% 
   slack_handler.py1500100% 
   utils.py250100% 
src/dm_mac/models
   __init__.py00100% 
   machine.py361199%670
   users.py940100% 
src/dm_mac/views
   __init__.py00100% 
   api.py220100% 
   machine.py690100% 
   prometheus.py990100% 
TOTAL1090199% 

Tests Skipped Failures Errors Time
155 0 💤 0 ❌ 0 🔥 13.304s ⏱️

@jantman
jantman merged commit cfc396a into main Nov 30, 2025
16 checks passed
@jantman
jantman deleted the dashboard branch November 30, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant