2024-05-15 11:59:24 +02:00
|
|
|
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
with types;
|
|
|
|
let
|
|
|
|
cfg = config.components.monitor.prometheus;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.components.monitor.prometheus = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = lib.types.bool;
|
2024-05-18 12:02:21 +02:00
|
|
|
default = config.components.monitor.metrics.enable;
|
2024-05-15 11:59:24 +02:00
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = int;
|
|
|
|
default = 8090;
|
|
|
|
description = "port to provide Prometheus export";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
|
|
|
|
(mkIf config.components.monitor.prometheus.enable {
|
|
|
|
services.prometheus = {
|
|
|
|
checkConfig = "syntax-only";
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf config.components.monitor.prometheus.enable {
|
|
|
|
services.opentelemetry-collector.settings = {
|
|
|
|
exporters.prometheus.endpoint = "127.0.0.1:${toString cfg.port}";
|
|
|
|
service.pipelines.metrics.exporters = [ "prometheus" ];
|
|
|
|
};
|
|
|
|
services.prometheus.scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "opentelemetry";
|
|
|
|
metrics_path = "/metrics";
|
|
|
|
scrape_interval = "10s";
|
|
|
|
static_configs = [{ targets = [ "localhost:${toString cfg.port}" ]; }];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
})
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|