From 1dc04e92b29c3ba2135bd893dc1d9ab22f9233cd Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Thu, 10 Oct 2024 12:43:33 +0500 Subject: [PATCH] catarina: metrics --- nixosConfigurations/catarina/default.nix | 1 + .../catarina/services/gitea.nix | 4 + .../catarina/services/metrics.nix | 123 ++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 nixosConfigurations/catarina/services/metrics.nix diff --git a/nixosConfigurations/catarina/default.nix b/nixosConfigurations/catarina/default.nix index de4dae8..f5430a5 100644 --- a/nixosConfigurations/catarina/default.nix +++ b/nixosConfigurations/catarina/default.nix @@ -14,6 +14,7 @@ ./services/gitea.nix ./services/radio.nix ./services/matrix.nix + ./services/metrics.nix ]; # Nix settings diff --git a/nixosConfigurations/catarina/services/gitea.nix b/nixosConfigurations/catarina/services/gitea.nix index 258639c..992a698 100644 --- a/nixosConfigurations/catarina/services/gitea.nix +++ b/nixosConfigurations/catarina/services/gitea.nix @@ -55,6 +55,10 @@ indexer = { REPO_INDEXER_ENABLED = true; }; + + metrics = { + ENABLED = true; + }; }; mailerPasswordFile = config.sops.secrets."gitea/mail".path; diff --git a/nixosConfigurations/catarina/services/metrics.nix b/nixosConfigurations/catarina/services/metrics.nix new file mode 100644 index 0000000..229f8ab --- /dev/null +++ b/nixosConfigurations/catarina/services/metrics.nix @@ -0,0 +1,123 @@ +{ + config, + pkgs, + ... +}: { + services.grafana = { + enable = true; + settings.server = { + domain = "grafana.elnafo.ru"; + http_port = 2342; + http_addr = "127.0.0.1"; + }; + }; + + services.prometheus = { + enable = true; + port = 9090; + globalConfig.scrape_interval = "10s"; # "1m" + + exporters = { + node = { + enable = true; + enabledCollectors = ["systemd"]; + port = 9092; + }; + }; + scrapeConfigs = [ + { + job_name = "catarina"; + static_configs = [ + { + targets = ["127.0.0.1:${toString config.services.prometheus.exporters.node.port}"]; + } + ]; + } + ]; + }; + + services.loki = { + enable = true; + configuration = { + auth_enabled = false; + server = { + http_listen_port = 3100; + }; + common = { + ring = { + instance_addr = "127.0.0.1"; + kvstore = { + store = "inmemory"; + }; + }; + replication_factor = 1; + path_prefix = "/tmp/loki"; + }; + schema_config = { + configs = [ + { + from = "2020-05-15"; + store = "tsdb"; + object_store = "filesystem"; + schema = "v13"; + index = { + prefix = "index_"; + period = "24h"; + }; + } + ]; + }; + storage_config = { + filesystem = { + directory = "/tmp/loki/chunks"; + }; + }; + }; + }; + + services.promtail = { + enable = true; + configuration = { + server = { + http_listen_port = 3101; + grpc_listen_port = 0; + }; + clients = [ + { + url = "http://127.0.0.1:3100/loki/api/v1/push"; + } + ]; + scrape_configs = [ + { + job_name = "journal"; + journal = { + max_age = "12h"; + labels = { + job = "systemd-journal"; + host = "catarina"; + }; + }; + relabel_configs = [ + { + source_labels = [ + "__journal__systemd_unit" + ]; + target_label = "unit"; + } + ]; + } + ]; + }; + }; + + services.nginx = { + virtualHosts."grafana.elnafo.ru" = { + forceSSL = true; + useACMEHost = "elnafo.ru"; + locations."/" = { + proxyPass = "http://127.0.0.1:${toString config.services.grafana.port}"; + proxyWebsockets = true; + }; + }; + }; +}