mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Add Telemetry::metrics_address option
This commit is contained in:
parent
322d223c18
commit
d549e3d56a
2 changed files with 8 additions and 2 deletions
|
@ -6,6 +6,10 @@ module Telemetry;
|
||||||
# to see the options without needing the rest.
|
# to see the options without needing the rest.
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
## Address used to make metric data available to Prometheus scrapers via
|
||||||
|
## HTTP.
|
||||||
|
const metrics_address = getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") &redef;
|
||||||
|
|
||||||
## Port used to make metric data available to Prometheus scrapers via
|
## Port used to make metric data available to Prometheus scrapers via
|
||||||
## HTTP.
|
## HTTP.
|
||||||
const metrics_port = 0/unknown &redef;
|
const metrics_port = 0/unknown &redef;
|
||||||
|
|
|
@ -35,8 +35,9 @@ void Manager::InitPostScript() {
|
||||||
// Metrics port setting is used to calculate a URL for prometheus scraping
|
// Metrics port setting is used to calculate a URL for prometheus scraping
|
||||||
std::string prometheus_url;
|
std::string prometheus_url;
|
||||||
auto metrics_port = id::find_val("Telemetry::metrics_port")->AsPortVal();
|
auto metrics_port = id::find_val("Telemetry::metrics_port")->AsPortVal();
|
||||||
|
auto metrics_address = id::find_val("Telemetry::metrics_address")->AsStringVal()->ToStdString();
|
||||||
if ( metrics_port->Port() != 0 )
|
if ( metrics_port->Port() != 0 )
|
||||||
prometheus_url = util::fmt("localhost:%u", metrics_port->Port());
|
prometheus_url = util::fmt("%s:%u", metrics_address.data(), metrics_port->Port());
|
||||||
|
|
||||||
if ( ! prometheus_url.empty() ) {
|
if ( ! prometheus_url.empty() ) {
|
||||||
CivetCallbacks* callbacks = nullptr;
|
CivetCallbacks* callbacks = nullptr;
|
||||||
|
@ -77,7 +78,8 @@ void Manager::InitPostScript() {
|
||||||
// CivetWeb stores a copy of the callbacks, so we're safe to delete the pointer here
|
// CivetWeb stores a copy of the callbacks, so we're safe to delete the pointer here
|
||||||
delete callbacks;
|
delete callbacks;
|
||||||
} catch ( const CivetException& exc ) {
|
} catch ( const CivetException& exc ) {
|
||||||
reporter->FatalError("Failed to setup Prometheus endpoint: %s\n", exc.what());
|
reporter->FatalError("Failed to setup Prometheus endpoint: %s. Attempted to bind to %s.", exc.what(),
|
||||||
|
prometheus_url.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
prometheus_exposer->RegisterCollectable(prometheus_registry);
|
prometheus_exposer->RegisterCollectable(prometheus_registry);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue