Guides

Monitor a VPS and its Docker containers without Prometheus

What to watch on a single server running Docker, how to read each number with tools already on Ubuntu, and how to keep the history without running Prometheus, exporters and Grafana.

Updated

A common way to monitor a server is Prometheus, with node_exporter for the host, cAdvisor for the containers and Grafana for the charts. That's four services to run, secure and upgrade. On one server, the questions are usually simpler: is the machine short of CPU, memory or disk, which container is using it, and since when?

This guide covers what to watch on a single Linux server running Docker, how to read each number with tools that are already there, and how to keep the history without running a monitoring stack.

What to watch

  • CPU and load. The load average counts tasks running or waiting. Compare it with the number of cores: a load of 4 on a 4-core server is busy, on a 16-core server it's quiet.
  • Memory. Watch available memory, not free memory. Linux fills spare memory with cache and gives it back when a process needs it.
  • Swap. Swap that's in use isn't a problem on its own. Pages moving in and out of it every second are.
  • Disk space and inodes. A full disk stops databases and Docker alike, and so does running out of inodes with space left.
  • Disk I/O. How busy each disk is, and how long requests wait for it.
  • Network. Traffic in and out per interface.
  • Each container. Its CPU and memory, against the limit it runs under, and whether the kernel has killed it for running out of memory.

Check it now with the tools on the server

The following commands work on a stock Ubuntu server. Run them over SSH.

CPU and load

nproc
uptime
vmstat 5 3

nproc prints the number of cores, and uptime ends with the load averages over 1, 5 and 15 minutes. In vmstat, ignore the first line, which averages everything since boot. Then read us and sy for CPU time spent in programs and the kernel, id for idle, and wa for time spent waiting on disks. A high wa means the disk, not the CPU, is the bottleneck.

Memory and swap

free -h

Read the available column: it's what new work can still use, cache included. In the vmstat output above, si and so show memory swapped in and out each second. Numbers that stay above zero mean the server needs more memory, or a process needs less.

Disks

df -h
df -i
sudo apt install sysstat
iostat -x 5 3

df -h shows space per filesystem and df -i shows inodes. iostat comes with the sysstat package. In its extended output, %util is how busy each disk was, and r_await and w_await are how long reads and writes waited, in milliseconds.

Network

ip -s link
sar -n DEV 5 3

ip -s link prints each interface's byte and packet counters since boot. sar, also from sysstat, turns them into a rate per second. Your public interface may be called eth0, ens3 or enp1s0, depending on the provider. Docker's bridges and veth interfaces carry container traffic that's already counted on the public one.

Containers

docker stats --no-stream
docker system df
docker inspect --format '{{.Name}} oom-killed={{.State.OOMKilled}}' $(docker ps -aq)

docker stats shows each container's CPU, memory, network and block I/O. Its CPU column counts one core as 100%, so a container on two busy cores shows 200%. Its memory column shows usage against the container's limit, or against the whole machine when there's no limit. docker system df shows the disk used by images, containers and volumes. The last command lists every container and whether the kernel killed it for running out of memory. journalctl -k | grep -i oom shows when.

What these commands don't give you

They all answer "what's happening now". The useful questions are usually about a stretch of time. Has memory crept up since Tuesday's deploy? When will the disk fill at this rate? Did the new version double the CPU?

To answer those, something has to read the numbers on a schedule and keep them. sysstat can record host history with sar once you enable its collector in /etc/default/sysstat, but it knows nothing about containers. Prometheus and its exporters keep everything, at the cost of running them.

How Echowa keeps the history

Echowa is a self-hosted deploy tool for one server, and it measures the machine it deploys to. There's nothing extra to install:

  • No agent, no exporter. Every 15 seconds, Echowa reads the host from the kernel's own counters and every container from Docker's stats API, inside its own process.
  • The host. CPU, load, memory, swap, space on every disk, disk I/O and network. It leaves out tmpfs and overlay mounts, partitions, Docker's bridges and veth interfaces, so the figures are the machine's own.
  • Each app. CPU and memory, summed across the app's containers, so a chart carries on across deploys. Running tasks are drawn as steps, so a rollout's overlap shows. An out-of-memory kill shows on the app's overview.
  • Each database. Connections, cache hits, commits and size every minute, and the slowest queries from the database's own statistics.
  • History. Each minute's readings are kept as an average and a maximum for 48 hours, hourly figures for 90 days and daily figures for a year, in a SQLite file of their own. Charts cover the last hour to the last 90 days.

We checked the figures against the machine's own tools: host CPU of 10.2% against vmstat's 10%, and a busy container's memory of 8.99 MiB against docker stats' 8.988 MiB. The collector costs about 0.09% of one CPU core, around 13ms a reading. With 10 containers running, Docker's daemon used another 0.22% of a core to answer the stats requests.

Echowa can alert, too. Add a provider in Settings, Notifications, such as Slack, Discord, Teams, ntfy or email, then the alerts you want: an app unhealthy, memory near its limit, a disk over a threshold. What it can't do is report its own server going down, since nothing on that server can, so pair it with an external uptime check for that.

To try it, install Echowa on a fresh Ubuntu or Debian server. The install guide covers the details, and Deploy a Docker image from GHCR to your own server walks through a first app.

curl -fsSL https://get.echowa.dev/install.sh | sudo bash

When Prometheus is the right tool

A monitoring stack earns its keep once you run several servers, need alert rules that page someone, want your app's own metrics next to the system's, or need to query months of data in detail. Echowa covers one server and the apps it deploys, and nothing beyond them.