comparison mod_http_admin_api/mod_http_admin_api.lua @ 4776:13e913471b75

mod_http_admin_api: Ensure freshness of metrics when in manual mode When in manual collection mode, as recommended for Prometheus, collection needs to be triggered manually, or they would be stale, possibly dating from the start of the server. This might vary per metric depending on how and when the metrics are gathered.
author Kim Alvefur <zash@zash.se>
date Thu, 18 Nov 2021 19:26:07 +0100
parents bd83c9ada037
children 883ad8b0a7c0
comparison
equal deleted inserted replaced
4775:fd90925dc239 4776:13e913471b75
14 local mod_groups = module:depends("groups_internal"); 14 local mod_groups = module:depends("groups_internal");
15 15
16 local push_errors = module:shared("cloud_notify/push_errors"); 16 local push_errors = module:shared("cloud_notify/push_errors");
17 17
18 local site_name = module:get_option_string("site_name", module.host); 18 local site_name = module:get_option_string("site_name", module.host);
19
20 local manual_stats_collection = module:context("*"):get_option("statistics_interval") == "manual";
19 21
20 local json_content_type = "application/json"; 22 local json_content_type = "application/json";
21 23
22 local www_authenticate_header = ("Bearer realm=%q"):format(module.host.."/"..module.name); 24 local www_authenticate_header = ("Bearer realm=%q"):format(module.host.."/"..module.name);
23 25
610 end 612 end
611 613
612 local function get_server_metrics(event) 614 local function get_server_metrics(event)
613 event.response.headers["Content-Type"] = json_content_type; 615 event.response.headers["Content-Type"] = json_content_type;
614 local result = {}; 616 local result = {};
617 if manual_stats_collection then
618 statsmanager.collect();
619 end
615 local families = statsmanager.get_metric_registry():get_metric_families(); 620 local families = statsmanager.get_metric_registry():get_metric_families();
616 result.memory = maybe_export_plain_gauge(families.process_resident_memory_bytes); 621 result.memory = maybe_export_plain_gauge(families.process_resident_memory_bytes);
617 result.cpu = maybe_export_plain_counter(families.process_cpu_seconds); 622 result.cpu = maybe_export_plain_counter(families.process_cpu_seconds);
618 result.c2s = maybe_export_summed_gauge(families["prosody_mod_c2s/connections"]) 623 result.c2s = maybe_export_summed_gauge(families["prosody_mod_c2s/connections"])
619 return json.encode(result); 624 return json.encode(result);