Mercurial > prosody-modules
annotate mod_munin/mod_munin.lua @ 5534:7b4e0c3642bf
mod_firewall: Fix inverted logic of 'FROM FULL JID?'
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Jun 2023 13:04:19 +0100 |
parents | 7e5c8186f121 |
children |
rev | line source |
---|---|
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 module:set_global(); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local s_format = string.format; |
4553
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
4 local t_insert = table.insert; |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
5 local t_concat = table.concat; |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local array = require"util.array"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local it = require"util.iterators"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local mt = require"util.multitable"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local meta = mt.new(); meta.data = module:shared"meta"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local data = mt.new(); data.data = module:shared"data"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local munin_listener = {}; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local munin_commands = {}; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local node_name = module:get_option_string("munin_node_name", "localhost"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local ignore_stats = module:get_option_set("munin_ignored_stats", { }); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local function clean_fieldname(name) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 return (name:gsub("[^A-Za-z0-9_]", "_"):gsub("^[^A-Za-z_]", "_%1")); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 function munin_listener.onconnect(conn) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 -- require"core.statsmanager".collect(); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 conn:write("# munin node at "..node_name.."\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 function munin_listener.onincoming(conn, line) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 line = line and line:match("^[^\r\n]+"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 if type(line) ~= "string" then return end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 -- module:log("debug", "incoming: %q", line); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local command = line:match"^%w+"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 command = munin_commands[command]; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 if not command then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 conn:write("# Unknown command.\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 return; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 local ok, err = pcall(command, conn, line); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 if not ok then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 module:log("error", "Error running %q: %s", line, err); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 conn:close(); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 function munin_listener.ondisconnect() end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 function munin_commands.cap(conn) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 conn:write("cap\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 |
1648 | 51 function munin_commands.list(conn) |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 conn:write(array(it.keys(data.data)):concat(" ") .. "\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 function munin_commands.config(conn, line) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 -- TODO what exactly? |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 local stat = line:match("%s(%S+)"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 if not stat then conn:write("# Unknown service\n.\n"); return end |
1648 | 59 for _, _, k, value in meta:iter(stat, "", nil) do |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 conn:write(s_format("%s %s\n", k, value)); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 end |
1648 | 62 for _, name, k, value in meta:iter(stat, nil, nil) do |
1676
accbf0db0246
mod_munin: Exclude ignored stats even if they happen to be included in data
Kim Alvefur <zash@zash.se>
parents:
1648
diff
changeset
|
63 if name ~= "" and not ignore_stats:contains(name) then |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 conn:write(s_format("%s.%s %s\n", name, k, value)); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 conn:write(".\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 function munin_commands.fetch(conn, line) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 local stat = line:match("%s(%S+)"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 if not stat then conn:write("# Unknown service\n.\n"); return end |
1648 | 73 for _, name, value in data:iter(stat, nil) do |
1676
accbf0db0246
mod_munin: Exclude ignored stats even if they happen to be included in data
Kim Alvefur <zash@zash.se>
parents:
1648
diff
changeset
|
74 if not ignore_stats:contains(name) then |
1692
44ddec97ad82
mod_munin: Use string.format flag instead of tostring when reporting values
Kim Alvefur <zash@zash.se>
parents:
1676
diff
changeset
|
75 conn:write(s_format("%s.value %.12f\n", name, value)); |
1676
accbf0db0246
mod_munin: Exclude ignored stats even if they happen to be included in data
Kim Alvefur <zash@zash.se>
parents:
1648
diff
changeset
|
76 end |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 conn:write(".\n"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 function munin_commands.quit(conn) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 conn:close(); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 module:hook("stats-updated", function (event) |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 local all_stats, this = event.stats_extra; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 local host, sect, name, typ, key; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 for stat, value in pairs(event.changed_stats) do |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 if not ignore_stats:contains(stat) then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 this = all_stats[stat]; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 -- module:log("debug", "changed_stats[%q] = %s", stat, tostring(value)); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 host, sect, name, typ = stat:match("^/([^/]+)/([^/]+)/(.+):(%a+)$"); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 if host == nil then |
3130
c47cd8dbd310
mod_munin: Allow names containing any number of “:”.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3129
diff
changeset
|
94 sect, name, typ = stat:match("^([^.]+)%.(.+):(%a+)$"); |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 elseif host == "*" then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 host = nil; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 end |
1898 | 98 if sect:find("^mod_measure_.") then |
1897
effd909d05b0
mod_munin: Strip mod_measure_ and mod_statistics_ from section names
Kim Alvefur <zash@zash.se>
parents:
1692
diff
changeset
|
99 sect = sect:sub(13); |
1898 | 100 elseif sect:find("^mod_statistics_.") then |
1897
effd909d05b0
mod_munin: Strip mod_measure_ and mod_statistics_ from section names
Kim Alvefur <zash@zash.se>
parents:
1692
diff
changeset
|
101 sect = sect:sub(16); |
effd909d05b0
mod_munin: Strip mod_measure_ and mod_statistics_ from section names
Kim Alvefur <zash@zash.se>
parents:
1692
diff
changeset
|
102 end |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 key = clean_fieldname(s_format("%s_%s_%s", host or "global", sect, typ)); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 if not meta:get(key) then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 if host then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 meta:set(key, "", "graph_title", s_format("%s %s on %s", sect, typ, host)); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 else |
3129
2ffc268ba2fa
mod_munin: Don’t use host when it is nil.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1898
diff
changeset
|
109 meta:set(key, "", "graph_title", s_format("Global %s %s", sect, typ)); |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 meta:set(key, "", "graph_vlabel", this and this.units or typ); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 meta:set(key, "", "graph_category", sect); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 meta:set(key, name, "label", name); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 elseif not meta:get(key, name, "label") then |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 meta:set(key, name, "label", name); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 data:set(key, name, value); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 end |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 end); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 |
4553
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
124 local function openmetrics_handler(event) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
125 local registry = event.metric_registry |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
126 local host, sect, name, typ, key; |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
127 for family_name, metric_family in pairs(registry:get_metric_families()) do |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
128 if not ignore_stats:contains(family_name) then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
129 -- module:log("debug", "changed_stats[%q] = %s", stat, tostring(value)); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
130 local host_key |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
131 if metric_family.label_keys[1] == "host" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
132 host_key = 1 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
133 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
134 if family_name:sub(1, 12) == "prosody_mod_" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
135 sect, name = family_name:match("^prosody_mod_([^/]+)/(.+)$") |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
136 else |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
137 sect, name = family_name:match("^([^_]+)_(.+)$") |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
138 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
139 name = clean_fieldname(name) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
140 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
141 local metric_type = metric_family.type_ |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
142 if metric_type == "gauge" or metric_type == "unknown" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
143 typ = "GAUGE" |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
144 else |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
145 typ = "DCOUNTER" |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
146 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
147 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
148 for labelset, metric in metric_family:iter_metrics() do |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
149 host = host_key and labelset[host_key] or "global" |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
150 local name_parts = {} |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
151 for i, label in ipairs(labelset) do |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
152 if i ~= host_key then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
153 t_insert(name_parts, label) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
154 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
155 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
156 local full_name = t_concat(name_parts, "_") |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
157 local display_name = #name_parts > 0 and full_name or name |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
158 key = clean_fieldname(s_format("%s_%s_%s", host or "global", sect, name)); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
159 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
160 local unit |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
161 local factor = 1 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
162 unit = metric_family.unit |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
163 if unit == "seconds" and typ == "DCOUNTER" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
164 factor = 100 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
165 unit = "%time" |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
166 elseif typ == "DCOUNTER" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
167 unit = unit .. "/s" |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
168 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
169 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
170 if not meta:get(key, "") then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
171 meta:set(key, "", "graph_title", s_format(metric_family.description)); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
172 if unit ~= "" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
173 meta:set(key, "", "graph_vlabel", unit); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
174 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
175 meta:set(key, "", "graph_category", sect); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
176 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
177 if not meta:get(key, display_name) then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
178 meta:set(key, display_name, "label", display_name); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
179 meta:set(key, display_name, "type", typ) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
180 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
181 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
182 for suffix, extra_labels, value in metric:iter_samples() do |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
183 if metric_type == "histogram" or metric_type == "summary" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
184 if suffix == "_sum" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
185 data:set(key, display_name, value * factor) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
186 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
187 elseif suffix == "_total" or suffix == "" then |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
188 data:set(key, display_name, value * factor) |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
189 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
190 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
191 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
192 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
193 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
194 end |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
195 |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
196 module:hook("openmetrics-updated", openmetrics_handler); |
7e5c8186f121
mod_munin: Port to new OpenMetrics based statistics module
Jonas Schäfer <jonas@wielicki.name>
parents:
3130
diff
changeset
|
197 |
1624
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 module:provides("net", { |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 listener = munin_listener; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 default_mode = "*l"; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 default_port = 4949; |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
202 }); |
0f20390f6fa5
mod_munin: Implementation of the Munin collection protocol
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
203 |