nixiso/opentelemetry-collector: init

This commit is contained in:
Bouke van der Bijl 2023-03-14 14:15:17 +01:00
parent a12204ede9
commit cf90db8b70
3 changed files with 75 additions and 0 deletions

View file

@ -733,6 +733,7 @@
./services/monitoring/munin.nix ./services/monitoring/munin.nix
./services/monitoring/nagios.nix ./services/monitoring/nagios.nix
./services/monitoring/netdata.nix ./services/monitoring/netdata.nix
./services/monitoring/opentelemetry-collector.nix
./services/monitoring/parsedmarc.nix ./services/monitoring/parsedmarc.nix
./services/monitoring/prometheus/alertmanager.nix ./services/monitoring/prometheus/alertmanager.nix
./services/monitoring/prometheus/default.nix ./services/monitoring/prometheus/default.nix

View file

@ -0,0 +1,73 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkEnableOption mkIf mkOption types getExe;
cfg = config.services.opentelemetry-collector;
opentelemetry-collector = cfg.package;
settingsFormat = pkgs.formats.yaml {};
in {
options.services.opentelemetry-collector = {
enable = mkEnableOption (lib.mdDoc "Opentelemetry Collector");
package = mkOption {
type = types.package;
default = pkgs.opentelemetry-collector;
defaultText = lib.literalExpression "pkgs.opentelemetry-collector";
description = lib.mdDoc "The opentelemetry-collector package to use.";
};
settings = mkOption {
type = settingsFormat.type;
default = {};
description = lib.mdDoc ''
Specify the configuration for Opentelemetry Collector in Nix.
See https://opentelemetry.io/docs/collector/configuration/ for available options.
'';
};
configFile = mkOption {
type = types.nullOr types.path;
default = null;
description = lib.mdDoc ''
Specify a path to a configuration file that Opentelemetry Collector should use.
'';
};
};
config = mkIf cfg.enable {
assertions = [{
assertion = (
(cfg.settings == {}) != (cfg.configFile == null)
);
message = ''
Please specify a configuration for Opentelemetry Collector with either
'services.opentelemetry-collector.settings' or
'services.opentelemetry-collector.configFile'.
'';
}];
systemd.services.opentelemetry-collector = {
description = "Opentelemetry Collector Service Daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig = let
conf = if cfg.configFile == null
then settingsFormat.generate "config.yaml" cfg.settings
else cfg.configFile;
in
{
ExecStart = "${getExe opentelemetry-collector} --config=file:${conf}";
DynamicUser = true;
Restart = "always";
ProtectSystem = "full";
DevicePolicy = "closed";
NoNewPrivileges = true;
WorkingDirectory = "/var/lib/opentelemetry-collector";
StateDirectory = "opentelemetry-collector";
};
};
};
}

View file

@ -48,5 +48,6 @@ buildGoModule rec {
''; '';
license = licenses.asl20; license = licenses.asl20;
maintainers = with maintainers; [ uri-canva jk ]; maintainers = with maintainers; [ uri-canva jk ];
mainProgram = "otelcorecol";
}; };
} }