1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.smokeping;
7 goDuration = types.mkOptionType {
8 name = "goDuration";
9 description = "Go duration (https://golang.org/pkg/time/#ParseDuration)";
10 check = x: types.str.check x && builtins.match "(-?[0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+" x != null;
11 inherit (types.str) merge;
12 };
13in
14{
15 port = 9374;
16 extraOpts = {
17 telemetryPath = mkOption {
18 type = types.str;
19 default = "/metrics";
20 description = ''
21 Path under which to expose metrics.
22 '';
23 };
24 pingInterval = mkOption {
25 type = goDuration;
26 default = "1s";
27 description = ''
28 Interval between pings.
29 '';
30 };
31 buckets = mkOption {
32 type = types.commas;
33 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";
34 description = ''
35 List of buckets to use for the response duration histogram.
36 '';
37 };
38 hosts = mkOption {
39 type = with types; listOf str;
40 description = ''
41 List of endpoints to probe.
42 '';
43 };
44 };
45 serviceOpts = {
46 serviceConfig = {
47 AmbientCapabilities = [ "CAP_NET_RAW" ];
48 ExecStart = ''
49 ${pkgs.prometheus-smokeping-prober}/bin/smokeping_prober \
50 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
51 --web.telemetry-path ${cfg.telemetryPath} \
52 --buckets ${cfg.buckets} \
53 --ping.interval ${cfg.pingInterval} \
54 --privileged \
55 ${concatStringsSep " \\\n " cfg.extraFlags} \
56 ${concatStringsSep " " cfg.hosts}
57 '';
58 };
59 };
60}