Pages

Tuesday, November 26, 2013

Combine metrics and zabbix

Metrics is a Java library to measure code speed, counting calls etc. The Metrics Library provides connectors for different Monitoring and Graphing systems like Graphite and Ganglia.

Because we use Zabbix as our primary monitoring system we've had the use case to connect Metrics with Zabbix.

After a short research i've found a library callend Zabbix/j which connectes active or passive from java source to a Zabbix server.

Based on this library i've implemented this small code to provide an adapter between Metrics an Zabbix. Which is available on GitHub https://github.com/janramm87/metrics-zabbix

Integration Pattern

Metrics provides a so called "MetricRegistry" where a listener can be added. This listener will be fired when a metric is added or removed.
This is the perfect integration point for my implementation, because i need to addMetricProvider to the Zabbix/j framework.

Configuration

The ZabbixMetricsAgent needs to be initialized with the MetricsRegistry and the ZabbixAgent.
Everytime a new Metric ist registered with the MetricsRegistry this measure will be available for Zabbix.

My base configuration was working with an active Zabbix agent configuration, which let the Application push information to the Zabbix Server.

Example Scenario:

On a service A which is named in Zabbix as "service-a.janramm.com" we want to measure the requests per minute.
In order to archieve this, we need to add a meter-metric to our java code which will be called on every request.

private final Meter requests = metrics.meter("requests");

public void handleRequest(Request request, Response response) {
    requests.mark();
    // etc
}

In addition to that we need to configure Zabbix to do the check. I assume that the host service-a.janramm.com is already monitored via zabbix.

We need to add an item with the following configuration:
  • type: Zabbix Agent (active)
  • key: requests.ONE_MINUTE_RATE


No comments:

Post a Comment