Last active
September 1, 2015 22:51
-
-
Save nathwill/c96df7e2236dafaffd2a to your computer and use it in GitHub Desktop.
heka memcached stats decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
nathwill
commented
Sep 1, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment