1{
2 config,
3 lib,
4 pkgs,
5 options,
6 ...
7}:
8
9let
10 cfg = config.services.prometheus.exporters.nginxlog;
11 inherit (lib) mkOption types;
12in
13{
14 port = 9117;
15 extraOpts = {
16 settings = mkOption {
17 type = types.submodule {
18 options = {
19 consul = mkOption {
20 default = null;
21 type = types.nullOr (types.attrsOf types.anything);
22 description = ''
23 Consul integration options. For more information see the [example config](https://github.com/martin-helmich/prometheus-nginxlog-exporter#configuration-file).
24
25 This is disabled by default.
26 '';
27 };
28 namespaces = mkOption {
29 default = [ ];
30 type = types.listOf (types.attrsOf types.anything);
31
32 description = ''
33 Namespaces to collect the metrics for. For more information see the [example config](https://github.com/martin-helmich/prometheus-nginxlog-exporter#configuration-file).
34 '';
35 };
36 };
37 };
38 default = { };
39 description = ''
40 All settings of nginxlog expressed as an Nix attrset.
41
42 Check the official documentation for the corresponding YAML
43 settings that can all be used here: <https://github.com/martin-helmich/prometheus-nginxlog-exporter>
44
45 The `listen` object is already generated by `port`, `listenAddress` and `metricsEndpoint` and
46 will be merged with the value of `settings` before writing it as JSON.
47 '';
48 };
49
50 metricsEndpoint = mkOption {
51 type = types.str;
52 default = "/metrics";
53 description = ''
54 Path under which to expose metrics.
55 '';
56 };
57 };
58
59 serviceOpts =
60 let
61 listenConfig = {
62 listen = {
63 port = cfg.port;
64 address = cfg.listenAddress;
65 metrics_endpoint = cfg.metricsEndpoint;
66 };
67 };
68 completeConfig = pkgs.writeText "nginxlog-exporter.yaml" (
69 builtins.toJSON (lib.recursiveUpdate listenConfig cfg.settings)
70 );
71 in
72 {
73 serviceConfig = {
74 ExecStart = ''
75 ${pkgs.prometheus-nginxlog-exporter}/bin/prometheus-nginxlog-exporter -config-file ${completeConfig}
76 '';
77 Restart = "always";
78 ProtectSystem = "full";
79 };
80 };
81}