git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #18770 from mayflower/prometheus-alertmanager

Prometheus alertmanager module

commitab40702c9689ec692d16d2b45b5d71dc19b9fe54 authorBenjamin Staffin <benley@gmail.com> dateTue 20 Sep 2016, 19:54 (10 years ago) parent1cb54e3619ab48
3 files changed+144
nixos/modules/module-list.nix+1 nixos/modules/services/monitoring/prometheus/alertmanager.nix+116 nixos/modules/services/monitoring/prometheus/default.nix+27
nixos/modules/module-list.nix+1
@@ -289,6 +289,7 @@
289289 ./services/monitoring/nagios.nix
290290 ./services/monitoring/prometheus/default.nix
291291 ./services/monitoring/prometheus/node-exporter.nix
292+ ./services/monitoring/prometheus/alertmanager.nix
292293 ./services/monitoring/riemann.nix
293294 ./services/monitoring/riemann-dash.nix
294295 ./services/monitoring/riemann-tools.nix
nixos/modules/services/monitoring/prometheus/alertmanager.nixnew file+116
@@ -0,0 +1,116 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.prometheus.alertmanager;
7+ mkConfigFile = pkgs.writeText "alertmanager.yml" (builtins.toJSON cfg.configuration);
8+in {
9+ options = {
10+ services.prometheus.alertmanager = {
11+ enable = mkEnableOption "Prometheus Alertmanager";
12+
13+ user = mkOption {
14+ type = types.str;
15+ default = "nobody";
16+ description = ''
17+ User name under which Alertmanager shall be run.
18+ '';
19+ };
20+
21+ group = mkOption {
22+ type = types.str;
23+ default = "nogroup";
24+ description = ''
25+ Group under which Alertmanager shall be run.
26+ '';
27+ };
28+
29+ configuration = mkOption {
30+ type = types.attrs;
31+ default = {};
32+ description = ''
33+ Alertmanager configuration as nix attribute set.
34+ '';
35+ };
36+
37+ logFormat = mkOption {
38+ type = types.nullOr types.str;
39+ default = null;
40+ description = ''
41+ If set use a syslog logger or JSON logging.
42+ '';
43+ };
44+
45+ logLevel = mkOption {
46+ type = types.enum ["debug" "info" "warn" "error" "fatal"];
47+ default = "warn";
48+ description = ''
49+ Only log messages with the given severity or above.
50+ '';
51+ };
52+
53+ webExternalUrl = mkOption {
54+ type = types.nullOr types.str;
55+ default = null;
56+ description = ''
57+ The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy).
58+ Used for generating relative and absolute links back to Alertmanager itself.
59+ If the URL has a path portion, it will be used to prefix all HTTP endoints served by Alertmanager.
60+ If omitted, relevant URL components will be derived automatically.
61+ '';
62+ };
63+
64+ listenAddress = mkOption {
65+ type = types.nullOr types.str;
66+ default = null;
67+ description = ''
68+ Address to listen on for the web interface and API.
69+ '';
70+ };
71+
72+ port = mkOption {
73+ type = types.int;
74+ default = 9093;
75+ description = ''
76+ Port to listen on for the web interface and API.
77+ '';
78+ };
79+
80+ openFirewall = mkOption {
81+ type = types.bool;
82+ default = false;
83+ description = ''
84+ Open port in firewall for incoming connections.
85+ '';
86+ };
87+ };
88+ };
89+
90+
91+ config = mkIf cfg.enable {
92+ networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
93+
94+ systemd.services.alertmanager = {
95+ wantedBy = [ "multi-user.target" ];
96+ after = [ "network.target" ];
97+ script = ''
98+ ${pkgs.prometheus-alertmanager.bin}/bin/alertmanager \
99+ -config.file ${mkConfigFile} \
100+ -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
101+ -log.level ${cfg.logLevel} \
102+ ${optionalString (cfg.webExternalUrl != null) ''-web.external-url ${cfg.webExternalUrl} \''}
103+ ${optionalString (cfg.logFormat != null) "-log.format ${cfg.logFormat}"}
104+ '';
105+
106+ serviceConfig = {
107+ User = cfg.user;
108+ Group = cfg.group;
109+ Restart = "always";
110+ PrivateTmp = true;
111+ WorkingDirectory = "/tmp";
112+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
113+ };
114+ };
115+ };
116+}
nixos/modules/services/monitoring/prometheus/default.nix+27
@@ -29,6 +29,9 @@ let
2929 "-storage.local.path=${cfg.dataDir}/metrics"
3030 "-config.file=${writePrettyJSON "prometheus.yml" promConfig}"
3131 "-web.listen-address=${cfg.listenAddress}"
32+ "-alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}"
33+ "-alertmanager.timeout=${toString cfg.alertmanagerTimeout}s"
34+ (optionalString (cfg.alertmanagerURL != []) "-alertmanager.url=${concatStringsSep "," cfg.alertmanagerURL}")
3235 ];
3336
3437 promTypes.globalConfig = types.submodule {
@@ -388,6 +391,30 @@ in {
388391 A list of scrape configurations.
389392 '';
390393 };
394+
395+ alertmanagerURL = mkOption {
396+ type = types.listOf types.str;
397+ default = [];
398+ description = ''
399+ List of Alertmanager URLs to send notifications to.
400+ '';
401+ };
402+
403+ alertmanagerNotificationQueueCapacity = mkOption {
404+ type = types.int;
405+ default = 10000;
406+ description = ''
407+ The capacity of the queue for pending alert manager notifications.
408+ '';
409+ };
410+
411+ alertmanagerTimeout = mkOption {
412+ type = types.int;
413+ default = 10;
414+ description = ''
415+ Alert manager HTTP API timeout (in seconds).
416+ '';
417+ };
391418 };
392419 };
393420