anyrun: 0-unstable-2024-11-08 -> 0-unstable-2024-12-27 (#369731)
[NixPkgs.git] / nixos / modules / services / monitoring / prometheus / exporters / smokeping.nix
blob0a3ceba88d20118c5e88178721a0dee80cd848e8
2   config,
3   lib,
4   pkgs,
5   options,
6   ...
7 }:
9 let
10   cfg = config.services.prometheus.exporters.smokeping;
11   inherit (lib) mkOption types concatStringsSep;
12   goDuration = types.mkOptionType {
13     name = "goDuration";
14     description = "Go duration (https://golang.org/pkg/time/#ParseDuration)";
15     check =
16       x: types.str.check x && builtins.match "(-?[0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+" x != null;
17     inherit (types.str) merge;
18   };
21   port = 9374;
22   extraOpts = {
23     telemetryPath = mkOption {
24       type = types.str;
25       default = "/metrics";
26       description = ''
27         Path under which to expose metrics.
28       '';
29     };
30     pingInterval = mkOption {
31       type = goDuration;
32       default = "1s";
33       description = ''
34         Interval between pings.
35       '';
36     };
37     buckets = mkOption {
38       type = types.commas;
39       default = "5e-05,0.0001,0.0002,0.0004,0.0008,0.0016,0.0032,0.0064,0.0128,0.0256,0.0512,0.1024,0.2048,0.4096,0.8192,1.6384,3.2768,6.5536,13.1072,26.2144";
40       description = ''
41         List of buckets to use for the response duration histogram.
42       '';
43     };
44     hosts = mkOption {
45       type = with types; listOf str;
46       description = ''
47         List of endpoints to probe.
48       '';
49     };
50   };
51   serviceOpts = {
52     serviceConfig = {
53       AmbientCapabilities = [ "CAP_NET_RAW" ];
54       CapabilityBoundingSet = [ "CAP_NET_RAW" ];
55       ExecStart = ''
56         ${pkgs.prometheus-smokeping-prober}/bin/smokeping_prober \
57           --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
58           --web.telemetry-path ${cfg.telemetryPath} \
59           --buckets ${cfg.buckets} \
60           --ping.interval ${cfg.pingInterval} \
61           --privileged \
62           ${concatStringsSep " \\\n  " cfg.extraFlags} \
63           ${concatStringsSep " " cfg.hosts}
64       '';
65     };
66   };