# HG changeset patch # User Emmanuel Gil Peyrot # Date 1529622227 -7200 # Node ID 99ac6dda98783d4c2b894aaff16a9269fb8d30ae # Parent 321fd53a319111e050638836d137dcd0548657ef mod_prometheus: Move timestamp generation to the stats-update event. diff -r 321fd53a3191 -r 99ac6dda9878 mod_prometheus/mod_prometheus.lua --- 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, "");