我有一个问题,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}}]

我的声明如下:
半人马座5.3
传感器0.20
Redis 2.4.10版
拉比特MQ 3.5.3

最佳答案

我找到了答案。罪魁祸首在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

关于redis - Sensu截断输出字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32136041/

10-11 06:36