Skip to content

Commit

Permalink
nixos/module: add metrics options
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp committed Sep 19, 2024
1 parent 170ddcc commit 8f0138e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
self.nixosModules.server
];
services.server.enable = true;
services.server.metrics.enable = true;
};
verifyServices = [ "server.service" ];
};
Expand Down
37 changes: 32 additions & 5 deletions nixos/modules/server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ let
types
mkOption
mkIf
mkMerge
mkEnableOption
escapeShellArgs
optionals
;
cfg = config.services.server;
in
Expand Down Expand Up @@ -37,6 +37,27 @@ in
'';
};

metrics = {
enable = lib.mkEnableOption "Prometheus metrics server";

address = mkOption {
type = types.str;
default = "0.0.0.0";
example = "0.0.0.0";
description = ''
Listen address of the metrics server.
'';
};

port = mkOption {
type = types.port;
default = 8081;
description = ''
Listen port of the metrics service.
'';
};
};

logLevel = mkOption {
type = types.str;
default = "info";
Expand All @@ -50,10 +71,16 @@ in

systemd.services.server =
let
args = escapeShellArgs [
"--listen-address"
"${cfg.address}:${toString cfg.port}"
];
args = escapeShellArgs (
[
"--listen-address"
"${cfg.address}:${toString cfg.port}"
]
++ optionals cfg.metrics.enable [
"--metrics-listen-address"
"${cfg.metrics.address}:${toString cfg.metrics.port}"
]
);
in
{
description = "server";
Expand Down

0 comments on commit 8f0138e

Please sign in to comment.