Software /
code /
prosody-modules
Changeset
3134:99ac6dda9878
mod_prometheus: Move timestamp generation to the stats-update event.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 22 Jun 2018 01:03:47 +0200 |
parents | 3133:321fd53a3191 |
children | 3135:e166ccc7a779 |
files | mod_prometheus/mod_prometheus.lua |
diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_prometheus/mod_prometheus.lua Fri Jun 22 00:38:37 2018 +0200 +++ b/mod_prometheus/mod_prometheus.lua Fri Jun 22 01:03:47 2018 +0200 @@ -63,6 +63,7 @@ module:hook("stats-updated", function (event) local all_stats, this = event.stats_extra; + local timestamp = tostring(get_timestamp()); local host, sect, name, typ; data = {}; for stat, value in pairs(event.stats) do @@ -86,6 +87,7 @@ labels = { ["type"] = name}, -- TODO: Use the other types where it makes sense. typ = (typ == "rate" and "counter" or "gauge"), + timestamp = timestamp, }; if host then field.labels.host = host; @@ -102,12 +104,11 @@ response.headers.content_type = "text/plain; version=0.4.4"; local answer = {}; - local timestamp = tostring(get_timestamp()); for key, fields in pairs(data) do t_insert(answer, repr_help(key, "TODO: add a description here.")); t_insert(answer, repr_type(key, fields[1].typ)); for _, field in pairs(fields) do - t_insert(answer, repr_sample(key, field.labels, field.value, timestamp)); + t_insert(answer, repr_sample(key, field.labels, field.value, field.timestamp)); end end return t_concat(answer, "");