diff options
author | Martin Weinelt <hexa@darmstadt.ccc.de> | 2021-11-22 23:09:53 +0100 |
---|---|---|
committer | Martin Weinelt <hexa@darmstadt.ccc.de> | 2021-11-23 11:30:28 +0100 |
commit | 386a1e79eb2df31c43bdf2b27828467a655318a8 (patch) | |
tree | 4355ffc24023ad8047d02fb0e2e7d4a46e2bdd18 /nixos/modules | |
parent | 0f4340da1d9b21a91ba442ec246c594a9c64ae10 (diff) | |
download | nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar.gz nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar.bz2 nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar.lz nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar.xz nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.tar.zst nixpkgs-386a1e79eb2df31c43bdf2b27828467a655318a8.zip |
nixos/smartctl-exporter: init
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 62e90232e11..d29d50706ef 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -61,6 +61,7 @@ let "rtl_433" "script" "snmp" + "smartctl" "smokeping" "sql" "surfboard" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix b/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix new file mode 100644 index 00000000000..b6416b93e69 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.smartctl; + format = pkgs.formats.yaml {}; + configFile = format.generate "smartctl-exporter.yml" { + smartctl_exporter = { + bind_to = "${cfg.listenAddress}:${toString cfg.port}"; + url_path = "/metrics"; + smartctl_location = "${pkgs.smartmontools}/bin/smartctl"; + collect_not_more_than_period = cfg.maxInterval; + devices = cfg.devices; + }; + }; +in { + port = 9633; + + extraOpts = { + devices = mkOption { + type = types.listOf types.str; + default = []; + example = literalExpression '' + [ "/dev/sda", "/dev/nvme0n1" ]; + ''; + description = '' + Paths to disks that will be monitored. + ''; + }; + maxInterval = mkOption { + type = types.str; + default = "60s"; + example = "2m"; + description = '' + Interval that limits how often a disk can be queried. + ''; + }; + }; + + serviceOpts = { + serviceConfig = { + AmbientCapabilities = [ + "CAP_SYS_ADMIN" + ]; + CapabilityBoundingSet = [ + "CAP_SYS_ADMIN" + ]; + DevicePolicy = "closed"; + DeviceAllow = lib.mkForce cfg.devices; + ExecStart = '' + ${pkgs.prometheus-smartctl-exporter}/bin/smartctl_exporter -config ${configFile} + ''; + PrivateDevices = lib.mkForce false; + ProtectProc = "invisible"; + ProcSubset = "pid"; + SupplementaryGroups = [ "disk" ]; + SystemCallFilter = [ + "@system-service" + "~@privileged @resources" + ]; + }; + }; +} |