git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #65088 from WilliButz/prometheus-exporters-cleanup

prometheus-nginx-exporter: switch to official version & general prometheus-exporters cleanup

commitd893a9acf8d8727b2907987c064206dcc89f3fb5 authorFranz Pletz <fpletz@fnordicwalking.de> dateMon 22 Jul 2019, 15:03 (7 years ago) parent95be462294bed6
23 files changed+129−184
nixos/doc/manual/release-notes/rl-1909.xml+7 nixos/modules/services/monitoring/prometheus/exporters.nix+32−24 nixos/modules/services/monitoring/prometheus/exporters.xml+39−1 nixos/modules/services/monitoring/prometheus/exporters/bind.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/blackbox.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/collectd.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/dnsmasq.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/dovecot.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/fritzbox.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/json.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/minio.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/nginx.nix+17−9 nixos/modules/services/monitoring/prometheus/exporters/node.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/postfix.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/snmp.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/surfboard.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/tor.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/unifi.nix+1−1 nixos/modules/services/monitoring/prometheus/exporters/varnish.nix+1−2 nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix+1−1 nixos/tests/prometheus-exporters.nix+6−4 pkgs/servers/monitoring/prometheus/nginx-exporter.nix+12−10 pkgs/servers/monitoring/prometheus/nginx-exporter_deps.nix−119
nixos/doc/manual/release-notes/rl-1909.xml+7
@@ -195,6 +195,13 @@
195195 <xref linkend="opt-programs.zsh.loginShellInit" /> and <xref linkend="opt-programs.zsh.promptInit" /> may break if it relies on those options being set.
196196 </para>
197197 </listitem>
198+ <listitem>
199+ <para>
200+ The <literal>prometheus-nginx-exporter</literal> package now uses the offical exporter provided by NGINX Inc.
201+ Its metrics are differently structured and are incompatible to the old ones. For information about the metrics,
202+ have a look at the <link xlink:href="https://github.com/nginxinc/nginx-prometheus-exporter">official repo</link>.
203+ </para>
204+ </listitem>
198205 </itemizedlist>
199206 </section>
200207
nixos/modules/services/monitoring/prometheus/exporters.nix+32−24
@@ -1,8 +1,10 @@
1−{ config, pkgs, lib, ... }:
2−
3−with lib;
1+{ config, pkgs, lib, options, ... }:
42
53let
4+ inherit (lib) concatStrings foldl foldl' genAttrs literalExample maintainers
5+ mapAttrsToList mkDefault mkEnableOption mkIf mkMerge mkOption
6+ optional types;
7+
68 cfg = config.services.prometheus.exporters;
79
810 # each attribute in `exporterOpts` is expected to have specified:
@@ -17,25 +19,28 @@ let
1719 # Note that `extraOpts` is optional, but a script for the exporter's
1820 # systemd service must be provided by specifying either
1921 # `serviceOpts.script` or `serviceOpts.serviceConfig.ExecStart`
20− exporterOpts = {
21− blackbox = import ./exporters/blackbox.nix { inherit config lib pkgs; };
22− collectd = import ./exporters/collectd.nix { inherit config lib pkgs; };
23− dnsmasq = import ./exporters/dnsmasq.nix { inherit config lib pkgs; };
24− dovecot = import ./exporters/dovecot.nix { inherit config lib pkgs; };
25− fritzbox = import ./exporters/fritzbox.nix { inherit config lib pkgs; };
26− json = import ./exporters/json.nix { inherit config lib pkgs; };
27− minio = import ./exporters/minio.nix { inherit config lib pkgs; };
28− nginx = import ./exporters/nginx.nix { inherit config lib pkgs; };
29− node = import ./exporters/node.nix { inherit config lib pkgs; };
30− postfix = import ./exporters/postfix.nix { inherit config lib pkgs; };
31− snmp = import ./exporters/snmp.nix { inherit config lib pkgs; };
32− surfboard = import ./exporters/surfboard.nix { inherit config lib pkgs; };
33− tor = import ./exporters/tor.nix { inherit config lib pkgs; };
34− unifi = import ./exporters/unifi.nix { inherit config lib pkgs; };
35− varnish = import ./exporters/varnish.nix { inherit config lib pkgs; };
36− bind = import ./exporters/bind.nix { inherit config lib pkgs; };
37− wireguard = import ./exporters/wireguard.nix { inherit config lib pkgs; };
38− };
22+
23+ exporterOpts = genAttrs [
24+ "bind"
25+ "blackbox"
26+ "collectd"
27+ "dnsmasq"
28+ "dovecot"
29+ "fritzbox"
30+ "json"
31+ "minio"
32+ "nginx"
33+ "node"
34+ "postfix"
35+ "snmp"
36+ "surfboard"
37+ "tor"
38+ "unifi"
39+ "varnish"
40+ "wireguard"
41+ ] (name:
42+ import (./. + "/exporters/${name}.nix") { inherit config lib pkgs options; }
43+ );
3944
4045 mkExporterOpts = ({ name, port }: {
4146 enable = mkEnableOption "the prometheus ${name} exporter";
@@ -97,9 +102,10 @@ let
97102 };
98103 });
99104
100− mkSubModule = { name, port, extraOpts, ... }: {
105+ mkSubModule = { name, port, extraOpts, imports }: {
101106 ${name} = mkOption {
102107 type = types.submodule {
108+ inherit imports;
103109 options = (mkExporterOpts {
104110 inherit name port;
105111 } // extraOpts);
@@ -112,13 +118,15 @@ let
112118 mkSubModules = (foldl' (a: b: a//b) {}
113119 (mapAttrsToList (name: opts: mkSubModule {
114120 inherit name;
115− inherit (opts) port serviceOpts;
121+ inherit (opts) port;
116122 extraOpts = opts.extraOpts or {};
123+ imports = opts.imports or [];
117124 }) exporterOpts)
118125 );
119126
120127 mkExporterConf = { name, conf, serviceOpts }:
121128 mkIf conf.enable {
129+ warnings = conf.warnings or [];
122130 networking.firewall.extraCommands = mkIf conf.openFirewall (concatStrings [
123131 "ip46tables -A nixos-fw ${conf.firewallFilter} "
124132 "-m comment --comment ${name}-exporter -j nixos-fw-accept"
nixos/modules/services/monitoring/prometheus/exporters.xml+39−1
@@ -113,7 +113,7 @@
113113 specific options and configuration:
114114<programlisting>
115115# nixpgs/nixos/modules/services/prometheus/exporters/postfix.nix
116−{ config, lib, pkgs }:
116+{ config, lib, pkgs, options }:
117117
118118with lib;
119119
@@ -184,4 +184,42 @@ in
184184 </listitem>
185185 </itemizedlist>
186186 </section>
187+ <section xml:id="module-services-prometheus-exporters-update-exporter-module">
188+ <title>Updating an exporter module</title>
189+ <para>
190+ Should an exporter option change at some point, it is possible to add
191+ information about the change to the exporter definition similar to
192+ <literal>nixpkgs/nixos/modules/rename.nix</literal>:
193+<programlisting>
194+{ config, lib, pkgs, options }:
195+
196+with lib;
197+
198+let
199+ cfg = config.services.prometheus.exporters.nginx;
200+in
201+{
202+ port = 9113;
203+ extraOpts = {
204+ # additional module options
205+ # ...
206+ };
207+ serviceOpts = {
208+ # service configuration
209+ # ...
210+ };
211+ imports = [
212+ # 'services.prometheus.exporters.nginx.telemetryEndpoint' -> 'services.prometheus.exporters.nginx.telemetryPath'
213+ (mkRenamedOptionModule [ "telemetryEndpoint" ] [ "telemetryPath" ])
214+
215+ # removed option 'services.prometheus.exporters.nginx.insecure'
216+ (mkRemovedOptionModule [ "insecure" ] ''
217+ This option was replaced by 'prometheus.exporters.nginx.sslVerify' which defaults to true.
218+ '')
219+ ({ options.warnings = options.warnings; })
220+ ];
221+}
222+</programlisting>
223+ </para>
224+ </section>
187225</chapter>
nixos/modules/services/monitoring/prometheus/exporters/bind.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/blackbox.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/collectd.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/dnsmasq.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/dovecot.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/fritzbox.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/json.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/minio.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/nginx.nix+17−9
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
@@ -16,32 +16,40 @@ in
1616 Can be enabled with services.nginx.statusPage = true.
1717 '';
1818 };
19− telemetryEndpoint = mkOption {
19+ telemetryPath = mkOption {
2020 type = types.str;
2121 default = "/metrics";
2222 description = ''
2323 Path under which to expose metrics.
2424 '';
2525 };
26− insecure = mkOption {
26+ sslVerify = mkOption {
2727 type = types.bool;
2828 default = true;
2929 description = ''
30− Ignore server certificate if using https.
30+ Whether to perform certificate verification for https.
3131 '';
3232 };
33+
3334 };
3435 serviceOpts = {
3536 serviceConfig = {
3637 DynamicUser = true;
3738 ExecStart = ''
38− ${pkgs.prometheus-nginx-exporter}/bin/nginx_exporter \
39− --nginx.scrape_uri '${cfg.scrapeUri}' \
40− --telemetry.address ${cfg.listenAddress}:${toString cfg.port} \
41− --telemetry.endpoint ${cfg.telemetryEndpoint} \
42− --insecure ${toString cfg.insecure} \
39+ ${pkgs.prometheus-nginx-exporter}/bin/nginx-prometheus-exporter \
40+ --nginx.scrape-uri '${cfg.scrapeUri}' \
41+ --nginx.ssl-verify ${toString cfg.sslVerify} \
42+ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
43+ --web.telemetry-path ${cfg.telemetryPath} \
4344 ${concatStringsSep " \\\n " cfg.extraFlags}
4445 '';
4546 };
4647 };
48+ imports = [
49+ (mkRenamedOptionModule [ "telemetryEndpoint" ] [ "telemetryPath" ])
50+ (mkRemovedOptionModule [ "insecure" ] ''
51+ This option was replaced by 'prometheus.exporters.nginx.sslVerify'.
52+ '')
53+ ({ options.warnings = options.warnings; })
54+ ];
4755}
nixos/modules/services/monitoring/prometheus/exporters/node.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/postfix.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/snmp.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/surfboard.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/tor.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/unifi.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/modules/services/monitoring/prometheus/exporters/varnish.nix+1−2
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
@@ -68,7 +68,6 @@ in
6868 serviceOpts = {
6969 path = [ pkgs.varnish ];
7070 serviceConfig = {
71− DynamicUser = true;
7271 RestartSec = mkDefault 1;
7372 ExecStart = ''
7473 ${pkgs.prometheus-varnish-exporter}/bin/prometheus_varnish_exporter \
nixos/modules/services/monitoring/prometheus/exporters/wireguard.nix+1−1
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs }:
1+{ config, lib, pkgs, options }:
22
33with lib;
44
nixos/tests/prometheus-exporters.nix+6−4
@@ -3,10 +3,11 @@
33, pkgs ? import ../.. { inherit system config; }
44}:
55
6−with pkgs.lib;
7−with import ../lib/testing.nix { inherit system pkgs; };
8−
96let
7+ inherit (import ../lib/testing.nix { inherit system pkgs; }) makeTest;
8+ inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge
9+ removeSuffix replaceChars singleton splitString;
10+
1011 escape' = str: replaceChars [''"'' "$" "\n"] [''\\\"'' "\\$" ""] str;
1112
1213/*
@@ -73,7 +74,7 @@ let
7374 exporterTest = ''
7475 waitForUnit("prometheus-bind-exporter.service");
7576 waitForOpenPort(9119);
76− succeed("curl -sSf http://localhost:9119/metrics" | grep -q 'bind_query_recursions_total 0');
77+ succeed("curl -sSf http://localhost:9119/metrics | grep -q 'bind_query_recursions_total 0'");
7778 '';
7879 };
7980
@@ -311,6 +312,7 @@ let
311312 };
312313 exporterTest = ''
313314 waitForUnit("prometheus-varnish-exporter.service");
315+ waitForOpenPort(6081);
314316 waitForOpenPort(9131);
315317 succeed("curl -sSf http://localhost:9131/metrics | grep -q 'varnish_up 1'");
316318 '';
pkgs/servers/monitoring/prometheus/nginx-exporter.nix+12−10
@@ -2,23 +2,25 @@
22
33buildGoPackage rec {
44 name = "nginx_exporter-${version}";
5− version = "0.1.0";
5+ version = "0.4.1";
66
7− goPackagePath = "github.com/discordianfish/nginx_exporter";
7+ goPackagePath = "github.com/nginxinc/nginx-prometheus-exporter";
8+
9+ buildFlagsArray = [
10+ "-ldflags=" "-X main.version=${version}"
11+ ];
812
913 src = fetchFromGitHub {
1014 rev = "v${version}";
11− owner = "discordianfish";
12− repo = "nginx_exporter";
13− sha256 = "1xwxnvkzslaj44r44ag24a9qfzjdxwz67hhpkdq42193zqpnlim7";
15+ owner = "nginxinc";
16+ repo = "nginx-prometheus-exporter";
17+ sha256 = "0c5bxl9xrd4gh2w5wyrzghmbcy9k1khydzml5cm0rsyqhwsvs8m5";
1418 };
1519
16− goDeps = ./nginx-exporter_deps.nix;
17−
1820 meta = with stdenv.lib; {
19− description = "Metrics relay from nginx stats to Prometheus";
20− homepage = https://github.com/discordianfish/nginx_exporter;
21− license = licenses.mit;
21+ description = "NGINX Prometheus Exporter for NGINX and NGINX Plus";
22+ homepage = "https://github.com/nginxinc/nginx-prometheus-exporter";
23+ license = licenses.asl20;
2224 maintainers = with maintainers; [ benley fpletz willibutz ];
2325 platforms = platforms.unix;
2426 };
pkgs/servers/monitoring/prometheus/nginx-exporter_deps.nixdeleted−119
@@ -1,119 +0,0 @@
1−[
2− {
3− goPackagePath = "github.com/alecthomas/template";
4− fetch = {
5− type = "git";
6− url = "https://github.com/alecthomas/template";
7− rev = "a0175ee3bccc567396460bf5acd36800cb10c49c";
8− sha256 = "0qjgvvh26vk1cyfq9fadyhfgdj36f1iapbmr5xp6zqipldz8ffxj";
9− };
10− }
11− {
12− goPackagePath = "github.com/alecthomas/units";
13− fetch = {
14− type = "git";
15− url = "https://github.com/alecthomas/units";
16− rev = "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a";
17− sha256 = "1j65b91qb9sbrml9cpabfrcf07wmgzzghrl7809hjjhrmbzri5bl";
18− };
19− }
20− {
21− goPackagePath = "github.com/beorn7/perks";
22− fetch = {
23− type = "git";
24− url = "https://github.com/beorn7/perks";
25− rev = "3a771d992973f24aa725d07868b467d1ddfceafb";
26− sha256 = "1l2lns4f5jabp61201sh88zf3b0q793w4zdgp9nll7mmfcxxjif3";
27− };
28− }
29− {
30− goPackagePath = "github.com/golang/protobuf";
31− fetch = {
32− type = "git";
33− url = "https://github.com/golang/protobuf";
34− rev = "b4deda0973fb4c70b50d226b1af49f3da59f5265";
35− sha256 = "0ya4ha7m20bw048m1159ppqzlvda4x0vdprlbk5sdgmy74h3xcdq";
36− };
37− }
38− {
39− goPackagePath = "github.com/matttproud/golang_protobuf_extensions";
40− fetch = {
41− type = "git";
42− url = "https://github.com/matttproud/golang_protobuf_extensions";
43− rev = "c12348ce28de40eed0136aa2b644d0ee0650e56c";
44− sha256 = "1d0c1isd2lk9pnfq2nk0aih356j30k3h1gi2w0ixsivi5csl7jya";
45− };
46− }
47− {
48− goPackagePath = "github.com/prometheus/client_golang";
49− fetch = {
50− type = "git";
51− url = "https://github.com/prometheus/client_golang";
52− rev = "82f5ff156b29e276022b1a958f7d385870fb9814";
53− sha256 = "111j329yrlgvh73dm80gawwxsh9dgjkw74254kyj5c2rfmra7znz";
54− };
55− }
56− {
57− goPackagePath = "github.com/prometheus/client_model";
58− fetch = {
59− type = "git";
60− url = "https://github.com/prometheus/client_model";
61− rev = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c";
62− sha256 = "19y4ywsivhpxj7ikf2j0gm9k3cmyw37qcbfi78n526jxcc7kw998";
63− };
64− }
65− {
66− goPackagePath = "github.com/prometheus/common";
67− fetch = {
68− type = "git";
69− url = "https://github.com/prometheus/common";
70− rev = "d811d2e9bf898806ecfb6ef6296774b13ffc314c";
71− sha256 = "0r4067r4ysmljksqw3awcxx5qplqhykahc5igdzgkky7i4bvaik1";
72− };
73− }
74− {
75− goPackagePath = "github.com/prometheus/procfs";
76− fetch = {
77− type = "git";
78− url = "https://github.com/prometheus/procfs";
79− rev = "8b1c2da0d56deffdbb9e48d4414b4e674bd8083e";
80− sha256 = "0x128p15h35mgwqxkigfkk1lfrcz9g697ahl8v6xp9kwvcqvjrrf";
81− };
82− }
83− {
84− goPackagePath = "github.com/sirupsen/logrus";
85− fetch = {
86− type = "git";
87− url = "https://github.com/sirupsen/logrus";
88− rev = "778f2e774c725116edbc3d039dc0dfc1cc62aae8";
89− sha256 = "0drlrl192k4qkpcf1b6nw2qlixply31x2jhcckjzl3hn4mzwi6nf";
90− };
91− }
92− {
93− goPackagePath = "golang.org/x/crypto";
94− fetch = {
95− type = "git";
96− url = "https://go.googlesource.com/crypto";
97− rev = "ae8bce0030810cf999bb2b9868ae5c7c58e6343b";
98− sha256 = "0aihwcf0g8mq1sb96pwhpgvwxlf862pdhsfr7mdppz7bii4i9shw";
99− };
100− }
101− {
102− goPackagePath = "golang.org/x/sys";
103− fetch = {
104− type = "git";
105− url = "https://go.googlesource.com/sys";
106− rev = "78d5f264b493f125018180c204871ecf58a2dce1";
107− sha256 = "0x23n60wskys39dwybz5za77ldky9i518kp58ragpd5528kcc68s";
108− };
109− }
110− {
111− goPackagePath = "gopkg.in/alecthomas/kingpin.v2";
112− fetch = {
113− type = "git";
114− url = "https://gopkg.in/alecthomas/kingpin.v2";
115− rev = "947dcec5ba9c011838740e680966fd7087a71d0d";
116− sha256 = "0mndnv3hdngr3bxp7yxfd47cas4prv98sqw534mx7vp38gd88n5r";
117− };
118− }
119−]