Created
July 22, 2015 00:20
-
-
Save nathwill/300939a73e0f0346f898 to your computer and use it in GitHub Desktop.
heka nginx_stub_status 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
-- This Source Code Form is subject to the terms of the Mozilla Public | |
-- License, v. 2.0. If a copy of the MPL was not distributed with this | |
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
--[[ | |
--]] | |
local l = require 'lpeg' | |
l.locale(l) | |
local sp = l.S(' \n\t')^0 | |
local num = l.digit^1 | |
local headings = l.P'server accepts handled requests' | |
function column(tag) | |
return sp * l.Cg(num / tonumber, tag) | |
end | |
local act_conn = l.P'Active connections:' * column('connections') | |
local reading = sp * l.P'Reading:' * column('reading') | |
local writing = sp * l.P'Writing:' * column('writing') | |
local waiting = sp * l.P'Waiting:' * column('waiting') | |
local fmt = act_conn * sp * headings * column('accepts') * column('handled') * | |
column('requests') * reading * writing * waiting | |
local grammar = l.Ct(fmt) | |
local payload_keep = read_config("payload_keep") | |
local msg = { | |
Type = 'nginx_stub_status', | |
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 | |
if payload_keep then | |
msg.Payload = data | |
end | |
msg.Fields.StatusCode = read_message("Fields[StatusCode]") | |
inject_message(msg) | |
return 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nginx_stub_status_input.toml:
nginx_stub_status_decoder.toml: