How swlee3306/system-metrics-agent works
This is a Go system-metrics agent: the documented default workflow starts a periodic exporter and HTTP servers, collecting host CPU, memory, and disk data into Prometheus gauges while exposing host-information API routes. Network data is available through its API collector. Authentication, alerting, and time-series storage exist as separate experiments; the README explicitly says they are not wired into the default path. The graph follows shown calls and README statements; unsampled config and peripheral code is represented only where paths are supported.
Main entry points: router.go HTTP servers and routes · metric_exporter.go Metric exporter · main.go Process entry · server.go Agent startup
Components 18
Agent runtime
- Process entry
main.go - Agent startup
cmd/server.go - Standard logger
pkg/logger/logger.go
Host collection
- CPU collector
internal/collector/cpu/cpu.go - Memory collector
internal/collector/memory/memory.go - Disk collector
internal/collector/disk/disk.go - Network collector
internal/collector/network/network.go - Metric data models
pkg/config
Metrics and API
- Metric exporter
internal/collector/exporter/metric_exporter.go - HTTP servers and routes
pkg/web/router.go - Prometheus client
pkg/prometheus/prometheus.go
Unwired experiments
- JWT and permissions
auth/auth.go - Alert rules
alerting/alerts.go - Time-series storage
storage/timeseries.go - Grafana examples
grafana
Other components
- Agent operator
- Prometheus scraper
- API client
Connections 20
- Agent operator → Process entry: starts
README.md - Process entry → Standard logger: logs build info
main.go - Process entry → Agent startup: starts agent
main.go - Agent startup → Metric exporter: starts periodically
cmd/server.go - Agent startup → HTTP servers and routes: starts server
cmd/server.go - Metric exporter → CPU collector: collects
internal/collector/exporter/metric_exporter.go - Metric exporter → Memory collector: collects
internal/collector/exporter/metric_exporter.go - Metric exporter → Disk collector: collects
internal/collector/exporter/metric_exporter.go - Metric exporter → Metric data models: uses models
internal/collector/exporter/metric_exporter.go - HTTP servers and routes → CPU collector: serves CPU info
pkg/web/router.go - HTTP servers and routes → Memory collector: serves memory info
pkg/web/router.go - HTTP servers and routes → Disk collector: serves disk info
pkg/web/router.go - HTTP servers and routes → Network collector: serves network info
pkg/web/router.go - HTTP servers and routes → Metric exporter: registers gauges
pkg/web/router.go - Prometheus scraper → HTTP servers and routes: scrapes metrics
pkg/web/router.go - API client → HTTP servers and routes: requests host data
pkg/web/router.go - Agent operator → JWT and permissions: configures separately
README.md - Agent operator → Alert rules: configures separately
README.md - Agent operator → Time-series storage: configures separately
README.md - Agent operator → Grafana examples: reviews examples
README.md