How to populate InfluxDB metrics using handlers

What are Sensu handlers?

Sensu event handlers are actions executed by the Sensu server on events.
In this example, we’ll use a handler to populate a time series database. If
you’re not totally comfortable with handlers yet, check out the in-depth
guide on handlers first!

Using a handler to populate InfluxDB

Registering the asset

Assets are shareable, reusable packages that make it easy to deploy Sensu plugins.
In this guide, we’ll use the Sensu InfluxDB handler asset to power an influx-db handler.

You can use the following sensuctl example to register the Sensu InfluxDB handler asset for Linux AMD64, or you can download the latest asset definition for your platform from Bonsai and register the asset using sensuctl create --file filename.yml.

Creating the handler

Now we’ll use sensuctl to create a handler called influx-db that pipes event data to InfluxDB using the sensu-influxdb-handler asset.
Edit the command below to include your database name, address, username, and password.
For more information about the Sensu InfluxDB handler, see the asset page in Bonsai.

Assigning the handler to an event

With the influx-db handler now created, it can be assigned to a check for
check output metric extraction. In this example, the check name is
collect-metrics:

sensuctl check set-output-metric-handlers collect-metrics influx-db

The handler can also be assigned to the Sensu StatsD listener at agent startup to pass
all StatsD metrics into InfluxDB:

sensu-agent start --statsd-event-handlers influx-db

Validating the handler

It might take a few moments once the handler is assigned to the check or StatsD
server, for Sensu to receive the metrics, but once an event is handled, you
should start to see your InfluxDB being populated! Otherwise, you can verify the
proper behavior of this handler by using sensu-backend logs.
See the troubleshooting guide for log locations by platform.

Whenever an event is being handled, a log entry is added with the message
"handler":"influx-db","level":"debug","msg":"sending event to handler",
followed by a second one with the message "msg":"pipelined executed event pipe
handler","output":"","status":0.

Next steps

You now know how to apply a handler to metrics and take action on events. From
this point, here are some recommended resources:

About Sensu

The Sensu monitoring event pipeline empowers businesses to automate their monitoring workflows and gain deep visibility into their multi-cloud infrastructure, from Kubernetes to bare metal. Companies like Sony, Box.com, and Activision rely on Sensu to help deliver value faster, at scale.