diff --git a/userspace/falco/app/actions/process_events.cpp b/userspace/falco/app/actions/process_events.cpp index 80361be3..00e44293 100644 --- a/userspace/falco/app/actions/process_events.cpp +++ b/userspace/falco/app/actions/process_events.cpp @@ -491,6 +491,9 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s) } if(s.enabled_sources.size() == 1) { + // Since the inspector is now opened, we can enable prometheus metrics + s.webserver.enable_prometheus_metrics(s); + // optimization: with only one source we don't spawn additional threads process_inspector_events(s, src_info->inspector, @@ -520,6 +523,10 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s) break; } } + if(s.enabled_sources.size() > 1) { + // Since all inspectors are now opened, we can enable prometheus metrics + s.webserver.enable_prometheus_metrics(s); + } // wait for event processing to terminate for all sources // if a thread terminates with an error, we trigger the app termination diff --git a/userspace/falco/webserver.cpp b/userspace/falco/webserver.cpp index 3998f853..5b83162a 100644 --- a/userspace/falco/webserver.cpp +++ b/userspace/falco/webserver.cpp @@ -58,12 +58,6 @@ void falco_webserver::start(const falco::app::state &state, res.set_content(versions_json_str, "application/json"); }); - if(state.config->m_metrics_enabled && webserver_config.m_prometheus_metrics_enabled) { - m_server->Get("/metrics", [&state](const httplib::Request &, httplib::Response &res) { - res.set_content(falco_metrics::to_text_prometheus(state), - falco_metrics::content_type_prometheus); - }); - } // run server in a separate thread if(!m_server->is_valid()) { m_server = nullptr; @@ -106,3 +100,13 @@ void falco_webserver::stop() { m_running = false; } } + +void falco_webserver::enable_prometheus_metrics(const falco::app::state &state) { + if(state.config->m_metrics_enabled && + state.config->m_webserver_config.m_prometheus_metrics_enabled) { + m_server->Get("/metrics", [&state](const httplib::Request &, httplib::Response &res) { + res.set_content(falco_metrics::to_text_prometheus(state), + falco_metrics::content_type_prometheus); + }); + } +} diff --git a/userspace/falco/webserver.h b/userspace/falco/webserver.h index 2c5c08b0..e5d97e58 100644 --- a/userspace/falco/webserver.h +++ b/userspace/falco/webserver.h @@ -40,6 +40,7 @@ public: virtual void start(const falco::app::state& state, const falco_configuration::webserver_config& webserver_config); virtual void stop(); + virtual void enable_prometheus_metrics(const falco::app::state& state); private: bool m_running = false;