Plup
Plup

Reputation: 1242

Configure Sensu to send metrics in Influxdb

I'm trying to send metrics to influxdb in UDP with sensu.

I set my influxdb database :

# echo "cpu value=1" | nc -C -w 1 -u localhost 8089
# echo "select * from cpu" | influx -database sensu
name: cpu
time                value
1490898218118704438 1

I installed the plugin from the repository (https://github.com/sensu-plugins/sensu-plugins-influxdb) :

# sensu-install -p influxdb
# cp /opt/sensu/embedded/bin/mutator-influxdb-line-protocol.rb /etc/sensu/extensions/

Configured the handler according to the doc :

{
"handlers": {
  "influxdb": {
    "type": "udp",
    "socket": {
      "host": "localhost",
      "port": 8089
    },
    "mutator": "influxdb_line_protocol"
  }
  }

And configured a check to use this handler :

{
"checks": {
  "cpu-metrics": {
    "command": "/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb",
    "handlers": [
      "influxdb"
    ],
    "interval": 60,
    "subscribers": [
      "production"
    ],
    "type": "metric",
    "standalone": false
  }
}
}

Now when I restart my sensu-server I can see the extension loaded :

{"timestamp":"2017-03-30T19:53:05.083622+0000","level":"warn","message":"loaded extension","type":"mutator","name":"influxdb_line_protocol","description":"returns check output formatted for InfluxDB's line protocol"}

And I can see the metrics collected on the client side :

{"timestamp":"2017-03-30T20:08:49.940732+0000","level":"info","message":"received check request","check":{"command":"/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb","handlers":["influxdb"],"type":"metric","standalone":false,"name":"cpu-metrics","issued":1490904529}} {"timestamp":"2017-03-30T20:08:51.150984+0000","level":"info","message":"publishing check result","payload":{"client":"nott","check":{"command":"/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb","handlers":["metrics"],"type":"metric","standalone":false,"name":"cpu-metrics","issued":1490904529,"interval":60,"subscribers":["production"],"executed":1490904529,"duration":1.21,"output":"nott.cpu.user 0.25 1490904531\nnott.cpu.nice 0.00 1490904531\nnott.cpu.system 0.00 1490904531\nnott.cpu.idle 99.25 1490904531\nnott.cpu.iowait 0.00 1490904531\nnott.cpu.irq 0.00 1490904531\nnott.cpu.softirq 0.00 1490904531\nnott.cpu.steal 0.50 1490904531\nnott.cpu.guest 0.00 1490904531\n","status":0}}}

But I still have nothing more in my influxdb database.

influx -database sensu
Connected to http://localhost:8086 version 1.2.1
InfluxDB shell version: 1.2.1
> show measurements;
name: measurements
name
----
cpu

Any insights ?

UPDATE: As requested in comment here is my influxdb UDP config :

[[udp]]
  enabled = true
  bind-address = "127.0.0.1:8089"
  database = "sensu"
  retention-policy = ""
  batch-size = 5000
  batch-pending = 10
  batch-timeout = "1s"
  read-buffer = 0

UPDATE 2: If I add the debug handler I can see the result of the metric check in the server logs:

{"timestamp":"2017-04-15T13:05:46.047354+0000","level":"info","message":"handler extension output","extension":{"type":"extension","name":"debug"},"event":{"id":"1303c9d3-096c-4744-9fdc-9566c831270c"},"output":"{\"client\":{\"name\":\"nott\",\"address\":\"127.0.0.1\",\"environment\":\"production\",\"subscriptions\":[\"certs\",\"production\",\"client:nott\"],\"socket\":{\"bind\":\"127.0.0.1\",\"port\":3030},\"version\":\"0.28.2\",\"timestamp\":1492261543},\"check\":{\"command\":\"/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb\",\"handlers\":[\"metrics\"],\"interval\":60,\"subscribers\":[\"production\"],\"type\":\"metric\",\"standalone\":true,\"name\":\"cpu-metrics\",\"issued\":1492261544,\"executed\":1492261544,\"duration\":1.205,\"output\":\"nott.cpu.user 0.75 1492261546\nnott.cpu.nice 0.00 1492261546\nnott.cpu.system 0.00 1492261546\nnott.cpu.idle 99.00 1492261546\nnott.cpu.iowait 0.00 1492261546\nnott.cpu.irq 0.00 1492261546\nnott.cpu.softirq 0.00 1492261546\nnott.cpu.steal 0.25 1492261546\nnott.cpu.guest 0.00 1492261546\n\",\"status\":0,\"history\":[\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"],\"total_state_change\":0},\"occurrences\":1,\"occurrences_watermark\":1,\"action\":\"create\",\"timestamp\":1492261546,\"id\":\"1303c9d3-096c-4744-9fdc-9566c831270c\",\"last_ok\":1492261546,\"silenced\":false,\"silenced_by\":[]}","status":0}

But I see nothing no exchanges on the porr 8089 on the loopback.

Upvotes: 0

Views: 1143

Answers (1)

teknoboy
teknoboy

Reputation: 175

I had the same problem. It was solved after adding the line precision = "s" to the UDP block in the influxdb.conf file.

Upvotes: 1

Related Questions