Technical Blog

Monitoring OpenStack with Zabbix

I use Zabbix to monitor OpenStack, and this is roughly how I set it up.

Why Zabbix?#

Of the usual options, it's the one I like best, mostly because it's easy to get started with and easy to scale. You can have a full deployment, with the server, database, proxies and agents, up in about a day. The stock templates cover the basic OS metrics, and triggers can look at several metrics at once, so you can combine CPU, memory and Nova API response time to decide whether a node is healthy.

It's agent-based, and agents can register themselves. Start an agent on a new hypervisor and an auto-registration rule can add the host, link the right templates and start monitoring it without anyone touching the UI. Proxies let you reach networks the server can't reach, which is the main reason it works so well for multi-region clouds. For the database you can use MySQL/MariaDB or PostgreSQL. Oracle used to be supported, but not anymore.

Architecture#

Zabbix architecture: a Zabbix server with its database at the top, three Zabbix proxies below it, and a group of Zabbix agents reporting to each proxy
Server and database at the top, a proxy per region, agents reporting to their local proxy.

The setup is simple. The Zabbix server holds the configuration, evaluates the triggers and writes everything to its database. Proxies sit in each region or data center, collect data from the agents near them and forward it to the server. Agents run on every host and are fairly lightweight. Monitoring always has some overhead, but you won't notice it.

The proxies are what make it work across regions. A remote region only has to allow one connection, from its proxy to the server, instead of opening its whole network to your monitoring. You can put a proxy in front of AWS or GCP too, and then everything ends up in one place.

The shortest collection interval is one second, so don't expect millisecond resolution. For most checks a minute is fine anyway. Agents can run in passive mode, where the server or proxy connects and asks for each value, or in active mode, where the agent fetches its list of checks and pushes the values itself. Active mode scales better and works through firewalls and NAT, since only the agent opens connections. This is an agent on a hypervisor in a remote region, using active checks through the local proxy:

# /etc/zabbix/zabbix_agent2.conf  (Zabbix config files only allow whole-line comments)
# the proxy that's allowed to poll this agent
Server=zabbix-proxy.region2.example.com
# where to get active checks from and send data to
ServerActive=zabbix-proxy.region2.example.com
Hostname=compute-r2-017
# matched by the auto-registration action
HostMetadata=openstack compute

Items, triggers and events#

Most of Zabbix comes down to these three. An item is a metric, something you want to measure and keep, like CPU, memory or a service's response time. A trigger is an expression that looks at item data and decides whether things are OK or a problem. An event is created when something happens, like a trigger changing state, and events can run actions such as sending an alert, opening a ticket or running a script.

Zabbix item configuration form: name, type Zabbix agent, key, type of information, update interval 1m, custom intervals, history storage period 90d and trend storage period 365d
An item: what to collect, how often, and how long to keep it.

An item has a type (Zabbix agent, HTTP agent, SNMP, IPMI and so on), a key that says what to collect, and an update interval. For timing the OpenStack APIs, web scenarios are useful, because they record the response time of each step as an item. Then there's history and trends. History keeps the raw values (90 days in the screenshot), and trends keep hourly min/avg/max values for much longer (365 days here). Don't keep raw history forever. The Zabbix database grows really fast, and it can reach 60 to 70 GB even for fairly small environments.

Zabbix trigger configuration form: name, severity, expression, OK event generation (Expression, Recovery expression or None), PROBLEM event generation mode and OK event closes settings
A trigger, with the OK event generation setting.

Say the item is the Nova API response time, and anything over 10 seconds is a problem. By default the trigger goes back to OK as soon as the expression is false, which can make alerts flap. If you set OK event generation to "Recovery expression", you can ask for something stricter before the problem counts as fixed, like the response time staying under 3 seconds for ten minutes and a test VM having booted since:

# problem
avg(/OpenStack Control Plane/nova.api.response_time,5m)>10

# recovery
max(/OpenStack Control Plane/nova.api.response_time,10m)<3 and last(/OpenStack Control Plane/nova.canary.boot)=1

The item keys there are made up. The response time would come from a web scenario step against the Nova endpoint, and nova.canary.boot from a script that boots a tiny VM and deletes it again.

Templates and hosts#

Zabbix template configuration form for a template named Openstack, with tabs for items, triggers, graphs, dashboards, discovery rules and web scenarios
A template called “Openstack”, with its items, triggers and graphs in the tabs along the top.

A template bundles items, triggers, graphs, dashboards and discovery rules, and you can apply it to as many hosts as you want. The one above is an Openstack template for the checks from part 2. Link it to a host and the host gets all of them, and when you change the template, every linked host gets the change. I usually layer them, with a base OS template and then one per role (controller, compute, network, storage).

Zabbix new host form: host name, visible name, templates, groups, interfaces, description, monitored by proxy and enabled
Adding a host: name, templates, groups, interfaces and which proxy watches it.

Adding a host by hand is easy. You give it a name, templates and groups, the interfaces to reach it on (agent, SNMP, or IPMI for the BMC), and the proxy that monitors it. In a cloud you shouldn't be adding hosts by hand, though. Set up an auto-registration action, and any agent that connects with HostMetadata=openstack compute gets created, put in the right group and linked to the compute template. If you hook that into however you provision hypervisors, new capacity is monitored from the first minute.

Happy monitoring!