diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-11-01 10:34:24 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-11-01 13:33:56 +0200 |
commit | 36d11e2e6fe28672904bf91f6e5eaeca87103705 (patch) | |
tree | 3097d3e3c4b8b29fd84612ae53ba96acc9058d3b /src/plugins/lua/metric_exporter.lua | |
parent | e2f599d7477081f0b58437b9218d72657883ab01 (diff) | |
download | rspamd-36d11e2e6fe28672904bf91f6e5eaeca87103705.tar.gz rspamd-36d11e2e6fe28672904bf91f6e5eaeca87103705.zip |
[Minor] Get rid of some global variables
- Also fix some bugs along the way
Diffstat (limited to 'src/plugins/lua/metric_exporter.lua')
-rw-r--r-- | src/plugins/lua/metric_exporter.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/plugins/lua/metric_exporter.lua b/src/plugins/lua/metric_exporter.lua index c4a0cdc0e..39a02665b 100644 --- a/src/plugins/lua/metric_exporter.lua +++ b/src/plugins/lua/metric_exporter.lua @@ -66,7 +66,7 @@ local function graphite_config(opts) return false end for _, v in ipairs(settings['metrics']) do - isvalid = false + local isvalid = false for _, vm in ipairs(valid_metrics) do if vm == v then isvalid = true @@ -95,6 +95,7 @@ local function graphite_push(kwargs) end local metrics_str = '' for _, v in ipairs(settings['metrics']) do + local mvalue local mname = string.format('%s.%s', settings['metric_prefix'], v:gsub(' ', '_')) local split = rspamd_str_split(v, '.') if #split == 1 then @@ -171,7 +172,7 @@ rspamd_config:add_on_load(function (cfg, ev_base, worker) end end) -- Push metrics to backend - function push_metrics(worker, time) + local function push_metrics(worker, time) logger.infox('Pushing metrics to %s backend', settings['backend']) local args = { ev_base = ev_base, @@ -182,21 +183,21 @@ rspamd_config:add_on_load(function (cfg, ev_base, worker) end backends[settings['backend']]['push'](args) end + -- Push metrics at regular intervals + local function schedule_regular_push() + rspamd_config:add_periodic(ev_base, settings['interval'], function (cfg, ev_base) + push_metrics(worker) + return true + end) + end -- Push metrics to backend and reschedule check - function schedule_intermediate_push(when) + local function schedule_intermediate_push(when) rspamd_config:add_periodic(ev_base, when, function (cfg, ev_base) push_metrics(worker) schedule_regular_push() return false end) end - -- Push metrics at regular intervals - function schedule_regular_push() - rspamd_config:add_periodic(ev_base, settings['interval'], function (cfg, ev_base) - push_metrics(worker) - return true - end) - end -- Try read statefile on startup local stamp local f, err = io.open(settings['statefile'], 'r') |