Software /
code /
prosody
Comparison
plugins/mod_s2s.lua @ 11525:5f99fcc43938
mod_s2s: Port to new OpenMetrics API
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Sun, 18 Apr 2021 12:35:16 +0200 |
parent | 11419:2c26dfc1977f |
child | 11526:15a3db955ad3 |
comparison
equal
deleted
inserted
replaced
11524:6de302b53a3e | 11525:5f99fcc43938 |
---|---|
39 local secure_domains, insecure_domains = | 39 local secure_domains, insecure_domains = |
40 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; | 40 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; |
41 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); | 41 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); |
42 local stanza_size_limit = module:get_option_number("s2s_stanza_size_limit"); -- TODO come up with a sensible default (util.xmppstream defaults to 10M) | 42 local stanza_size_limit = module:get_option_number("s2s_stanza_size_limit"); -- TODO come up with a sensible default (util.xmppstream defaults to 10M) |
43 | 43 |
44 local measure_connections = module:measure("connections", "amount"); | 44 local measure_connections_inbound = module:metric( |
45 local measure_ipv6 = module:measure("ipv6", "amount"); | 45 "gauge", "connections_inbound", "", |
46 "Established incoming s2s connections", | |
47 {"host", "type", "ip_family"} | |
48 ); | |
49 local measure_connections_outbound = module:metric( | |
50 "gauge", "connections_outbound", "", | |
51 "Established outgoing s2s connections", | |
52 {"host", "type", "ip_family"} | |
53 ); | |
46 | 54 |
47 local sessions = module:shared("sessions"); | 55 local sessions = module:shared("sessions"); |
48 | 56 |
49 local runner_callbacks = {}; | 57 local runner_callbacks = {}; |
50 | 58 |
58 use_ipv6 = module:get_option_boolean("use_ipv6", true); | 66 use_ipv6 = module:get_option_boolean("use_ipv6", true); |
59 use_dane = module:get_option_boolean("use_dane", false); | 67 use_dane = module:get_option_boolean("use_dane", false); |
60 }; | 68 }; |
61 | 69 |
62 module:hook("stats-update", function () | 70 module:hook("stats-update", function () |
63 local count = 0; | 71 measure_connections_inbound:clear() |
64 local ipv6 = 0; | 72 measure_connections_outbound:clear() |
73 -- TODO: init all expected metrics once? | |
74 -- or maybe create/delete them in host-activate/host-deactivate? requires | |
75 -- extra API in openmetrics.lua tho | |
65 for _, session in pairs(sessions) do | 76 for _, session in pairs(sessions) do |
66 count = count + 1; | 77 local is_inbound = string.sub(session.type, 4, 5) == "in" |
67 if session.ip and session.ip:match(":") then | 78 local metric_family = is_inbound and measure_connections_inbound or measure_connections_outbound |
68 ipv6 = ipv6 + 1; | 79 local host = is_inbound and session.to_host or session.from_host or "" |
69 end | 80 local type_ = session.type or "other" |
70 end | 81 |
71 measure_connections(count); | 82 -- we want to expose both v4 and v6 counters in all cases to make |
72 measure_ipv6(ipv6); | 83 -- queries smoother |
84 local is_ipv6 = session.ip and session.ip:match(":") and 1 or 0 | |
85 local is_ipv4 = 1 - is_ipv6 | |
86 metric_family:with_labels(host, type_, "ipv4"):add(is_ipv4) | |
87 metric_family:with_labels(host, type_, "ipv6"):add(is_ipv6) | |
88 end | |
73 end); | 89 end); |
74 | 90 |
75 --- Handle stanzas to remote domains | 91 --- Handle stanzas to remote domains |
76 | 92 |
77 local bouncy_stanzas = { message = true, presence = true, iq = true }; | 93 local bouncy_stanzas = { message = true, presence = true, iq = true }; |