diff --git a/common/general/default.nix b/common/general/default.nix index 0e882e8..c172e28 100644 --- a/common/general/default.nix +++ b/common/general/default.nix @@ -57,6 +57,7 @@ in ./shell/common.nix ./fonts.nix ./tty_caps_esc.nix + ./reporting.nix ]; config = { # name this computer diff --git a/common/general/reporting.nix b/common/general/reporting.nix new file mode 100644 index 0000000..8042c3d --- /dev/null +++ b/common/general/reporting.nix @@ -0,0 +1,74 @@ +{ + lib, + config, + ... +}: +let + ccfg = import ../config.nix; + cfg_path = [ + ccfg.custom_config_key + "reporting" + ]; + cfg = lib.attrsets.getAttrFromPath cfg_path config; +in +{ + options = + { } + // lib.attrsets.setAttrByPath cfg_path { + enable = lib.mkEnabledOption true "Reporting node and logs"; + }; + + config = lib.mkIf cfg.enable { + services.prometheus.exporters.node = { + enable = true; + port = 9100; + }; + + # Create necessary directories with appropriate permissions + systemd.tmpfiles.rules = [ + "d /tmp/positions 1777 - - -" # World-writable directory for positions file + "f /tmp/positions.yaml 0666 - - -" # World-writable positions file + ]; + users.groups.systemd-journal.members = [ "promtail" ]; + services.promtail = { + enable = true; + extraFlags = [ + "-config.expand-env=true" + ]; + configuration = { + server = { + http_listen_port = 9080; + grpc_listen_port = 0; + }; + positions = { + filename = "/tmp/positions.yaml"; # Changed from /var/lib/promtail/positions.yaml + }; + clients = [ + { + url = "http://100.64.0.13:3100/loki/api/v1/push"; # Points to your Loki instance + } + ]; + scrape_configs = [ + { + job_name = "journal"; + journal = { + json = false; + max_age = "12h"; + path = "/var/log/journal"; + labels = { + job = "systemd-journal"; + host = config.networking.hostName; + }; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + } + ]; + } + ]; + }; + }; + }; +}