How snippycode101/sysmon works
sysmon is a Linux resource-monitoring service: its entrypoint starts periodic /proc sampling alongside an HTTP API, and clients retrieve metrics and threshold alerts as JSON. The collector calculates CPU, memory, and load, checks configured thresholds, and writes snapshots and alerts to a synchronized in-memory store; API handlers read that state. The README documents graceful shutdown and all three endpoints. Relationships are shown where supported by the excerpts; /proc inputs are external to the repository.
Main entry points: collector.go Periodic collector · api.go Route registration · main.go Service entrypoint · store.go In-memory store
Components 19
Service runtime
- Service entrypoint
cmd/sysmon/main.go
Resource collection
- Periodic collector
internal/collector/collector.go - CPU sampling
internal/collector/collector.go - Memory sampling
internal/collector/collector.go - Load sampling
internal/collector/collector.go - Threshold checks
internal/collector/collector.go
Shared state
- In-memory store
internal/store/store.go - Latest snapshot
internal/store/store.go - Alert history
internal/store/store.go
HTTP API
- HTTP server setup
internal/api/api.go - Route registration
internal/api/api.go - Request logging
internal/api/api.go - Health endpoint
internal/api/api.go - Metrics endpoint
internal/api/api.go - Alerts endpoint
internal/api/api.go
Other components
- Operator / client
- /proc/stat
- /proc/meminfo
- /proc/loadavg
Connections 24
- Service entrypoint → In-memory store: creates
cmd/sysmon/main.go - Service entrypoint → Periodic collector: configures and starts
cmd/sysmon/main.go - Service entrypoint → HTTP server setup: starts HTTP server
cmd/sysmon/main.go - Periodic collector → CPU sampling: samples
internal/collector/collector.go - Periodic collector → Memory sampling: samples
internal/collector/collector.go - Periodic collector → Load sampling: samples
internal/collector/collector.go - CPU sampling → /proc/stat: reads
internal/collector/collector.go - Memory sampling → /proc/meminfo: reads
internal/collector/collector.go - Load sampling → /proc/loadavg: reads
internal/collector/collector.go - Periodic collector → Threshold checks: checks snapshot
internal/collector/collector.go - Periodic collector → Latest snapshot: writes snapshot
internal/collector/collector.go - Threshold checks → Alert history: appends breaches
internal/collector/collector.go - In-memory store → Latest snapshot: holds
internal/store/store.go - In-memory store → Alert history: bounds
internal/store/store.go - HTTP server setup → Route registration: builds routes
internal/api/api.go - Route registration → Request logging: wraps handler
internal/api/api.go - Route registration → Health endpoint: routes
internal/api/api.go - Route registration → Metrics endpoint: routes
internal/api/api.go - Route registration → Alerts endpoint: routes
internal/api/api.go - Metrics endpoint → Latest snapshot: reads
internal/api/api.go - Alerts endpoint → Alert history: reads
internal/api/api.go - Operator / client → Health endpoint: requests
README.md - Operator / client → Metrics endpoint: requests
README.md - Operator / client → Alerts endpoint: requests
README.md