Skip to content

Commit

Permalink
Allow specifying custom namespace for exported metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
krisleipus committed Oct 30, 2023
1 parent 89db4b9 commit fba60ec
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ pub struct Opts {
)]
pub exporter_metrics_enabled: HashMapSwitch,

// Exporter metrics namespace
#[clap(long = "exporter_metrics_namespace", default_value = "elasticsearch")]
pub exporter_metrics_namespace: String,

/// Exporter metadata refresh interval
#[clap(long = "exporter_metadata_refresh_interval", default_value = "3m")]
pub exporter_metadata_refresh_interval: humantime::Duration,
Expand Down
1 change: 1 addition & 0 deletions src/bin/elasticsearch_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
exporter_skip_zero_metrics: !opts.exporter_allow_zero_metrics,
exporter_poll_intervals: opts.exporter_poll_intervals.0.clone(),
exporter_metrics_enabled: opts.exporter_metrics_enabled.0.clone(),
exporter_metrics_namespace: opts.exporter_metrics_namespace.clone(),
exporter_metadata_refresh_interval: *opts.exporter_metadata_refresh_interval,

exporter_metrics_lifetime_interval: opts.exporter_metrics_lifetime_interval.0.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Collection {
Opts::new(metric_key, key)
.const_labels(self.const_labels.clone())
.subsystem(self.subsystem)
.namespace(crate::NAMESPACE),
.namespace(self.options.exporter_metrics_namespace.clone()),
&labels.keys().map(|s| s.as_str()).collect::<Vec<&str>>(),
)?;

Expand Down Expand Up @@ -171,7 +171,7 @@ impl Collection {
Opts::new(metric_key, key)
.const_labels(self.const_labels.clone())
.subsystem(self.subsystem)
.namespace(crate::NAMESPACE),
.namespace(self.options.exporter_metrics_namespace.clone()),
&labels.keys().map(|s| s.as_str()).collect::<Vec<&str>>(),
)?;

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ pub mod metadata;

pub(crate) mod metrics;

const NAMESPACE: &str = "elasticsearch";

/// Labels type with ordered keys
pub type Labels = BTreeMap<String, String>;

Expand Down
2 changes: 2 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct ExporterOptions {
pub exporter_skip_zero_metrics: bool,
/// Exporter metrics switch either ON or OFF
pub exporter_metrics_enabled: ExporterMetricsSwitch,
/// Export metrics namespace
pub exporter_metrics_namespace: String,
/// Exporter metadata refresh interval
pub exporter_metadata_refresh_interval: Duration,

Expand Down

0 comments on commit fba60ec

Please sign in to comment.