Created
July 2, 2021 18:36
-
-
Save jszwedko/01a1dccf27d5e9a362795aa4bac09647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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