Sends host and container CPU, memory and disk usage to Seq every minute
450
Docker container that sends the host's CPU, load, memory and disk usage to Seq as a structured event every minute, so you can chart the trend in a Seq dashboard. Optionally it also sends CPU, memory and disk usage per running container.
This project uses:
curl and jq/proc/stat and /proc/meminfo inside a container report the host's values, so no privileged mode is needed. The host root filesystem is mounted read-only on /host for the disk figures.
Container figures come from the Docker API. Instead of mounting /var/run/docker.sock into this container (which gives root-equivalent access to the host), compose.yaml runs a socket proxy on an internal network that only allows reading container info and stats.
docker build -t <dockerhub-user>/server-metrics:latest .
or
docker pull <dockerhub-user>/server-metrics:latest
docker run -d --name server-metrics --restart unless-stopped \
--network logging \
-v /:/host:ro \
-e HOST_NAME=docker-server \
-e SEQ_URL=http://seq:5341 \
-e SEQ_API_KEY=myapikey \
<dockerhub-user>/server-metrics:latest
For container metrics, use the Portainer stack below (it adds the socket proxy) or set DOCKER_URL to a socket proxy with CONTAINERS=1 that this container can reach.
Use compose.yaml: Stacks → Add stack → paste it (or point to this repository) and set SEQ_API_KEY under Environment variables.
| Variable | Default | Description |
|---|---|---|
HOST_NAME | container hostname | Value of the Host property in Seq |
SEQ_URL | http://seq:5341 | Seq ingestion URL |
SEQ_API_KEY | (empty) | Seq API key; omitted when empty |
INTERVAL | 60 | Seconds between measurements |
WARN_PERCENT | 90 | Event level becomes Warning when CPU, memory or disk usage exceeds this |
DISK_PATH | /host | Path whose filesystem is measured |
DOCKER_URL | (empty) | Docker API (socket proxy) URL, e.g. http://docker-proxy:2375; container metrics are off when empty |
Every host event has Application = 'server-metrics' and these properties:
| Property | Description |
|---|---|
CpuPercent | Average CPU usage (all cores) since the previous measurement |
CpuCores, CpuUsedCores | Number of cores (capacity) and cores in use |
Load1, Load5, Load15 | Load average |
MemUsedPercent, MemUsedMB, MemTotalMB | Memory used, excluding page cache |
DiskUsedPercent, DiskUsedGB, DiskFreeGB, DiskTotalGB | Filesystem of DISK_PATH |
With DOCKER_URL set, every running container gets an event with Application = 'container-metrics', the same Host and these properties:
| Property | Description |
|---|---|
Container, Image, ComposeProject | Container name, image and compose/stack project (when set) |
CpuPercent, CpuUsedCores | CPU usage as a share of all host cores (like the host CpuPercent) and cores in use, over about one second |
MemUsedMB, MemLimitMB, MemUsedPercent | Memory used excluding page cache (as docker stats), and the container limit (host memory when unlimited) |
DiskUsedMB | Size of the container's writable layer; volumes and the image are not included |
The level is Warning when CpuPercent or MemUsedPercent exceeds WARN_PERCENT.
select mean(CpuPercent) as CPU, mean(MemUsedPercent) as Memory from stream where Application = 'server-metrics' group by time(5m)
select min(DiskFreeGB) as DiskFree from stream where Application = 'server-metrics' group by time(1h)
select mean(CpuPercent) as CPU from stream where Application = 'container-metrics' group by Container, time(5m)
select mean(MemUsedMB) as Memory from stream where Application = 'container-metrics' group by Container, time(5m)
seq-container-dashboards.sh creates a Seq dashboard named Container - <name> for every running container, copying the charts of the server metrics dashboard. Re-run it after adding containers; existing dashboards are updated, not duplicated. It needs a Seq API key with the Setup permission in a file on the server and runs inside the server-metrics container:
ssh [email protected] 'docker cp ~/.seq-dashboard-key server-metrics:/tmp/seq.key &&
docker exec -i -e SEQ_ADMIN_KEY_FILE=/tmp/seq.key server-metrics sh -s;
docker exec server-metrics rm -f /tmp/seq.key' < seq-container-dashboards.sh
Add -e DRY_RUN=1 to only print what would be created, or -e EXCLUDE="docker-proxy server-metrics" to skip containers.
GitHub Actions (docker-publish.yml) builds for linux/amd64, linux/arm64 and linux/arm/v7 and pushes to Docker Hub on every push to main, on v*.*.* tags and weekly. Set the repository secrets DOCKERHUB_USERNAME and DOCKERHUB_TOKEN.
Content type
Image
Digest
sha256:1f4203d9d…
Size
6.4 MB
Last updated
3 days ago
docker pull 301167/server-metrics