2024-05-15 11:59:24 +02:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
with types;
|
|
|
|
let
|
|
|
|
cfg = config.components.monitor.opentelemetry;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.components.monitor.opentelemetry = {
|
2024-05-19 10:44:37 +02:00
|
|
|
enable = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = config.components.monitor.enable;
|
|
|
|
description = "weather or not to use opentelemetry";
|
|
|
|
};
|
2024-05-15 11:59:24 +02:00
|
|
|
receiver.endpoint = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = "endpoint to receive the opentelementry data from other collectors";
|
|
|
|
};
|
|
|
|
exporter.endpoint = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = "endpoint to ship opentelementry data too";
|
|
|
|
};
|
2024-05-17 22:21:14 +02:00
|
|
|
exporter.debug = mkOption {
|
|
|
|
type = nullOr (enum [ "logs" "metrics" ]);
|
|
|
|
default = null;
|
|
|
|
description = "enable debug exporter.";
|
|
|
|
};
|
2024-05-15 11:59:24 +02:00
|
|
|
metrics.endpoint = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "127.0.0.1:8100";
|
|
|
|
description = "endpoint on where to provide opentelementry metrics";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
2024-05-18 12:02:21 +02:00
|
|
|
|
2024-05-19 10:44:37 +02:00
|
|
|
(mkIf config.components.monitor.opentelemetry.enable {
|
2024-05-15 11:59:24 +02:00
|
|
|
services.opentelemetry-collector = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.unstable.opentelemetry-collector-contrib;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
# add default tags to metrics
|
|
|
|
# todo : make sure we filter out metrics from otlp receivers
|
|
|
|
(mkIf config.components.monitor.enable {
|
|
|
|
services.opentelemetry-collector.settings = {
|
2024-05-15 17:11:41 +02:00
|
|
|
|
|
|
|
processors = {
|
|
|
|
|
|
|
|
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourcedetectionprocessor/README.md
|
|
|
|
"resourcedetection/system" = {
|
|
|
|
detectors = [ "system" ];
|
|
|
|
override = false;
|
|
|
|
system.hostname_sources = [ "os" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
metricstransform.transforms = [
|
|
|
|
{
|
|
|
|
include = ".*";
|
|
|
|
match_type = "regexp";
|
|
|
|
action = "update";
|
|
|
|
operations = [{
|
|
|
|
action = "add_label";
|
|
|
|
new_label = "machine";
|
|
|
|
new_value = config.networking.hostName;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-05-15 11:59:24 +02:00
|
|
|
};
|
|
|
|
})
|
2024-05-18 12:02:21 +02:00
|
|
|
(mkIf config.components.monitor.metrics.enable {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.metrics.processors = [
|
|
|
|
"metricstransform"
|
|
|
|
"resourcedetection/system"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf config.components.monitor.logs.enable {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.logs.processors = [ "resourcedetection/system" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-05-15 11:59:24 +02:00
|
|
|
|
2024-05-17 22:21:14 +02:00
|
|
|
(mkIf (config.components.monitor.opentelemetry.exporter.debug != null) {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
exporters.debug = {
|
|
|
|
verbosity = "detailed";
|
|
|
|
sampling_initial = 5;
|
|
|
|
sampling_thereafter = 200;
|
|
|
|
};
|
|
|
|
service.pipelines.${config.components.monitor.opentelemetry.exporter.debug} = {
|
|
|
|
exporters = [ "debug" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-05-15 11:59:24 +02:00
|
|
|
# ship to next instance
|
|
|
|
(mkIf (config.components.monitor.opentelemetry.exporter.endpoint != null) {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
exporters.otlp = {
|
|
|
|
endpoint = cfg.exporter.endpoint;
|
|
|
|
tls.insecure = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
2024-05-18 12:02:21 +02:00
|
|
|
(mkIf
|
|
|
|
(
|
|
|
|
config.components.monitor.opentelemetry.exporter.endpoint != null &&
|
|
|
|
config.components.monitor.logs.enable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.logs.exporters = [ "otlp" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf
|
|
|
|
(
|
|
|
|
config.components.monitor.opentelemetry.exporter.endpoint != null &&
|
|
|
|
config.components.monitor.metrics.enable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.metrics.exporters = [ "otlp" ];
|
|
|
|
};
|
|
|
|
})
|
2024-05-15 11:59:24 +02:00
|
|
|
|
|
|
|
# ship from other instance
|
|
|
|
(mkIf (config.components.monitor.opentelemetry.receiver.endpoint != null) {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
receivers.otlp.protocols.grpc.endpoint = cfg.receiver.endpoint;
|
|
|
|
};
|
|
|
|
})
|
2024-05-18 12:02:21 +02:00
|
|
|
(mkIf
|
|
|
|
(
|
|
|
|
config.components.monitor.opentelemetry.receiver.endpoint != null &&
|
|
|
|
config.components.monitor.logs.enable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.logs.receivers = [ "otlp" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf
|
|
|
|
(
|
|
|
|
config.components.monitor.opentelemetry.receiver.endpoint != null &&
|
|
|
|
config.components.monitor.metrics.enable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.pipelines.metrics.receivers = [ "otlp" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2024-05-15 11:59:24 +02:00
|
|
|
|
|
|
|
# scrape opentelemetry-colectors metrics
|
|
|
|
# todo: this should be collected another way (opentelemetry internal?)
|
2024-05-18 12:02:21 +02:00
|
|
|
# todo : enable me only when metrics.endpoint is set.
|
|
|
|
(mkIf config.components.monitor.metrics.enable {
|
2024-05-15 11:59:24 +02:00
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
receivers = {
|
|
|
|
prometheus.config.scrape_configs = [
|
|
|
|
{
|
|
|
|
job_name = "otelcol";
|
|
|
|
scrape_interval = "10s";
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ cfg.metrics.endpoint ];
|
|
|
|
}];
|
|
|
|
metric_relabel_configs = [
|
|
|
|
{
|
|
|
|
source_labels = [ "__name__" ];
|
|
|
|
regex = ".*grpc_io.*";
|
|
|
|
action = "drop";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
service = {
|
|
|
|
pipelines.metrics = {
|
|
|
|
receivers = [ "prometheus" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# todo : this should be automatically be collected
|
|
|
|
# open telemetries own metrics?
|
|
|
|
telemetry.metrics.address = cfg.metrics.endpoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
})
|
2024-05-18 12:02:21 +02:00
|
|
|
(mkIf (! config.components.monitor.metrics.enable) {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
service.telemetry.metrics.level = "none";
|
|
|
|
};
|
|
|
|
})
|
2024-05-15 11:59:24 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
}
|