diff options
author | Karel Kočí <cynerd@email.cz> | 2022-12-18 13:39:13 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-12-18 13:39:13 +0100 |
commit | 78e13fc7069875b6101b517fb0bff1fe72835cfb (patch) | |
tree | 80467e4c9290e62858458c7f78cb3acd652fa6e1 /nixos/modules | |
parent | d7e20342a2fed30403603987728ddf7138858f4d (diff) | |
download | nixos-personal-78e13fc7069875b6101b517fb0bff1fe72835cfb.tar.gz nixos-personal-78e13fc7069875b6101b517fb0bff1fe72835cfb.tar.bz2 nixos-personal-78e13fc7069875b6101b517fb0bff1fe72835cfb.zip |
Add monitoring
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/default.nix | 1 | ||||
-rw-r--r-- | nixos/modules/develop.nix | 1 | ||||
-rw-r--r-- | nixos/modules/monitoring.nix | 92 |
3 files changed, 94 insertions, 0 deletions
diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index fd60aa4..8bf6a31 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -6,6 +6,7 @@ nixpkgs: { cynerd-gaming = import ./gaming.nix; cynerd-generic = import ./generic.nix; cynerd-hosts = import ./hosts.nix; + cynerd-monitoring = import ./monitoring.nix; cynerd-openvpn = import ./openvpn.nix; cynerd-syncthing = import ./syncthing.nix; cynerd-wifi-client = import ./wifi-client.nix; diff --git a/nixos/modules/develop.nix b/nixos/modules/develop.nix index c1c15b2..fa91d02 100644 --- a/nixos/modules/develop.nix +++ b/nixos/modules/develop.nix @@ -59,6 +59,7 @@ in { jinja2 ruamel-yaml msgpack + urllib3 influxdb-client psycopg diff --git a/nixos/modules/monitoring.nix b/nixos/modules/monitoring.nix new file mode 100644 index 0000000..247253e --- /dev/null +++ b/nixos/modules/monitoring.nix @@ -0,0 +1,92 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + +cnf = config.cynerd.monitoring; +hostName = config.networking.hostName; +isHost = cnf.host == hostName; + +in { + options.cynerd.monitoring = { + enable = mkOption { + type = types.bool; + default = true; + description = "If monitoring should be used"; + }; + hw = mkOption { + type = types.bool; + default = true; + description = "If hardware should be reported"; + }; + + host = mkOption { + type = types.str; + description = "Host name of the monitoring hosting system"; + readOnly = true; + }; + }; + + config = mkMerge [ + { cynerd.monitoring.host = "ridcully"; } + (mkIf cnf.enable { + # Telegraf configuration + services.telegraf = { + enable = true; + environmentFiles = ["/run/secrets/telegraf.env"]; + extraConfig = { + agent = {}; + outputs.influxdb_v2 = { + urls = ["http://${cnf.host}:8086"]; + token = "$INFLUX_TOKEN"; + organization = "personal"; + bucket = "monitoring"; + }; + inputs = { + cpu = { + percpu = true; + totalcpu = true; + }; + disk = { + ignore_fs = [ + "tmpfs" "devtmpfs" "devfs" "iso9660" "overlay" "aufs" "squashfs" + ]; + }; + diskio = {}; + diskio = {}; + mem = {}; + net = {}; + processes = {}; + swap = {}; + system = {}; + } // (optionalAttrs cnf.hw { + sensors = {}; + smart = {}; + }); + }; + }; + # TODO probably add this to the upstream configuration + systemd.services.telegraf.path = with pkgs; [ + ] ++ (optionals cnf.hw [ + nvme-cli lm_sensors smartmontools + ]); + }) + (mkIf isHost { + # InfluxDB + services.influxdb2.enable = mkIf isHost true; + # Grafana + services.grafana = mkIf isHost { + enable = true; + settings = { + users.allow_sign_up = false; + security = { + admin_user = "cynerd"; + admin_password = "$__file{/run/secrets/grafana.admin.pass}"; + }; + }; + }; + + }) + ]; +} |