diff options
author | Luke Granger-Brown <git@lukegb.com> | 2020-12-29 17:47:58 +0000 |
---|---|---|
committer | Luke Granger-Brown <git@lukegb.com> | 2020-12-29 18:59:51 +0000 |
commit | 3297ac72f15d9df5650e2532782bc81e31b7178c (patch) | |
tree | 2163086b5a367b05e6de0408a8c4fe222efcd977 /nixos | |
parent | 2c329d7954421d9535c919e7a75a87b62ad09554 (diff) | |
download | nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar.gz nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar.bz2 nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar.lz nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar.xz nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.tar.zst nixpkgs-3297ac72f15d9df5650e2532782bc81e31b7178c.zip |
nixos/prometheus: add smokeping and corresponding NixOS test
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters.nix | 1 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters/smokeping.nix | 60 | ||||
-rw-r--r-- | nixos/tests/prometheus-exporters.nix | 21 |
3 files changed, 82 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 683dc0390c5..3e7b303620f 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -47,6 +47,7 @@ let "rspamd" "rtl_433" "snmp" + "smokeping" "sql" "surfboard" "tor" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/smokeping.nix b/nixos/modules/services/monitoring/prometheus/exporters/smokeping.nix new file mode 100644 index 00000000000..0a7bb9c27be --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/smokeping.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.smokeping; + goDuration = types.mkOptionType { + name = "goDuration"; + description = "Go duration (https://golang.org/pkg/time/#ParseDuration)"; + check = x: types.str.check x && builtins.match "(-?[0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+" x != null; + inherit (types.str) merge; + }; +in +{ + port = 9374; + extraOpts = { + telemetryPath = mkOption { + type = types.str; + default = "/metrics"; + description = '' + Path under which to expose metrics. + ''; + }; + pingInterval = mkOption { + type = goDuration; + default = "1s"; + description = '' + Interval between pings. + ''; + }; + buckets = mkOption { + type = types.commas; + 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"; + description = '' + List of buckets to use for the response duration histogram. + ''; + }; + hosts = mkOption { + type = with types; listOf str; + description = '' + List of endpoints to probe. + ''; + }; + }; + serviceOpts = { + serviceConfig = { + AmbientCapabilities = [ "CAP_NET_RAW" ]; + ExecStart = '' + ${pkgs.prometheus-smokeping-prober}/bin/smokeping_prober \ + --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ + --web.telemetry-path ${cfg.telemetryPath} \ + --buckets ${cfg.buckets} \ + --ping.interval ${cfg.pingInterval} \ + --privileged \ + ${concatStringsSep " \\\n " cfg.extraFlags} \ + ${concatStringsSep " " cfg.hosts} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index ffa7f420c09..4dcea39cef1 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -670,6 +670,27 @@ let ''; }; + smokeping = { + exporterConfig = { + enable = true; + hosts = ["127.0.0.1"]; + }; + exporterTest = '' + wait_for_unit("prometheus-smokeping-exporter.service") + wait_for_open_port(9374) + wait_until_succeeds( + "curl -sSf localhost:9374/metrics | grep '{}' | grep -qv ' 0$'".format( + 'smokeping_requests_total{host="127.0.0.1",ip="127.0.0.1"} ' + ) + ) + wait_until_succeeds( + "curl -sSf localhost:9374/metrics | grep -q '{}'".format( + 'smokeping_response_ttl{host="127.0.0.1",ip="127.0.0.1"}' + ) + ) + ''; + }; + snmp = { exporterConfig = { enable = true; |