Skip to content

ryanduan02/raspberry-pi-system-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

rpi-metrics

A metrics agent for Raspberry Pi written in Go.

Features

  • Collector based architecture
  • Interval scheduler/runner
  • Console exporter (JSON Lines to stdout)
  • CPU temperature collector with sysfs:
    • /sys/class/thermal/thermal_zone0/temp (millidegrees Celsius)
  • Storage usage collector (Linux statfs):
    • Total/free/available/used bytes and used percent (per configured path)

Requirements

  • Raspberry Pi OS
  • Go installed (Go 1.22+ recommended)

Usage

To verify the temperature source exists:

cat /sys/class/thermal/thermal_zone0/temp

You should see an integer like 51250 (meaning 51.250°C). Build

From the rpi-metrics/ directory:

cd ~/Code/raspberry-pi-system-control/rpi-metrics
go mod tidy
mkdir -p bin
go build -o ./bin/rpi-metrics ./cmd/rpi-metrics

Run Basic run (collect every 5 seconds)

./bin/rpi-metrics -interval=5s

Example output (JSON line per interval):

{"collected_at":"2025-12-26T12:45:06.543191272Z","samples":
[{"name":"cpu_temperature","value":51.25,"unit":"celsius",
"ts":"2025-12-26T12:45:06.543188513Z","labels":{"path":"/sys/
class/thermal/thermal_zone0/temp","source":"sysfs"}}]}

To run discord messenger:

./bin/rpi-metrics -interval= {x}s -discord-webhook="https://discord.com/api/webhooks/{webook_id}" -discord-every= {x}s

Running persistently (SSH disconnect safe)

If you start rpi-metrics directly in an SSH session, it will usually stop when the SSH connection closes (e.g. you close your laptop).

TMUX

On the Pi:

sudo apt-get update
sudo apt-get install -y tmux
./scripts/tmux-start.sh -- -interval=5s -discord-webhook="https://discord.com/api/webhooks/REPLACE_ME" -discord-every=1m

Detach without stopping it: press Ctrl-b then d.

Later, reattach:

./scripts/tmux-attach.sh

Stop it: Ctrl-c inside the tmux session.

Or stop the session directly:

./scripts/tmux-stop.sh

Check logs:

sudo journalctl -u rpi-metrics -f

Stop it:

sudo systemctl stop rpi-metrics

Flags

  • interval - Collection interval duration (Go duration format). Examples: 500ms, 2s, 30s, 1m.

  • temp-path - Path to the sysfs temperature file.

  • storage-paths - Comma-separated list of filesystem paths to measure. Examples: / or /,/boot.

Example:

./bin/rpi-metrics -interval=2s -temp-path=/sys/class/thermal/thermal_zone0/temp

./bin/rpi-metrics -interval=5s -storage-paths=/,/boot
./bin/rpi-metrics -interval=5s -discord-webhook=https://discord.com/api/webhooks/{INSERT WEBHOOK} -discord-every=5s 

Web UI Dashboard

A web-based dashboard is available to visualize metrics in real-time. This should be packaged eventually

Build

cd ~/Code/raspberry-pi-system-control/rpi-metrics
go build -o ./bin/rpi-metrics-ui ./cmd/rpi-metrics-ui

Run

./bin/rpi-metrics-ui

Then open http://localhost:8080 in your browser.

Flags

  • -port - HTTP server port (default: 8080)

Example with custom port:

./bin/rpi-metrics-ui -port=3000

Features

  • CPU Temperature - Color-coded display with progress bar
  • CPU Utilization - Total usage plus per-core breakdown
  • Cooling State - Visual fan speed indicator (0-4 levels)
  • Storage - Multiple mount points with used/free/total display
  • Auto-refresh every 2 seconds
  • Pause/Resume functionality
  • Responsive design for mobile devices

Notes

This tool currently exports to stdout only. It is designed so additional exporters can be added later (HTTP/Prometheus scrape endpoint, MQTT, InfluxDB, etc.). CPU metrics reading uses sysfs for simplicity and performance.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published