2015-08-21 115 views
0

我有這個問題,其中sensu截斷輸出字符串的長度約260個字符。我搜索了一段時間,但找不到原因。Sensu截斷輸出字符串

如果我將結果輸出到sensu-client.log,則輸出字符串不會被截斷。但是當我檢查內部redis時,它被截斷。

下面是輸出JSON從意義上的API /結果:

[{"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}}] 

我environtment如下:

  • Centos的5.3
  • 扇子0.20
  • Redis的2.4.10
  • RabbitMQ 3.5.3

回答

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