An experimental API for gathering Linux server / Docker Engine metrics.
This will be used in coolify.io.
- Real-time system metrics collection (CPU, Memory)
- Docker container metrics tracking
- Historical metrics storage with SQLite
- REST API for querying metrics
- Configurable data retention
- Push metrics to external endpoints
- Debug and profiling endpoints
- Go 1.21 or higher (for development)
- Docker (for container metrics)
- Linux environment (production deployment)
docker run -d \
-p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock \
-e TOKEN=your-secret-token \
-e PUSH_ENDPOINT=https://your-endpoint.com/metrics \
ghcr.io/coollabsio/sentinel:latest# Clone the repository
git clone https://github.com/coollabsio/sentinel.git
cd sentinel
# Install dependencies
go mod download
# Run the application
TOKEN=your-secret-token go run main.go# Install Air if not already installed
go install github.com/cosmtrek/air@latest
# Run with hot reload
airSentinel is configured using environment variables:
| Variable | Description | Example |
|---|---|---|
TOKEN |
Authentication token for API access | your-secret-token |
| Variable | Default | Description |
|---|---|---|
PUSH_ENDPOINT |
- | URL to push metrics to |
PUSH_INTERVAL_SECONDS |
60 | Interval for pushing metrics |
COLLECTOR_ENABLED |
true |
Enable/disable metrics collection |
COLLECTOR_REFRESH_RATE_SECONDS |
10 | Metrics collection interval |
COLLECTOR_RETENTION_PERIOD_DAYS |
7 | How long to keep metrics in database |
DEBUG |
false |
Enable debug mode and profiling endpoints |
PORT |
8080 |
HTTP server port |
export TOKEN=your-secret-token
export PUSH_ENDPOINT=https://coolify.io/api/metrics
export COLLECTOR_REFRESH_RATE_SECONDS=30
export COLLECTOR_RETENTION_PERIOD_DAYS=14
export DEBUG=false
./sentinelSentinel provides a comprehensive REST API for retrieving system and Docker container metrics.
GET /api/health- Health checkGET /api/version- Get service versionGET /api/cpu/current- Current CPU usageGET /api/cpu/history- Historical CPU dataGET /api/memory/current- Current memory usageGET /api/memory/history- Historical memory dataGET /api/container/:id/cpu/history- Container CPU historyGET /api/container/:id/memory/history- Container memory history
All API requests require a Bearer token:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8080/api/cpu/currentFor detailed API documentation including request/response examples, query parameters, and error responses, see API.md.
An OpenAPI 3.0 specification is available at openapi.yaml for use with Swagger UI and other API tools.
Sentinel follows a service-oriented architecture with these components:
- API Server (
pkg/api/) - Gin-based HTTP server exposing metrics endpoints - Collector Service (
pkg/collector/) - Periodically collects system and Docker metrics - Push Service (
pkg/push/) - Sends metrics to external endpoints - Database Layer (
pkg/db/) - SQLite storage with automatic cleanup
Docker Engine ──┐
├──> Collector Service ──> SQLite Database ──> API Server ──> Clients
System Stats ───┘ │
└──> Push Service ──> External Endpoint
sentinel/
├── cmd/ # Application entry points
├── pkg/
│ ├── api/ # HTTP API and controllers
│ ├── collector/ # Metrics collection service
│ ├── push/ # Push service
│ ├── db/ # Database layer
│ └── config/ # Configuration management
├── main.go # Application main
├── go.mod # Go dependencies
├── Dockerfile # Docker build configuration
├── API.md # API documentation
└── openapi.yaml # OpenAPI specification
# Build binary
go build -o sentinel .
# Build Docker image
docker build -t sentinel .
# Run tests
go test ./...
# Format code
go fmt ./...
# Run linter
golangci-lint runKey dependencies used in the project:
- gin-gonic/gin: HTTP web framework
- docker/docker: Docker API client
- shirou/gopsutil: System metrics collection
- mattn/go-sqlite3: SQLite database driver
- golang.org/x/sync/errgroup: Concurrent service management
version: '3.8'
services:
sentinel:
image: ghcr.io/coollabsio/sentinel:latest
ports:
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- sentinel-data:/data
environment:
TOKEN: ${SENTINEL_TOKEN}
PUSH_ENDPOINT: ${PUSH_ENDPOINT}
COLLECTOR_REFRESH_RATE_SECONDS: 30
COLLECTOR_RETENTION_PERIOD_DAYS: 14
restart: unless-stopped
volumes:
sentinel-data:[Unit]
Description=Sentinel Metrics Service
After=network.target docker.service
Requires=docker.service
[Service]
Type=simple
User=sentinel
Environment="TOKEN=your-secret-token"
Environment="PUSH_ENDPOINT=https://your-endpoint.com/metrics"
ExecStart=/usr/local/bin/sentinel
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetcurl http://localhost:8080/api/healthWhen DEBUG=true, access database statistics:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8080/api/statsGo profiling endpoints are available at /debug/pprof/* when debug mode is enabled.
This is an experimental project for Coolify.io. Contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
See LICENSE file for details.
For issues and questions:
- GitHub Issues: https://github.com/coollabsio/sentinel/issues
- Coolify Discord: https://discord.gg/coolify