0

我有这个问题,其中 sensu 将输出字符串截断为大约 260 个字符的长度。我已经搜索了很长时间,但找不到导致此问题的原因。

如果我将结果输出到 sensu-client.log,则输出字符串不会被截断。但是当我检查redis内部时,它被截断了。

这是 sensu-api /results 的输出 JSON:

[{"client":"test","check":{"command":"/etc/sensu/plugins/load-metrics.rb -s load","interval":120,"standalone":true,"name":"load-metrics","issued":1440145476,"executed":1440145476,"duration":0.117,"output":"load.load_avg.one 0.04 1440145476\nload.load_avg.five 0.01 1440145476\nload.load_avg.fifteen 0.00 1440145476\n\n","status":0}},{"client":"test","check":{"command":"/etc/sensu/plugins/memory-metrics.rb -s memory","interval":120,"standalone":true,"name":"memory-metrcis","issued":1440145481,"executed":1440145481,"duration":0.105,"output":"memory.total 1050628096 1440145481\nmemory.free 93421568 1440145481\nmemory.buffers 53370880 1440145481\nmemory.cached 482304000 1440145481\nmemory.swapTotal 2113921024 1440145481\nmemory.swapFree 2113921024 1440145481\nmemory.dirty 204800 1440145481\nmemory.swapU","status":0}},{"client":"test","check":{"command":"/etc/sensu/plugins/interface-metrics.rb -s interface","interval":120,"standalone":true,"name":"interface-metrics","issued":1440145496,"executed":1440145496,"duration":0.103,"output":"interface.lo.rxBytes 17062685 1440145496\ninterface.lo.rxPackets 80712 1440145496\ninterface.lo.rxErrors 0 1440145496\ninterface.lo.rxDrops 0 1440145496\ninterface.lo.rxFifo 0 1440145496\ninterface.lo.rxFrame 0 1440145496\ninterface.lo.rxCompressed 0 1440145496\ni","status":0}},{"client":"test","check":{"thresholds":{"warning":120,"critical":180},"name":"keepalive","issued":1440145470,"executed":1440145470,"output":"Keepalive sent from client 19 seconds ago","status":0}},{"client":"test","check":{"command":"/etc/sensu/plugins/disk-metrics.rb -s disk","interval":120,"standalone":true,"name":"disk-metrics","issued":1440145470,"executed":1440145470,"duration":0.098,"output":"disk.sda.reads 20589 1440145470\ndisk.sda.readsMerged 14159 1440145470\ndisk.sda.sectorsRead 971661 1440145470\ndisk.sda.readTime 234278 1440145470\ndisk.sda.writes 29582 1440145470\ndisk.sda.writesMerged 107721 1440145470\ndisk.sda.sectorsWritten 1098420 1440145","status":0}}]

我的环境如下:

  • Centos 5.3
  • 森苏 0.20
  • Redis 2.4.10
  • 兔MQ 3.5.3
4

1 回答 1

0

我找到了答案。罪魁祸首在sensu的源代码中:lib/sensu/server/process.rb

 def store_check_result(client, check, &callback)
    @logger.debug("storing check result", :check => check)
    @redis.sadd("result:#{client[:name]}", check[:name])
    result_key = "#{client[:name]}:#{check[:name]}"
    check_truncated = check.merge(:output => check[:output][0..256]) <-- THIS LINE
    @redis.set("result:#{result_key}", MultiJson.dump(check_truncated)) do
      history_key = "history:#{result_key}"
      @redis.rpush(history_key, check[:status]) do
        @redis.ltrim(history_key, -21, -1)
        callback.call
      end
    end
  end
于 2015-08-21T12:39:31.730 回答