【发布时间】:2017-03-30 20:14:55
【问题描述】:
我正在尝试使用 sensu 将指标发送到 UDP 中的 influxdb。
我设置了我的 influxdb 数据库:
# echo "cpu value=1" | nc -C -w 1 -u localhost 8089
# echo "select * from cpu" | influx -database sensu
name: cpu
time value
1490898218118704438 1
我从存储库 (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/
根据文档配置处理程序:
{
"handlers": {
"influxdb": {
"type": "udp",
"socket": {
"host": "localhost",
"port": 8089
},
"mutator": "influxdb_line_protocol"
}
}
并配置检查以使用此处理程序:
{
"checks": {
"cpu-metrics": {
"command": "/opt/sensu/embedded/bin/metrics-cpu-pcnt-usage.rb",
"handlers": [
"influxdb"
],
"interval": 60,
"subscribers": [
"production"
],
"type": "metric",
"standalone": false
}
}
}
现在当我重新启动我的sensu-server 时,我可以看到加载的扩展:
{"timestamp":"2017-03-30T19:53:05.083622+0000","level":"warn","message":"加载的扩展","type":"mutator","name" :"influxdb_line_protocol","description":"返回为 InfluxDB 的线路协议格式化的检查输出"}
我可以看到在客户端收集的指标:
{"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","已发布":1490904529}} {"timestamp":"2017-03-30T20:08:51.150984+0000","level":"info","message":"发布检查结果","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 “:”nnott.cpu.system 0.00 1490904531 \ nnott.cpu.iowait 0.001490904531 \ nnott.cpu.iowait 0.00 1490904531 \nnott.cpu.softirq 0.00 1490904531\nnott.cpu.steal 0.50 1490904531\nnott.cpu.guest 0.00 1490904531\n","status":0}}}
但我的 influxdb 数据库中仍然没有更多内容。
influx -database sensu
Connected to http://localhost:8086 version 1.2.1
InfluxDB shell version: 1.2.1
> show measurements;
name: measurements
name
----
cpu
有什么见解吗?
更新:根据评论中的要求,这里是我的 influxdb UDP 配置:
[[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
更新 2:如果我添加调试处理程序,我可以在服务器日志中看到指标检查的结果:
{"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 149226154.cpu. 1492261546\nnott.cpu.softirq 0.00 1492261546\nnott.cpu.steal 0.2 5 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\":[]}","状态”:0}
但我在环回的 porr 8089 上看不到任何交换。
【问题讨论】:
-
您是否启用并配置了 InfluxDB 配置文件的 UDP 部分?
-
我更新了配置,但是当我这样做
echo "cpu value=1" | nc -C -w 1 -u localhost 8089时,我实际上在正确端口的数据库中注入了UDP中的数据。所以 influxdb 有效。