comparison mod_prometheus/mod_prometheus.lua @ 3128:a34e7bd87b39

mod_prometheus: Optimise global lookups.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 21 Jun 2018 22:15:15 +0200
parents 36770ae1148f
children ddd39ca7b953
comparison
equal deleted inserted replaced
3127:36770ae1148f 3128:a34e7bd87b39
5 -- This module is MIT/X11 licensed. 5 -- This module is MIT/X11 licensed.
6 6
7 module:set_global(); 7 module:set_global();
8 module:depends "http"; 8 module:depends "http";
9 9
10 local tostring = tostring;
10 local s_format = string.format; 11 local s_format = string.format;
11 local t_insert = table.insert; 12 local t_insert = table.insert;
13 local t_concat = table.concat;
12 local socket = require "socket"; 14 local socket = require "socket";
13 local mt = require "util.multitable"; 15 local mt = require "util.multitable";
14 16
15 local meta = mt.new(); meta.data = module:shared"meta"; 17 local meta = mt.new(); meta.data = module:shared"meta";
16 local data = mt.new(); data.data = module:shared"data"; 18 local data = mt.new(); data.data = module:shared"data";
52 t_insert(values, repr_label(escape_name(key), escape(value))); 54 t_insert(values, repr_label(escape_name(key), escape(value)));
53 end 55 end
54 if #values == 0 then 56 if #values == 0 then
55 return ""; 57 return "";
56 end 58 end
57 return "{"..table.concat(values, ", ").."}"; 59 return "{"..t_concat(values, ", ").."}";
58 end 60 end
59 61
60 local function repr_sample(metric, labels, value, timestamp) 62 local function repr_sample(metric, labels, value, timestamp)
61 return escape_name(metric)..repr_labels(labels).." "..value.." "..timestamp.."\n"; 63 return escape_name(metric)..repr_labels(labels).." "..value.." "..timestamp.."\n";
62 end 64 end
110 t_insert(answer, repr_help(name, "TODO: add a description here.")); 112 t_insert(answer, repr_help(name, "TODO: add a description here."));
111 t_insert(answer, repr_type(name, "gauge")); 113 t_insert(answer, repr_type(name, "gauge"));
112 t_insert(answer, repr_sample(name, {}, value, timestamp)); 114 t_insert(answer, repr_sample(name, {}, value, timestamp));
113 end 115 end
114 end 116 end
115 return table.concat(answer, ""); 117 return t_concat(answer, "");
116 end 118 end
117 119
118 function module.add_host(module) 120 function module.add_host(module)
119 module:provides("http", { 121 module:provides("http", {
120 default_path = "metrics"; 122 default_path = "metrics";