Skip to content

Commit 6fbe0e3

Browse files
committed
nixos/module: add metrics options
1 parent 1a0f1ae commit 6fbe0e3

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

nixos/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
self.nixosModules.server
1313
];
1414
services.server.enable = true;
15+
services.server.metrics.enable = true;
1516
};
1617
verifyServices = [ "server.service" ];
1718
};

nixos/modules/server.nix

+32-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ let
44
types
55
mkOption
66
mkIf
7-
mkMerge
87
mkEnableOption
98
escapeShellArgs
9+
optionals
1010
;
1111
cfg = config.services.server;
1212
in
@@ -37,6 +37,27 @@ in
3737
'';
3838
};
3939

40+
metrics = {
41+
enable = lib.mkEnableOption "Prometheus metrics server";
42+
43+
address = mkOption {
44+
type = types.str;
45+
default = "0.0.0.0";
46+
example = "0.0.0.0";
47+
description = ''
48+
Listen address of the metrics server.
49+
'';
50+
};
51+
52+
port = mkOption {
53+
type = types.port;
54+
default = 8081;
55+
description = ''
56+
Listen port of the metrics service.
57+
'';
58+
};
59+
};
60+
4061
logLevel = mkOption {
4162
type = types.str;
4263
default = "info";
@@ -50,10 +71,16 @@ in
5071

5172
systemd.services.server =
5273
let
53-
args = escapeShellArgs [
54-
"--listen-address"
55-
"${cfg.address}:${toString cfg.port}"
56-
];
74+
args = escapeShellArgs (
75+
[
76+
"--listen-address"
77+
"${cfg.address}:${toString cfg.port}"
78+
]
79+
++ optionals cfg.metrics.enable [
80+
"--metrics-listen-address"
81+
"${cfg.metrics.address}:${toString cfg.metrics.port}"
82+
]
83+
);
5784
in
5885
{
5986
description = "server";

0 commit comments

Comments
 (0)