Mercurial > prosody-modules
diff mod_prometheus/mod_prometheus.lua @ 3149:ccbfe7df02dc
mod_prometheus: Expose min, max and average when available.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 25 Jun 2018 23:58:13 +0200 |
parents | 9817e45a79e6 |
children | 343dc9dd70dd |
line wrap: on
line diff
--- a/mod_prometheus/mod_prometheus.lua Sun Jun 03 02:18:02 2018 +0200 +++ b/mod_prometheus/mod_prometheus.lua Mon Jun 25 23:58:13 2018 +0200 @@ -60,11 +60,37 @@ return escape_name(metric)..repr_labels(labels).." "..value.." "..timestamp.."\n"; end +local allowed_extras = { min = true, max = true, average = true }; +local function insert_extras(data, key, name, timestamp, extra) + if not extra then + return false; + end + local has_extra = false; + for extra_name in pairs(allowed_extras) do + if extra[extra_name] then + local field = { + value = extra[extra_name], + labels = { + ["type"] = name, + field = extra_name, + }, + typ = "gauge"; + timestamp = timestamp, + }; + t_insert(data[key], field); + has_extra = true; + end + end + return has_extra; +end + local function parse_stats() local timestamp = tostring(get_timestamp()); local data = {}; - for stat, value in pairs(get_stats()) do + local stats, changed_only, extras = get_stats(); + for stat, value in pairs(stats) do -- module:log("debug", "changed_stats[%q] = %s", stat, tostring(value)); + local extra = extras[stat]; local host, sect, name, typ = stat:match("^/([^/]+)/([^/]+)/(.+):(%a+)$"); if host == nil then sect, name, typ = stat:match("^([^.]+)%.(.+):(%a+)$"); @@ -91,7 +117,9 @@ if data[key] == nil then data[key] = {}; end - t_insert(data[key], field); + if not insert_extras(data, key, name, timestamp, extra) then + t_insert(data[key], field); + end end return data; end