comparison 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
comparison
equal deleted inserted replaced
3148:8c7b8b2c3237 3149:ccbfe7df02dc
58 58
59 local function repr_sample(metric, labels, value, timestamp) 59 local function repr_sample(metric, labels, value, timestamp)
60 return escape_name(metric)..repr_labels(labels).." "..value.." "..timestamp.."\n"; 60 return escape_name(metric)..repr_labels(labels).." "..value.." "..timestamp.."\n";
61 end 61 end
62 62
63 local allowed_extras = { min = true, max = true, average = true };
64 local function insert_extras(data, key, name, timestamp, extra)
65 if not extra then
66 return false;
67 end
68 local has_extra = false;
69 for extra_name in pairs(allowed_extras) do
70 if extra[extra_name] then
71 local field = {
72 value = extra[extra_name],
73 labels = {
74 ["type"] = name,
75 field = extra_name,
76 },
77 typ = "gauge";
78 timestamp = timestamp,
79 };
80 t_insert(data[key], field);
81 has_extra = true;
82 end
83 end
84 return has_extra;
85 end
86
63 local function parse_stats() 87 local function parse_stats()
64 local timestamp = tostring(get_timestamp()); 88 local timestamp = tostring(get_timestamp());
65 local data = {}; 89 local data = {};
66 for stat, value in pairs(get_stats()) do 90 local stats, changed_only, extras = get_stats();
91 for stat, value in pairs(stats) do
67 -- module:log("debug", "changed_stats[%q] = %s", stat, tostring(value)); 92 -- module:log("debug", "changed_stats[%q] = %s", stat, tostring(value));
93 local extra = extras[stat];
68 local host, sect, name, typ = stat:match("^/([^/]+)/([^/]+)/(.+):(%a+)$"); 94 local host, sect, name, typ = stat:match("^/([^/]+)/([^/]+)/(.+):(%a+)$");
69 if host == nil then 95 if host == nil then
70 sect, name, typ = stat:match("^([^.]+)%.(.+):(%a+)$"); 96 sect, name, typ = stat:match("^([^.]+)%.(.+):(%a+)$");
71 elseif host == "*" then 97 elseif host == "*" then
72 host = nil; 98 host = nil;
89 field.labels.host = host; 115 field.labels.host = host;
90 end 116 end
91 if data[key] == nil then 117 if data[key] == nil then
92 data[key] = {}; 118 data[key] = {};
93 end 119 end
94 t_insert(data[key], field); 120 if not insert_extras(data, key, name, timestamp, extra) then
121 t_insert(data[key], field);
122 end
95 end 123 end
96 return data; 124 return data;
97 end 125 end
98 126
99 local function get_metrics(event) 127 local function get_metrics(event)