1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.minioExporter;
7in {
8 options = {
9 services.prometheus.minioExporter = {
10 enable = mkEnableOption "prometheus minio exporter";
11
12 port = mkOption {
13 type = types.int;
14 default = 9290;
15 description = ''
16 Port to listen on.
17 '';
18 };
19
20 listenAddress = mkOption {
21 type = types.nullOr types.str;
22 default = null;
23 example = "0.0.0.0";
24 description = ''
25 Address to listen on for web interface and telemetry.
26 '';
27 };
28
29 minioAddress = mkOption {
30 type = types.str;
31 example = "https://10.0.0.1:9000";
32 default = if config.services.minio.enable then "http://localhost:9000" else null;
33 description = ''
34 The URL of the minio server.
35 Use HTTPS if Minio accepts secure connections only.
36 By default this connects to the local minio server if enabled.
37 '';
38 };
39
40 minioAccessKey = mkOption ({
41 type = types.str;
42 example = "BKIKJAA5BMMU2RHO6IBB";
43 description = ''
44 The value of the Minio access key.
45 It is required in order to connect to the server.
46 By default this uses the one from the local minio server if enabled
47 and <literal>config.services.minio.accessKey</literal>.
48 '';
49 } // optionalAttrs (config.services.minio.enable && config.services.minio.accessKey != "") {
50 default = config.services.minio.accessKey;
51 });
52
53 minioAccessSecret = mkOption ({
54 type = types.str;
55 description = ''
56 The calue of the Minio access secret.
57 It is required in order to connect to the server.
58 By default this uses the one from the local minio server if enabled
59 and <literal>config.services.minio.secretKey</literal>.
60 '';
61 } // optionalAttrs (config.services.minio.enable && config.services.minio.secretKey != "") {
62 default = config.services.minio.secretKey;
63 });
64
65 minioBucketStats = mkOption {
66 type = types.bool;
67 default = false;
68 description = ''
69 Collect statistics about the buckets and files in buckets.
70 It requires more computation, use it carefully in case of large buckets..
71 '';
72 };
73
74 extraFlags = mkOption {
75 type = types.listOf types.str;
76 default = [];
77 description = ''
78 Extra commandline options when launching the minio exporter.
79 '';
80 };
81
82 openFirewall = mkOption {
83 type = types.bool;
84 default = false;
85 description = ''
86 Open port in firewall for incoming connections.
87 '';
88 };
89 };
90 };
91
92 config = mkIf cfg.enable {
93 networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port;
94
95 systemd.services.prometheus-minio-exporter = {
96 description = "Prometheus exporter for Minio server metrics";
97 unitConfig.Documentation = "https://github.com/joe-pll/minio-exporter";
98 wantedBy = [ "multi-user.target" ];
99 after = optional config.services.minio.enable "minio.service";
100 serviceConfig = {
101 DynamicUser = true;
102 Restart = "always";
103 PrivateTmp = true;
104 WorkingDirectory = /tmp;
105 ExecStart = ''
106 ${pkgs.prometheus-minio-exporter}/bin/minio-exporter \
107 -web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \
108 -minio.server ${cfg.minioAddress} \
109 -minio.access-key ${cfg.minioAccessKey} \
110 -minio.access-secret ${cfg.minioAccessSecret} \
111 ${optionalString cfg.minioBucketStats "-minio.bucket-stats"} \
112 ${concatStringsSep " \\\n " cfg.extraFlags}
113 '';
114 };
115 };
116 };
117}