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 = lib.mdDoc '' 21 Path under which to expose metrics. 22 ''; 23 }; 24 pingInterval = mkOption { 25 type = goDuration; 26 default = "1s"; 27 description = lib.mdDoc '' 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 = lib.mdDoc '' 35 List of buckets to use for the response duration histogram. 36 ''; 37 }; 38 hosts = mkOption { 39 type = with types; listOf str; 40 description = lib.mdDoc '' 41 List of endpoints to probe. 42 ''; 43 }; 44 }; 45 serviceOpts = { 46 serviceConfig = { 47 AmbientCapabilities = [ "CAP_NET_RAW" ]; 48 CapabilityBoundingSet = [ "CAP_NET_RAW" ]; 49 ExecStart = '' 50 ${pkgs.prometheus-smokeping-prober}/bin/smokeping_prober \ 51 --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 52 --web.telemetry-path ${cfg.telemetryPath} \ 53 --buckets ${cfg.buckets} \ 54 --ping.interval ${cfg.pingInterval} \ 55 --privileged \ 56 ${concatStringsSep " \\\n " cfg.extraFlags} \ 57 ${concatStringsSep " " cfg.hosts} 58 ''; 59 }; 60 }; 61}