Unifi Controller (Follow up: monitoring with Digital Ocean)

tl;dr The code for the complete Unifi setup is available in the niels-s/unifi-terraform-example repo

After setting up my droplet and keeping an eye on it, I noticed DigitalOcean offers some more “enhanced” monitoring. Unfortunately, we don’t get that functionality straight out of the box because we use a CoreOS image 😅. So we have to do a little more work than with other distros.

Setting up the DigitalOcean client is straight forward since DO already provides a Docker image. We can practically do the same as we did before and add another systemd service to run the DO agent.

data "ignition_config" "unifi_controller" {
  ...

  systemd = [
    ...
    data.ignition_systemd_unit.do_agent_unit.rendered
  ]
}

// DigitalOcean Metric Agent
data "ignition_systemd_unit" "do_agent_unit" {
  name    = "do-agent.service"
  enabled = true

  content = <<-CONFIG
    [Unit]
    Description=The DigitalOcean Monitoring Agent
    Requires=docker.service
    After=docker.service
    After=network-online.target
    Wants=network-online.target

    [Service]
    Restart=always
    ExecStartPre=/usr/bin/docker pull digitalocean/do-agent:stable
    ExecStartPre=-/usr/bin/docker stop do-agent
    ExecStartPre=-/usr/bin/docker rm do-agent
    ExecStart=/usr/bin/docker run \
        --name do-agent \
        --restart=no \
        -v /proc:/host/proc:ro \
        -v /sys:/host/sys:ro \
        digitalocean/do-agent:stable

    [Install]
    WantedBy=multi-user.target
  CONFIG
}

Alerts

At the time of writing, the Digital Ocean Terraform provider doesn’t implement setting up alerts, so you will need to visit the DO Dashboard, so configure some rules yourself.

Example to configure a new alert

Configure New Alert

I was hoping I could also monitor the extra block volume I’ve attached, but unfortunately, the DO agent doesn’t recognize/monitor that volume at the moment. I will need to spend some more time looking into it perhaps it’s configurable 🤞

The code for the complete Unifi setup is available in the niels-s/unifi-terraform-example repo , the changes of this post can be found in this commit