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.

Revisions

  1. rafrombrc revised this gist Sep 18, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions decode_json_metric.lua
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,10 @@ local fields = {
    }

    local msg = {
    Fields = fields
    Fields = fields,
    Timestamp = nil,
    Hostname = nil,
    Type = "metric_message_type"
    }

    function process_message()
    @@ -28,8 +31,6 @@ function process_message()
    msg.Timestamp = time
    msg.Hostname = metric.host
    inject_message(msg)
    msg.Timestamp = nil
    msg.Hostname = nil
    end
    return 0
    end
  2. rafrombrc revised this gist Sep 18, 2014. 1 changed file with 2 additions and 7 deletions.
    9 changes: 2 additions & 7 deletions decode_json_metric.lua
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    require "cjson"

    local fields = {
    @@ -26,12 +25,8 @@ function process_message()
    fields.type = metric.type
    fields.type_instance = metric.type_instance
    local time = tonumber(metric.time)
    if time then
    msg.Timestamp = time
    end
    if metric.host then
    msg.Hostname = metric.host
    end
    msg.Timestamp = time
    msg.Hostname = metric.host
    inject_message(msg)
    msg.Timestamp = nil
    msg.Hostname = nil
  3. rafrombrc revised this gist Sep 18, 2014. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions decode_json_metric.lua
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,30 @@

    require "cjson"

    local fields = {
    values = {},
    interval = 0,
    plugin = "",
    plugin_instance = "",
    ["type"] = "",
    type_instance = ""
    }

    local msg = {
    Fields = fields
    }

    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
    local fields = {}
    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 msg = {Fields = fields}
    local time = tonumber(metric.time)
    if time then
    msg.Timestamp = time
    @@ -21,6 +33,8 @@ function process_message()
    msg.Hostname = metric.host
    end
    inject_message(msg)
    msg.Timestamp = nil
    msg.Hostname = nil
    end
    return 0
    end
  4. rafrombrc created this gist Sep 18, 2014.
    26 changes: 26 additions & 0 deletions decode_json_metric.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    require "cjson"

    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
    local fields = {}
    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 msg = {Fields = fields}
    local time = tonumber(metric.time)
    if time then
    msg.Timestamp = time
    end
    if metric.host then
    msg.Hostname = metric.host
    end
    inject_message(msg)
    end
    return 0
    end