Skip to content

Instantly share code, notes, and snippets.

@jszwedko
Created July 2, 2021 18:36
Show Gist options
  • Save jszwedko/01a1dccf27d5e9a362795aa4bac09647 to your computer and use it in GitHub Desktop.
Save jszwedko/01a1dccf27d5e9a362795aa4bac09647 to your computer and use it in GitHub Desktop.
local aggregator = {}
local count = 0;
function aggregator.init()
count = 0
end
function aggregator.process()
count = count + 1
end
function aggregator.timer_handler(emit)
emit(make_counter(count))
count = 0
end
function aggregator.shutdown(emit)
emit(make_counter(count))
end
function make_counter(value)
return {
metric = {
name = "event_counter",
kind = "incremental",
timestamp = os.date("!*t"),
counter = {
value = value
}
}
}
end
return aggregator
[sources.in]
type = "stdin"
[transforms.aggregator]
type = "lua"
version = "2"
inputs = ["in"] # add names of the input components here
hooks.init = "aggregator.init"
hooks.process = "aggregator.process"
hooks.shutdown = "aggregator.shutdown"
timers = [{interval_seconds = 1, handler = "aggregator.timer_handler"}]
source = "aggregator = require('aggregator')"
[sinks.out]
type = "console"
inputs = ["aggregator"]
encoding.codec = "json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment