···
1
-
<chapter xmlns="http://docbook.org/ns/docbook"
2
-
xmlns:xlink="http://www.w3.org/1999/xlink"
3
-
xmlns:xi="http://www.w3.org/2001/XInclude"
5
-
xml:id="module-services-prometheus-exporters">
6
-
<title>Prometheus exporters</title>
8
-
Prometheus exporters provide metrics for the
9
-
<link xlink:href="https://prometheus.io">prometheus monitoring system</link>.
11
-
<section xml:id="module-services-prometheus-exporters-configuration">
12
-
<title>Configuration</title>
1
+
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="module-services-prometheus-exporters">
2
+
<title>Prometheus exporters</title>
15
-
One of the most common exporters is the
16
-
<link xlink:href="https://github.com/prometheus/node_exporter">node
17
-
exporter</link>, it provides hardware and OS metrics from the host it's
18
-
running on. The exporter could be configured as follows:
4
+
Prometheus exporters provide metrics for the
5
+
<link xlink:href="https://prometheus.io">prometheus monitoring
8
+
<section xml:id="module-services-prometheus-exporters-configuration">
9
+
<title>Configuration</title>
11
+
One of the most common exporters is the
12
+
<link xlink:href="https://github.com/prometheus/node_exporter">node
13
+
exporter</link>, it provides hardware and OS metrics from the host
14
+
it's running on. The exporter could be configured as follows:
services.prometheus.exporters.node = {
25
+
"textfile"
31
-
firewallFilter = "-i br0 -p tcp -m tcp --dport 9100";
28
+
firewallFilter = "-i br0 -p tcp -m tcp --dport 9100";
34
-
It should now serve all metrics from the collectors that are explicitly
35
-
enabled and the ones that are
36
-
<link xlink:href="https://github.com/prometheus/node_exporter#enabled-by-default">enabled
37
-
by default</link>, via http under <literal>/metrics</literal>. In this
38
-
example the firewall should just allow incoming connections to the
39
-
exporter's port on the bridge interface <literal>br0</literal> (this would
40
-
have to be configured separately of course). For more information about
41
-
configuration see <literal>man configuration.nix</literal> or search through
43
-
<link xlink:href="https://nixos.org/nixos/options.html#prometheus.exporters">available
48
-
Prometheus can now be configured to consume the metrics produced by the exporter:
32
+
It should now serve all metrics from the collectors that are
33
+
explicitly enabled and the ones that are
34
+
<link xlink:href="https://github.com/prometheus/node_exporter#enabled-by-default">enabled
35
+
by default</link>, via http under <literal>/metrics</literal>. In
36
+
this example the firewall should just allow incoming connections
37
+
to the exporter's port on the bridge interface
38
+
<literal>br0</literal> (this would have to be configured
39
+
separately of course). For more information about configuration
40
+
see <literal>man configuration.nix</literal> or search through the
41
+
<link xlink:href="https://nixos.org/nixos/options.html#prometheus.exporters">available
45
+
Prometheus can now be configured to consume the metrics produced
54
+
job_name = "node";
57
-
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
56
+
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
67
-
<section xml:id="module-services-prometheus-exporters-new-exporter">
68
-
<title>Adding a new exporter</title>
71
-
To add a new exporter, it has to be packaged first (see
72
-
<literal>nixpkgs/pkgs/servers/monitoring/prometheus/</literal> for
73
-
examples), then a module can be added. The postfix exporter is used in this
65
+
<section xml:id="module-services-prometheus-exporters-new-exporter">
66
+
<title>Adding a new exporter</title>
80
-
Some default options for all exporters are provided by
81
-
<literal>nixpkgs/nixos/modules/services/monitoring/prometheus/exporters.nix</literal>:
68
+
To add a new exporter, it has to be packaged first (see
69
+
<literal>nixpkgs/pkgs/servers/monitoring/prometheus/</literal> for
70
+
examples), then a module can be added. The postfix exporter is
71
+
used in this example:
84
-
<listitem override='none'>
88
-
<literal>enable</literal>
93
-
<literal>port</literal>
98
-
<literal>listenAddress</literal>
103
-
<literal>extraFlags</literal>
108
-
<literal>openFirewall</literal>
113
-
<literal>firewallFilter</literal>
118
-
<literal>user</literal>
123
-
<literal>group</literal>
130
-
As there is already a package available, the module can now be added. This
131
-
is accomplished by adding a new file to the
132
-
<literal>nixos/modules/services/monitoring/prometheus/exporters/</literal>
133
-
directory, which will be called postfix.nix and contains all exporter
134
-
specific options and configuration:
76
+
Some default options for all exporters are provided by
77
+
<literal>nixpkgs/nixos/modules/services/monitoring/prometheus/exporters.nix</literal>:
79
+
<itemizedlist spacing="compact">
82
+
<literal>enable</literal>
87
+
<literal>port</literal>
92
+
<literal>listenAddress</literal>
97
+
<literal>extraFlags</literal>
102
+
<literal>openFirewall</literal>
107
+
<literal>firewallFilter</literal>
112
+
<literal>user</literal>
117
+
<literal>group</literal>
124
+
As there is already a package available, the module can now be
125
+
added. This is accomplished by adding a new file to the
126
+
<literal>nixos/modules/services/monitoring/prometheus/exporters/</literal>
127
+
directory, which will be called postfix.nix and contains all
128
+
exporter specific options and configuration:
# nixpgs/nixos/modules/services/prometheus/exporters/postfix.nix
{ config, lib, pkgs, options }:
···
telemetryPath = mkOption {
154
-
default = "/metrics";
149
+
default = "/metrics";
Path under which to expose metrics.
···
${pkgs.prometheus-postfix-exporter}/bin/postfix_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
191
-
${concatStringsSep " \\\n " cfg.extraFlags}
186
+
${concatStringsSep " \\\n " cfg.extraFlags}
195
+
This should already be enough for the postfix exporter.
196
+
Additionally one could now add assertions and conditional
197
+
default values. This can be done in the 'meta-module' that
198
+
combines all exporter definitions and generates the
200
+
<literal>nixpkgs/nixos/modules/services/prometheus/exporters.nix</literal>
205
+
<section xml:id="module-services-prometheus-exporters-update-exporter-module">
206
+
<title>Updating an exporter module</title>
201
-
This should already be enough for the postfix exporter. Additionally one
202
-
could now add assertions and conditional default values. This can be done
203
-
in the 'meta-module' that combines all exporter definitions and generates
205
-
<literal>nixpkgs/nixos/modules/services/prometheus/exporters.nix</literal>
208
+
Should an exporter option change at some point, it is possible to
209
+
add information about the change to the exporter definition
210
+
similar to <literal>nixpkgs/nixos/modules/rename.nix</literal>:
210
-
<section xml:id="module-services-prometheus-exporters-update-exporter-module">
211
-
<title>Updating an exporter module</title>
213
-
Should an exporter option change at some point, it is possible to add
214
-
information about the change to the exporter definition similar to
215
-
<literal>nixpkgs/nixos/modules/rename.nix</literal>:
{ config, lib, pkgs, options }:
···
235
-
# 'services.prometheus.exporters.nginx.telemetryEndpoint' -> 'services.prometheus.exporters.nginx.telemetryPath'
236
-
(mkRenamedOptionModule [ "telemetryEndpoint" ] [ "telemetryPath" ])
231
+
# 'services.prometheus.exporters.nginx.telemetryEndpoint' -> 'services.prometheus.exporters.nginx.telemetryPath'
232
+
(mkRenamedOptionModule [ "telemetryEndpoint" ] [ "telemetryPath" ])
# removed option 'services.prometheus.exporters.nginx.insecure'
239
-
(mkRemovedOptionModule [ "insecure" ] ''
235
+
(mkRemovedOptionModule [ "insecure" ] ''
This option was replaced by 'prometheus.exporters.nginx.sslVerify' which defaults to true.
({ options.warnings = options.warnings; })