about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/collectd.nix
blob: 3b2b123bbd078bf7f13415281239072471c6fc01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, lib, pkgs, options, ... }:

with lib;

let
  cfg = config.services.prometheus.exporters.collectd;
in
{
  port = 9103;
  extraOpts = {
    collectdBinary = {
      enable = mkEnableOption (lib.mdDoc "collectd binary protocol receiver");

      authFile = mkOption {
        default = null;
        type = types.nullOr types.path;
        description = lib.mdDoc "File mapping user names to pre-shared keys (passwords).";
      };

      port = mkOption {
        type = types.port;
        default = 25826;
        description = lib.mdDoc "Network address on which to accept collectd binary network packets.";
      };

      listenAddress = mkOption {
        type = types.str;
        default = "0.0.0.0";
        description = lib.mdDoc ''
          Address to listen on for binary network packets.
          '';
      };

      securityLevel = mkOption {
        type = types.enum ["None" "Sign" "Encrypt"];
        default = "None";
        description = lib.mdDoc ''
          Minimum required security level for accepted packets.
        '';
      };
    };

    logFormat = mkOption {
      type = types.enum [ "logfmt" "json" ];
      default = "logfmt";
      example = "json";
      description = lib.mdDoc ''
        Set the log format.
      '';
    };

    logLevel = mkOption {
      type = types.enum ["debug" "info" "warn" "error" "fatal"];
      default = "info";
      description = lib.mdDoc ''
        Only log messages with the given severity or above.
      '';
    };
  };
  serviceOpts = let
    collectSettingsArgs = optionalString (cfg.collectdBinary.enable) ''
      --collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
      --collectd.security-level ${cfg.collectdBinary.securityLevel} \
    '';
  in {
    serviceConfig = {
      ExecStart = ''
        ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
          --log.format ${escapeShellArg cfg.logFormat} \
          --log.level ${cfg.logLevel} \
          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
          ${collectSettingsArgs} \
          ${concatStringsSep " \\\n  " cfg.extraFlags}
      '';
    };
  };
}