Skip to content

Instantly share code, notes, and snippets.

@rafrombrc
Last active August 29, 2015 14:06
Show Gist options
  • Save rafrombrc/8d7b5713a694b7f8ca11 to your computer and use it in GitHub Desktop.
Save rafrombrc/8d7b5713a694b7f8ca11 to your computer and use it in GitHub Desktop.
require "cjson"
local fields = {
values = {},
interval = 0,
plugin = "",
plugin_instance = "",
["type"] = "",
type_instance = ""
}
local msg = {
Fields = fields,
Timestamp = nil,
Hostname = nil,
Type = "metric_message_type"
}
function process_message()
local payload = read_message("Payload")
local ok, metrics = pcall(cjson.decode, payload)
if not ok then return -1 end
for i, metric in ipairs(metrics) do
fields.values = metric.values
fields.interval = metric.interval
fields.plugin = metric.plugin
fields.plugin_instance = metric.plugin_instance
fields.type = metric.type
fields.type_instance = metric.type_instance
local time = tonumber(metric.time)
msg.Timestamp = time
msg.Hostname = metric.host
inject_message(msg)
end
return 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment