From 6260246b4afdc5231a50209b048a92ba5b4028ea Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 7 Jan 2022 12:37:37 +0100 Subject: vidhar: ... --- hosts/vidhar/default.nix | 32 +++++++++++++++++--------------- hosts/vidhar/prometheus/default.nix | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'hosts/vidhar') diff --git a/hosts/vidhar/default.nix b/hosts/vidhar/default.nix index 2e2c9946..ad40b903 100644 --- a/hosts/vidhar/default.nix +++ b/hosts/vidhar/default.nix @@ -182,7 +182,7 @@ enable_api = true; storage = { type = "local"; - local.directory = "/etc/loki/rules"; + local.directory = "${config.services.loki.dataDir}/rules"; }; rule_path = "${config.services.loki.dataDir}/rules-temp"; remote_write = { @@ -204,20 +204,22 @@ ]; }; }; - environment.etc."loki/rules/rules.yml".text = lib.generators.toYAML {} { - groups = [ - { name = "power-failures"; - rules = [ - { record = "apcupsd_power_failures:rate_1d"; - expr = "sum by (nodename) (rate({job=\"systemd-journal\"} | json | MESSAGE = \"Power failure.\"[1d])) * 86400"; - } - { record = "apcupsd_power_failures:per_week"; - expr = "sum by (nodename) (rate({job=\"systemd-journal\"} | json | MESSAGE = \"Power failure.\"[1w])) * 604800"; - } - ]; - } - ]; - }; + systemd.services.loki.preStart = let + rulesYaml = lib.generators.toYAML {} { + groups = [ + { name = "power-failures"; + rules = [ + { record = "apcupsd_power_failures:rate_1d"; + expr = "sum by (nodename) (rate({job=\"systemd-journal\"} | json | MESSAGE = \"Power failure.\"[1d])) * 86400"; + } + { record = "apcupsd_power_failures:per_week"; + expr = "sum by (nodename) (rate({job=\"systemd-journal\"} | json | MESSAGE = \"Power failure.\"[1w])) * 604800"; + } + ]; + } + ]; + }; + in "${pkgs.coreutils}/bin/install -m 0644 -o ${config.services.loki.user} -m ${config.services.loki.group} --target-directory=${services.loki.configuration.ruler.storage.local.directory} ${pkgs.writeText "rules.yml" rulesYaml}"; services.promtail = { enable = true; configuration = { diff --git a/hosts/vidhar/prometheus/default.nix b/hosts/vidhar/prometheus/default.nix index f4e8d7e5..d443e991 100644 --- a/hosts/vidhar/prometheus/default.nix +++ b/hosts/vidhar/prometheus/default.nix @@ -221,7 +221,7 @@ in { { record = "apcupsd_last_transfer_on_battery_counter_seconds:resets_per_day"; expr = "resets(apcupsd_last_transfer_on_battery_counter_seconds[1d])"; } - { record = "apcupsd_last_transfer_on_battery_counter_seconds:resets_per_wook"; + { record = "apcupsd_last_transfer_on_battery_counter_seconds:resets_per_week"; expr = "resets(apcupsd_last_transfer_on_battery_counter_seconds[1w])"; } ]; -- cgit v1.2.3