Catalogue
Checking Docker Container Status with Mackerel

Checking Docker Container Status with Mackerel

🌐 日本語で読む

Overview

“My Docker container had silently Exited before I knew it!”
This is a Mackerel Agent configuration to prevent exactly that kind of situation.

Installing mackerel-plugin-docker-state

1
2
3
4
5
6
7
$ sudo mkdir -p /etc/mackerel-agent/conf.d
$ sudo curl https://raw.githubusercontent.com/ABCanG/mackerel-plugin-docker-state/master/mackerel-plugin-docker-state -o /etc/mackerel-agent/conf.d/mackerel-plugin-docker-state
$ sudo chmod +x /etc/mackerel-agent/conf.d/mackerel-plugin-docker-state
$ sudo cat <<'EOF'>/etc/mackerel-agent/conf.d/docker-state.conf
[plugin.metrics.docker-state]
command = "/etc/mackerel-agent/conf.d/mackerel-plugin-docker-state"
EOF

Adding the include setting to mackerel-agent.conf

  • /etc/mackerel-agent/mackerel-agent.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
pidfile = "/var/run/mackerel-agent.pid"
root = "/var/lib/mackerel-agent"
verbose = false
apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
diagnostic = true

roles = ["xxxxxxxx:xxx"]

# include conf.d/*.conf
include = "/etc/mackerel-agent/conf.d/*.conf"

...
...

Restarting the Mackerel Agent

1
$ sudo service mackerel-agent restart

Checking the graph

After a little while, the graph will appear.
Note: Since this is a graph with only 0 or 1 values, a stacked graph was easier to read.

Note: In the graph above, two containers are running.

Creating a new monitoring rule

Searching for “running” brings it up.

I set it up so that when the 3-minute average drops below 1,
the container is considered stopped (Exited) and a notification is sent.

Wrap-up

This time I happened to have the chance to work on a service that had Mackerel installed.

I was reminded once again that the benefit of using a managed service like Mackerel
is the reduced operational cost: you don’t have to monitor your monitoring server.

kenzo0107

kenzo0107