Skip to content

Instantly share code, notes, and snippets.

@nathwill
Created July 22, 2015 00:20
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/300939a73e0f0346f898 to your computer and use it in GitHub Desktop.
Save nathwill/300939a73e0f0346f898 to your computer and use it in GitHub Desktop.
heka nginx_stub_status decoder
-- 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
@nathwill
Copy link
Author

nginx_stub_status_input.toml:

[nginx_stub_status_input]
type = "HttpInput"
url = "http://localhost:8090/nginx_status"
ticker_interval = 1
success_severity = 6
error_severity = 1
decoder = "nginx_stub_status_decoder"

nginx_stub_status_decoder.toml:

[root@app01.stage heka]# cat nginx_stub_status_decoder.toml 
[nginx_stub_status_decoder]
filename = "lua_decoders/nginx_stub_status.lua"
type = "SandboxDecoder"

[nginx_stub_status_decoder.config]
payload_keep = false

@nathwill
Copy link
Author

working on upstreaming: mozilla-services/heka#1636

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