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
Installing the handler command
The first thing you’ll want to do is create an executable script named
sensu-influxdb-handler, which will be responsible for populating a configurable
InfluxDB with Sensu metrics. The source code and installation instructions of
this script is available on GitHub. You can also download the binaries
directly from releases.
Creating the handler
Now that our handler command is installed, the second step is to create a
handler that we will call
influx-db, which is a pipe handler that pipes
event data into our previous script named
sensu-influxdb-handler. We will also
pass the database name, address, username, and password of the InfluxDB you wish
sensuctl handler create influx-db \ --type pipe \ --command "sensu-influxdb-handler \ --addr 'http://22.214.171.124:8086' \ --db-name 'myDB' \ --username 'foo' \ --password 'bar'"
Assigning the handler to an event
influx-db handler now created, it can be assigned to a check for
check output metric extraction. In this example, the check name is
sensuctl check set-output-metric-handlers collect-metrics influx-db
And/or, the handler can be assigned to the Sensu StatsD Listener to pass all StatsD metrics into InfluxDB:
sensu-agent --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. The default
location of these logs varies based on the platform used, but the
installation and configuration documentation provides this information.
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
You now know how to apply a handler to metrics and take action on events. From this point, here are some recommended resources: