diff --git a/docs/.map/map.csv b/docs/.map/map.csv index ed3ed10dc44df6..13ff0beb99c161 100644 --- a/docs/.map/map.csv +++ b/docs/.map/map.csv @@ -110,6 +110,7 @@ https://github.com/netdata/netdata/edit/master/src/collectors/README.md,Collecti https://github.com/netdata/netdata/edit/master/src/collectors/REFERENCE.md,Collectors configuration,Published,Collecting Metrics, https://github.com/netdata/agent-service-discovery/edit/master/README.md,Service discovery,Published,Collecting Metrics, https://github.com/netdata/netdata/edit/master/src/collectors/statsd.plugin/README.md,StatsD,Published,Collecting Metrics, +https://github.com/netdata/netdata/edit/master/src/crates/jf/otel-plugin/README.md,OpenTelemetry Metrics,Published,Collecting Metrics/OpenTelemetry,"Ingesting, storing and visualizing OpenTelemetry metrics", https://github.com/netdata/netdata/edit/master/docs/observability-centralization-points/metrics-centralization-points/README.md,Metrics Centralization Points,Published,Netdata Parents/Metrics Centralization Points, https://github.com/netdata/netdata/edit/master/docs/observability-centralization-points/metrics-centralization-points/configuration.md,Configuring Metrics Centralization Points,Published,Netdata Parents/Metrics Centralization Points, https://github.com/netdata/netdata/edit/master/docs/observability-centralization-points/metrics-centralization-points/sizing-netdata-parents.md,Sizing Netdata Parents,Published,Netdata Parents/Metrics Centralization Points, diff --git a/src/crates/jf/journal_file/src/file.rs b/src/crates/jf/journal_file/src/file.rs index 0f6b3a5c0c622b..e76188017a4b5c 100644 --- a/src/crates/jf/journal_file/src/file.rs +++ b/src/crates/jf/journal_file/src/file.rs @@ -19,9 +19,20 @@ use std::backtrace::Backtrace; use crate::value_guard::ValueGuard; +fn read_host_file(filename: &str) -> Result { + match std::fs::read_to_string(filename) { + Ok(contents) => Ok(contents), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + let filename = format!("/host/{}", filename); + Ok(std::fs::read_to_string(filename)?) + } + Err(e) => Err(e.into()), + } +} + #[cfg(target_os = "linux")] pub fn load_machine_id() -> Result<[u8; 16]> { - let content = std::fs::read_to_string("/etc/machine-id")?; + let content = read_host_file("/etc/machine-id")?; let decoded = hex::decode(content.trim()).map_err(|_| JournalError::UuidSerde)?; let bytes: [u8; 16] = decoded.try_into().map_err(|_| JournalError::UuidSerde)?; Ok(bytes) diff --git a/src/crates/jf/otel-plugin/README.md b/src/crates/jf/otel-plugin/README.md new file mode 100644 index 00000000000000..76df6cb350cdce --- /dev/null +++ b/src/crates/jf/otel-plugin/README.md @@ -0,0 +1,82 @@ +# OpenTelemetry Metrics (otel.plugin) + +`otel.plugin` is a [Netdata](https://github.com/netdata/netdata) external plugin, +enabling users to ingest, store and visualize OpenTelemetry metrics in charts. + +## Configuration + +Edit the [otel.yml](https://github.com/netdata/netdata/blob/master/src/crates/jf/otel-plugin/configs/otel.yml) +configuration file using `edit-config` from the Netdata +[config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory), +which is typically located under `/etc/netdata`. + +```bash +cd /etc/netdata # Replace this path with your Netdata config directory +sudo ./edit-config otel.yml +``` + +### gRPC Endpoint + +By default `otel.plugin` listens for incoming OTLP-formatted metrics on +`localhost:4317` via gRPC. Users can set up a secure TLS connection by +updating the TLS configuration in the `endpoint` section: + +```yaml +endpoint: + # gRPC endpoint to listen on for OpenTelemetry data + path: "127.0.0.1:4317" + + # Path to TLS certificate file (enables TLS when provided) + tls_cert_path: null + + # Path to TLS private key file (required when TLS certificate is provided) + tls_key_path: null + + # Path to TLS CA certificate file for client authentication (optional) + tls_ca_cert_path: null +``` + +### Metrics + +The `metrics` section allows users to specify the directory containing +configuration files for mapping OpenTelemetry metrics to Netdata chart +instances, and the number of metric samples the `otel.plugin` will use for +detecting their collection interval: + +```yaml +metrics: + # Directory with configuration files for mapping OTEL metrics to Netdata charts + # (relative paths are resolved based on Netdata's user configuration directory) + chart_configs_dir: otel.d/v1/metrics/ + + # Number of samples to buffer for collection interval detection + buffer_samples: 10 +``` + +## Mapping OpenTelemetry metrics to Netdata chart instances + +Without an explicit mapping, the `otel.plugin` defaults to creating distinct +chart instances based on the attributes of each data point in a metric. Users +can place their YAML chart configuration files under `otel.d/v1/metrics` to +override, or fine-tune, the default mapping. + +For each instrumentation scope and metric name, the configuration defines +the attributes that the `otel.plugin` will use when creating new chart +instances and dimension names. + +For example, the following bit from the +[otel.d/v1/metrics/hostmetrics.yml](https://github.com/netdata/netdata/blob/master/src/crates/jf/otel-plugin/configs/otel.d/v1/metrics/hostmetrics-receiver.yml) + configuration file for the [hostmetrics](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/internal/scraper/networkscraper/documentation.md) receiver: +```yaml +select: + instrumentation_scope_name: hostmetricsreceiver.*networkscraper + metric_name: system.network.connections +extract: + chart_instance_pattern: metric.attributes.protocol + dimension_name: metric.attributes.state +``` +will apply to metrics whose instrumentation scope and metric names match the +corresponding regular expressions specified in the values of the +`instrumentation_scope_name` and `metric_name` keys. Similarly, the values of +the `protocol` and `state` attributes of each data point in the matched metric +will be used to create a new chart instance with the proper dimension names. diff --git a/src/crates/jf/otel-plugin/src/netdata_chart.rs b/src/crates/jf/otel-plugin/src/netdata_chart.rs index 52390a7547c489..84e051e945a75a 100644 --- a/src/crates/jf/otel-plugin/src/netdata_chart.rs +++ b/src/crates/jf/otel-plugin/src/netdata_chart.rs @@ -148,8 +148,8 @@ impl NetdataChart { let name = ""; let title = &self.metric_description; let units = &self.metric_unit; - let family = &self.metric_name; let context = format!("otel.{}", &self.metric_name); + let family = context.clone(); let chart_type = if self.is_histogram() { "heatmap" } else {