From 209867b501f4f0dbdaee028d5487ed28ffe3f3fd Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Mon, 15 May 2023 09:30:42 +0200 Subject: [PATCH] track smartd with telegraf --- nixos/machines/chungus/configuration.nix | 2 +- nixos/machines/chungus/telegraf-smart.nix | 28 +++++++++++++++++++++++ nixos/machines/chungus/telegraf.nix | 5 ++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 nixos/machines/chungus/telegraf-smart.nix diff --git a/nixos/machines/chungus/configuration.nix b/nixos/machines/chungus/configuration.nix index 5df5047..c597796 100644 --- a/nixos/machines/chungus/configuration.nix +++ b/nixos/machines/chungus/configuration.nix @@ -30,6 +30,7 @@ ./prometheus.nix ./grafana.nix ./telegraf.nix + ./telegraf-smart.nix #./home-display.nix @@ -86,7 +87,6 @@ #}; services.printing.enable = false; - services.smartd.enable = true; #home-manager.users.mailUser.home.stateVersion = "22.11"; diff --git a/nixos/machines/chungus/telegraf-smart.nix b/nixos/machines/chungus/telegraf-smart.nix new file mode 100644 index 0000000..e740dd3 --- /dev/null +++ b/nixos/machines/chungus/telegraf-smart.nix @@ -0,0 +1,28 @@ +{ pkgs, ... }: +{ + systemd.services.telegraf.path = [ pkgs.smartmontools pkgs.nvme-cli "/run/wrappers" ]; + environment.systemPackages = [ pkgs.smartmontools pkgs.nvme-cli ]; + + services.telegraf = { + enable = true; + extraConfig.inputs.smart = { + attributes = true; + use_sudo = true; + }; + }; + + services.smartd.enable = true; + security.sudo.configFile = '' + # For smartctl add the following lines: + Cmnd_Alias SMARTCTL = ${pkgs.smartmontools}/bin/smartctl + telegraf ALL=(ALL) NOPASSWD: SMARTCTL + Defaults!SMARTCTL !logfile, !syslog, !pam_session + + # For nvme-cli add the following lines: + Cmnd_Alias NVME = ${pkgs.nvme-cli}/bin/nvme + telegraf ALL=(ALL) NOPASSWD: NVME + Defaults!NVME !logfile, !syslog, !pam_session + ''; + +} + diff --git a/nixos/machines/chungus/telegraf.nix b/nixos/machines/chungus/telegraf.nix index 5e65cd9..df51085 100644 --- a/nixos/machines/chungus/telegraf.nix +++ b/nixos/machines/chungus/telegraf.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: let urls = [ { url = "https://bitwarden.ingolf-wagner.de"; path = ""; } @@ -24,6 +24,7 @@ in inputs = { cpu = { }; diskio = { }; + smart.attributes = true; x509_cert = [{ sources = (map (url: "${url.url}:443") urls); interval = "30m"; # agent.interval = "10s" is default @@ -49,7 +50,7 @@ in targets = [ "localhost:9273" ]; labels = { service = "telegraf"; - server = "pepe"; + server = config.networking.hostName; }; }]; }