Enable Mimir Alertmanager, add example alert

Still TODO: actually connect it to Matrix
This commit is contained in:
Ilya K 2024-07-07 17:05:48 +03:00
parent 5ebd71e4d5
commit e8e262c6a4
2 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,5 @@
groups:
- name: Demo alerts
rules:
- alert: Demo alert
expr: 1

View file

@ -2,6 +2,7 @@
config,
lib,
nodes,
pkgs,
...
}:
let
@ -26,6 +27,8 @@ let
};
jobConfigs = map toJobConfig scrapableMetas;
mimirPort = config.services.mimir.configuration.server.http_listen_port;
in
{
options.bagel.services.prometheus.enable = mkEnableOption "Prometheus scraper";
@ -41,7 +44,7 @@ in
globalConfig.scrape_interval = "15s";
scrapeConfigs = jobConfigs;
remoteWrite = [
{ url = "http://localhost:9009/api/v1/push"; }
{ url = "http://localhost:${toString mimirPort}/api/v1/push"; }
];
};
@ -49,6 +52,8 @@ in
enable = true;
extraFlags = ["--config.expand-env=true"];
configuration = {
target = "all,alertmanager";
multitenancy_enabled = false;
common.storage = {
@ -73,11 +78,40 @@ in
blocks_storage.backend = "s3";
ruler_storage = {
backend = "local";
local.directory = ./alerts;
local.directory = pkgs.runCommand "mimir-rules" {} ''
mkdir -p $out
ln -s ${./alerts} $out/anonymous
'';
};
alertmanager = {
sharding_ring.replication_factor = 1;
fallback_config_file = pkgs.writers.writeYAML "alertmanager.yaml" {
route = {
group_by = ["alertname"];
receiver = "matrix";
};
receivers = [
{
name = "matrix";
}
];
};
};
alertmanager_storage.backend = "filesystem";
ruler.alertmanager_url = "http://localhost:${toString mimirPort}/alertmanager";
};
};
systemd.services.mimir.serviceConfig.EnvironmentFile = [ config.age.secrets.mimir-environment.path ];
services.nginx.virtualHosts."mimir.forkos.org" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${toString mimirPort}";
};
};
};
}