Annotate

mod_munin/mod_munin.lua @ 6301:fa45ae704b79

mod_cloud_notify: Update Readme diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md --- a/mod_cloud_notify/README.md +++ b/mod_cloud_notify/README.md @@ -1,109 +1,106 @@ ---- -labels: -- 'Stage-Beta' -summary: 'XEP-0357: Cloud push notifications' ---- +# Introduction -Introduction -============ +This module enables support for sending "push notifications" to clients +that need it, typically those running on certain mobile devices. -This module enables support for sending "push notifications" to clients that -need it, typically those running on certain mobile devices. +As well as this module, your client must support push notifications (the +apps that need it generally do, of course) and the app developer's push +gateway must be reachable from your Prosody server (this happens over a +normal XMPP server-to-server 's2s' connection). -As well as this module, your client must support push notifications (the apps -that need it generally do, of course) and the app developer's push gateway -must be reachable from your Prosody server (this happens over a normal XMPP -server-to-server 's2s' connection). - -Details -======= +# Details Some platforms, notably Apple's iOS and many versions of Android, impose -limits that prevent applications from running or accessing the network in the -background. This makes it difficult or impossible for an XMPP application to -remain reliably connected to a server to receive messages. - -In order for messaging and other apps to receive notifications, the OS vendors -run proprietary servers that their OS maintains a permanent connection to in -the background. Then they provide APIs to application developers that allow -sending notifications to specific devices via those servers. +limits that prevent applications from running or accessing the network +in the background. This makes it difficult or impossible for an XMPP +application to remain reliably connected to a server to receive +messages. -When you connect to your server with an app that requires push notifications, -it will use this module to set up a "push registration". When you receive -a message but your device is not connected to the server, this module will -generate a notification and send it to the push gateway operated by your -application's developers). Their gateway will then connect to your device's -OS vendor and ask them to forward the notification to your device. When your -device receives the notification, it will display it or wake up the app so it -can connect to XMPP and receive any pending messages. +In order for messaging and other apps to receive notifications, the OS +vendors run proprietary servers that their OS maintains a permanent +connection to in the background. Then they provide APIs to application +developers that allow sending notifications to specific devices via +those servers. -This protocol is described for developers in [XEP-0357: Push Notifications]. +When you connect to your server with an app that requires push +notifications, it will use this module to set up a "push registration". +When you receive a message but your device is not connected to the +server, this module will generate a notification and send it to the push +gateway operated by your application's developers). Their gateway will +then connect to your device's OS vendor and ask them to forward the +notification to your device. When your device receives the notification, +it will display it or wake up the app so it can connect to XMPP and +receive any pending messages. -For this module to work reliably, you must have [mod_smacks], [mod_mam] and -[mod_carbons] also enabled on your server. +This protocol is described for developers in \[XEP-0357: Push +Notifications\]. + +For this module to work reliably, you must have \[mod_smacks\], +\[mod_mam\] and \[mod_carbons\] also enabled on your server. -Some clients, notably Siskin and Snikket iOS need some additional extensions -that are not currently defined in a standard XEP. To support these clients, -see [mod_cloud_notify_extensions]. +Some clients, notably Siskin and Snikket iOS need some additional +extensions that are not currently defined in a standard XEP. To support +these clients, see \[mod_cloud_notify_extensions\]. -Configuration -============= +# Configuration - Option Default Description - ------------------------------------ ----------------- ------------------------------------------------------------------------------------------------------------------- - `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty - `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled - `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) - `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) - `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. - `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. + Option Default Description + -------------------------------------- ---------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty + `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled + `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) + `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) + `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. + `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. -(\*) There are privacy implications for enabling these options. +(\*) There are privacy implications for enabling these options.[^1] -Internal design notes -===================== +# Internal design notes -App servers are notified about offline messages, messages stored by [mod_mam] -or messages waiting in the smacks queue. -The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2]. +App servers are notified about offline messages, messages stored by +\[mod_mam\] or messages waiting in the smacks queue. The business rules +outlined +[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) +are all honored[^2]. -To cooperate with [mod_smacks] this module consumes some events: -`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`. -These events allow this module to send out notifications for messages received -while the session is hibernated by [mod_smacks] or even when smacks -acknowledgements for messages are delayed by a certain amount of seconds -configurable with the [mod_smacks] setting `smacks_max_ack_delay`. +To cooperate with \[mod_smacks\] this module consumes some events: +`smacks-ack-delayed`, `smacks-hibernation-start` and +`smacks-hibernation-end`. These events allow this module to send out +notifications for messages received while the session is hibernated by +\[mod_smacks\] or even when smacks acknowledgements for messages are +delayed by a certain amount of seconds configurable with the +\[mod_smacks\] setting `smacks_max_ack_delay`. -The `smacks_max_ack_delay` setting allows to send out notifications to clients -which aren't already in smacks hibernation state (because the read timeout or -connection close didn't already happen) but also aren't responding to acknowledgement -request in a timely manner. This setting thus allows conversations to be smoother -under such circumstances. +The `smacks_max_ack_delay` setting allows to send out notifications to +clients which aren't already in smacks hibernation state (because the +read timeout or connection close didn't already happen) but also aren't +responding to acknowledgement request in a timely manner. This setting +thus allows conversations to be smoother under such circumstances. -The new event `cloud-notify-ping` can be used by any module to send out a cloud -notification to either all registered endpoints for the given user or only the endpoints -given in the event data. +The new event `cloud-notify-ping` can be used by any module to send out +a cloud notification to either all registered endpoints for the given +user or only the endpoints given in the event data. -The config setting `push_notification_important_body` can be used to specify an alternative -body text to send to the remote pubsub node if the stanza is encrypted or has a body. -This way the real contents of the message aren't revealed to the push appserver but it -can still see that the push is important. -This is used by Chatsecure on iOS to send out high priority pushes in those cases for example. +The config setting `push_notification_important_body` can be used to +specify an alternative body text to send to the remote pubsub node if +the stanza is encrypted or has a body. This way the real contents of the +message aren't revealed to the push appserver but it can still see that +the push is important. This is used by Chatsecure on iOS to send out +high priority pushes in those cases for example. -Compatibility -============= - -**Note:** This module should be used with Lua 5.2 and higher. Using it with -Lua 5.1 may cause push notifications to not be sent to some clients. +# Compatibility ------- ----------------------------------------------------------------------------- - trunk Works - 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua) ------- ----------------------------------------------------------------------------- +**Note:** This module should be used with Lua 5.2 and higher. Using it +with Lua 5.1 may cause push notifications to not be sent to some +clients. + ------- ----------------------------------------------------------------- + trunk Works as of 25-06-13 + 13 Works + 0.12 Works + ------- ----------------------------------------------------------------- -[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service -[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown) +[^1]: The service which is expected to forward notifications to + something like Google Cloud Messaging or Apple Notification Service + +[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:36:52 +0200
parent 4553:7e5c8186f121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
648ce9087902 mod_munin: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1624
diff changeset
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
648ce9087902 mod_munin: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1624
diff changeset
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
648ce9087902 mod_munin: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1624
diff changeset
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
648ce9087902 mod_munin: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1624
diff changeset
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
d85ddd3e588a mod_munin: Fix syntax error
Kim Alvefur <zash@zash.se>
parents: 1897
diff changeset
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
d85ddd3e588a mod_munin: Fix syntax error
Kim Alvefur <zash@zash.se>
parents: 1897
diff changeset
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