summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPascal Bach <pasci.bach@gmail.com>2017-09-11 20:17:00 +0200
committerJörg Thalheim <Mic92@users.noreply.github.com>2017-09-11 19:17:00 +0100
commit334e23d244d46f949feef7863ae5eb91e35e33e8 (patch)
tree5305fd1dd7448ce2a5f878fa9d76f0e9ba9f273f /nixos
parentf6e4c4e6c9b03448e6b332dbedd2f151161a48e8 (diff)
downloadnixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar.gz
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar.bz2
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar.lz
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar.xz
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.tar.zst
nixlib-334e23d244d46f949feef7863ae5eb91e35e33e8.zip
nixos/prometheus-collectd-exporter: init module (#29212)
* prometheus-collectd-exporter service: init module

Supports JSON and binary (optional) protocol
of collectd.

* nixos/prometheus-collectd-exporter: submodule is not needed for collectdBinary
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/collectd-exporter.nix128
2 files changed, 129 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index a46448b94378..900f04662b22 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -363,6 +363,7 @@
   ./services/monitoring/prometheus/default.nix
   ./services/monitoring/prometheus/alertmanager.nix
   ./services/monitoring/prometheus/blackbox-exporter.nix
+  ./services/monitoring/prometheus/collectd-exporter.nix
   ./services/monitoring/prometheus/fritzbox-exporter.nix
   ./services/monitoring/prometheus/json-exporter.nix
   ./services/monitoring/prometheus/nginx-exporter.nix
diff --git a/nixos/modules/services/monitoring/prometheus/collectd-exporter.nix b/nixos/modules/services/monitoring/prometheus/collectd-exporter.nix
new file mode 100644
index 000000000000..f8a5b9576a11
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/collectd-exporter.nix
@@ -0,0 +1,128 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.collectdExporter;
+
+  collectSettingsArgs = if (cfg.collectdBinary.enable) then ''
+    -collectd.listen-address ${optionalString (cfg.collectdBinary.listenAddress != null) cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
+    -collectd.security-level ${cfg.collectdBinary.securityLevel} \
+  '' else "";
+
+in {
+  options = {
+    services.prometheus.collectdExporter = {
+      enable = mkEnableOption "prometheus collectd exporter";
+
+      port = mkOption {
+        type = types.int;
+        default = 9103;
+        description = ''
+          Port to listen on.
+          This is used for scraping as well as the to receive collectd data via the write_http plugin.
+        '';
+      };
+
+      listenAddress = mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        example = "0.0.0.0";
+        description = ''
+          Address to listen on for web interface, telemetry and collectd JSON data.
+        '';
+      };
+
+      collectdBinary = {
+        enable = mkEnableOption "collectd binary protocol receiver";
+
+        authFile = mkOption {
+          default = null;
+          type = types.nullOr types.path;
+          description = "File mapping user names to pre-shared keys (passwords).";
+        };
+
+        port = mkOption {
+          type = types.int;
+          default = 25826;
+          description = ''Network address on which to accept collectd binary network packets.'';
+        };
+
+        listenAddress = mkOption {
+          type = types.nullOr types.str;
+          default = null;
+          example = "0.0.0.0";
+          description = ''
+            Address to listen on for binary network packets.
+            '';
+        };
+
+        securityLevel = mkOption {
+          type = types.enum ["None" "Sign" "Encrypt"];
+          default = "None";
+          description = ''
+            Minimum required security level for accepted packets.
+            '';
+        };
+      };
+
+      extraFlags = mkOption {
+        type = types.listOf types.str;
+        default = [];
+        description = ''
+          Extra commandline options when launching the collectd exporter.
+        '';
+      };
+
+      logFormat = mkOption {
+        type = types.str;
+        default = "logger:stderr";
+        example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true";
+        description = ''
+          Set the log target and format.
+        '';
+      };
+
+      logLevel = mkOption {
+        type = types.enum ["debug" "info" "warn" "error" "fatal"];
+        default = "info";
+        description = ''
+          Only log messages with the given severity or above.
+        '';
+      };
+
+      openFirewall = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Open port in firewall for incoming connections.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port) ++
+      (optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port);
+
+    systemd.services.prometheus-collectd-exporter = {
+      description = "Prometheus exporter for Collectd metrics";
+      unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter";
+      wantedBy = [ "multi-user.target" ];
+      serviceConfig = {
+        DynamicUser = true;
+        Restart = "always";
+        PrivateTmp = true;
+        WorkingDirectory = /tmp;
+        ExecStart = ''
+          ${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \
+            -log.format ${cfg.logFormat} \
+            -log.level ${cfg.logLevel} \
+            -web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \
+            ${collectSettingsArgs} \
+            ${concatStringsSep " " cfg.extraFlags}
+        '';
+      };
+    };
+  };
+}