Skip to content

Instantly share code, notes, and snippets.

@rafrombrc
Created July 16, 2014 22:54
Show Gist options
  • Save rafrombrc/d1cf56f5e80621536101 to your computer and use it in GitHub Desktop.
Save rafrombrc/d1cf56f5e80621536101 to your computer and use it in GitHub Desktop.
Sample Lua code for graphing statsd data
require("circular_buffer")
require("string")
require("cjson")
local idx_num
local stat_value
local debug
-- # rows, # cols, # seconds per row
cbuf = circular_buffer.new(300, 1, 1)
cbuf_idx = cbuf:set_header(1, "counter.0.count")
stat_name = "Fields[stats.counters.000000.count]"
function process_message()
local ts = read_message("Fields[timestamp]") * 1e9
stat_value = read_message(stat_name)
if stat_value then
cbuf:add(ts, cbuf_idx, stat_value)
end
return 0
end
function timer_event(ns)
inject_payload("cbuf", "Counter Stats", cbuf)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment