1 min read

Easily check Docker container resource usage via Kamal

Kamal 2 introduced the concept of aliases within your deploy recipe and it's lovely(thanks @djmb). Previously, I had various bin/kamal/console scripts and other variations sprinkled throughout my apps, now those can all be replaced with a few aliases.

As you're building out a new app with Kamal and trying to right-size(CPU, memory limits) the containers on a server, there's a helpful Docker command you can run to look at current utilization, docker stats --no-stream.

We can map this to a Kamal alias so that it's as simple as running kamal stats and we'll get a simple report back with CPU, memory, network, and pids usage.

aliases:
  stats: server exec "docker stats --no-stream"

With that in place, we can fetch stats from our server(s) by running kamal stats which gives us a report that looks something like this:

From there, you tweak your CPU/memory as needed within your accessories/roles via:

servers:
  web:
    options:
      cpus: 0.5
      memory: 750mb