Skip to content

Latest commit

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

🖥️ System Stats API for Linux

About

Lightweight, fast system monitoring API written in Go.
Provides CPU, memory, disk, network and load metrics with both raw values and strings, e.g. 1.23 GB, 12.34%). Built for Linux (Debian/Ubuntu).


🌟 Key Features

  • Background StatsCollector with configurable refresh interval (caches metrics to reduce request latency).
  • Endpoints return both raw and readable fields for easy UI/alerts and programmatic use.
  • /health endpoint (uptime, version, time).
  • Logging + panic recovery middleware.
  • Simple CORS header (Access-Control-Allow-Origin: *).
  • Graceful shutdown (SIGINT/SIGTERM) and HTTP timeouts.
  • Configurable via config.json.

🚀 Quickstart

1. Clone

git clone https://github.com/mambuzrrr/brejax-system-stats-api.git
cd brejax-system-stats-api

2. Install dependencies

Make sure you have Go installed (go version should return a valid version).

go mod tidy

3. Configure the API

Edit the config.json file to customize your port and endpoint paths:

{
"port": 8123,
"refresh_interval_sec": 5,
"version": "0.1.0",
"endpoints": {
"stats": "/system-stats",
"cpu": "/cpu-info",
"memory": "/memory-info",
"disk": "/disk-info",
"network": "/network-info",
"load": "/load-info",
"health": "/health"
}
}

4. Run the server

go run main.go

📡 API Endpoints

EndpointDescription
/system-statsFull system stats: CPU, memory, disk, etc.
/cpu-infoCurrent CPU usage percentage.
/memory-infoRAM usage (total, used, percentage).
/disk-infoDisk usage (total, used, percentage).
/network-infoNetwork I/O statistics.
/load-infoSystem load averages (1, 5, 15 mins).
/healthService health: status, uptime, version, time

Example: Full Stats Output (/system-stats)

{
"cpu": {
"raw": [1.23],
"readable": ["1.23%"]
},
"memory": {
"total": 33554432000,
"total_readable": "31.25 GB",
"used": 2264924160,
"used_readable": "2.11 GB",
"used_percent": 6.76,
"used_percent_readable": "6.76%"
},
"disk": {
"total": 500107862016,
"total_readable": "465.66 GB",
"used": 200123435008,
"used_readable": "186.38 GB",
"used_percent": 40.02,
"used_percent_readable": "40.02%"
},
"network": [
{
"name": "eth0",
"bytes_sent": 123456789,
"bytes_sent_readable": "117.74 MB",
"bytes_recv": 987654321,
"bytes_recv_readable": "941.90 MB"
}
],
"system_load": {
"raw": {"load1": 0.12, "load5": 0.15, "load15": 0.18},
"readable": {"load1": "0.12", "load5": "0.15", "load15": "0.18"}
},
"updated_at": "2025-09-12T13:13:34Z"
}

About

Realtime Linux system metrics API in Go - CPU, RAM, Disk, Network & Load

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages