Skip to content

Instantly share code, notes, and snippets.

@nathwill
Last active September 1, 2015 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathwill/c96df7e2236dafaffd2a to your computer and use it in GitHub Desktop.
Save nathwill/c96df7e2236dafaffd2a to your computer and use it in GitHub Desktop.
heka memcached stats decoder
local l = require 'lpeg'
l.locale(l)
local sp = l.space^1
local unreserved = l.alnum + l.S"/=-.,_~"
local name = l.C(unreserved^1)
local prefix = l.P"STAT "
local pair = prefix^-1 * l.Cg(name * sp * name) * sp
local grammar = l.Cf(l.Ct("") * pair^0, rawset)
local msg = {
Type = read_config('type') or 'mcstats',
Payload = nil,
Fields = nil
}
function process_message()
local data = read_message("Payload")
msg.Fields = grammar:match(data)
if not msg.Fields then return -1 end
-- del non-numeric fields
msg.Fields.version = nil
msg.Fields.libevent = nil
-- numericize
for k, v in pairs(msg.Fields) do
msg.Fields[k] = tonumber(v)
end
inject_message(msg)
return 0
end
@nathwill
Copy link
Author

nathwill commented Sep 1, 2015

[memcached_stats]
type = "ProcessInput"
ticker_interval = 5
stdout = true
stderr = false
decoder = "memcached_stats_decoder"

  [mecached_stats.command.0]
  bin = "/usr/bin/echo"
  args = ["stats"]

  [memcached_stats.command.1]
  bin = "/usr/bin/nc"
  args = ["127.0.0.1", "11211"]

[memcached_stats_decoder]
type = "SandboxDecoder"
filename = "lua_decoders/memcached_stats.lua"

[RstEncoder]

[LogOutput]
message_matcher = "TRUE"
encoder = "RstEncoder"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment