git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #107891 from lukegb/smokeping-prober

prometheus-smokeping-prober: init at 0.3.1 from git

commit0587d518db1b4c88eab4c09c902317a4dd9b2a7f authorWilliButz <WilliButz@users.noreply.github.com> dateFri 1 Jan 2021, 16:08 (6 years ago) parent15c7a0e3297ac7
5 files changed+126
nixos/modules/services/monitoring/prometheus/exporters.nix+1 nixos/modules/services/monitoring/prometheus/exporters/smokeping.nix+60 nixos/tests/prometheus-exporters.nix+21 pkgs/servers/monitoring/prometheus/smokeping-prober.nix+43 pkgs/top-level/all-packages.nix+1
nixos/modules/services/monitoring/prometheus/exporters.nix+1
@@ -48,6 +48,7 @@ let
4848 "rspamd"
4949 "rtl_433"
5050 "snmp"
51+ "smokeping"
5152 "sql"
5253 "surfboard"
5354 "tor"
nixos/modules/services/monitoring/prometheus/exporters/smokeping.nixnew file+60
@@ -0,0 +1,60 @@
1+{ config, lib, pkgs, options }:
2+
3+with lib;
4+
5+let
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+ };
13+in
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+}
nixos/tests/prometheus-exporters.nix+21
@@ -695,6 +695,27 @@ let
695695 '';
696696 };
697697
698+ smokeping = {
699+ exporterConfig = {
700+ enable = true;
701+ hosts = ["127.0.0.1"];
702+ };
703+ exporterTest = ''
704+ wait_for_unit("prometheus-smokeping-exporter.service")
705+ wait_for_open_port(9374)
706+ wait_until_succeeds(
707+ "curl -sSf localhost:9374/metrics | grep '{}' | grep -qv ' 0$'".format(
708+ 'smokeping_requests_total{host="127.0.0.1",ip="127.0.0.1"} '
709+ )
710+ )
711+ wait_until_succeeds(
712+ "curl -sSf localhost:9374/metrics | grep -q '{}'".format(
713+ 'smokeping_response_ttl{host="127.0.0.1",ip="127.0.0.1"}'
714+ )
715+ )
716+ '';
717+ };
718+
698719 snmp = {
699720 exporterConfig = {
700721 enable = true;
pkgs/servers/monitoring/prometheus/smokeping-prober.nixnew file+43
@@ -0,0 +1,43 @@
1+{ stdenv, buildGoModule, fetchFromGitHub, nixosTests }:
2+
3+let
4+ inherit (stdenv) lib;
5+ baseVersion = "0.3.1";
6+ commit = "9ba85274dcc21bf8132cbe3b3dccfcb4aab57d9f";
7+in
8+buildGoModule rec {
9+ pname = "smokeping_prober";
10+ version = "${baseVersion}-g${commit}";
11+
12+ buildFlagsArray = let
13+ setVars = {
14+ Version = baseVersion;
15+ Revision = commit;
16+ Branch = commit;
17+ BuildUser = "nix";
18+ };
19+ varFlags = lib.concatStringsSep " " (lib.mapAttrsToList (name: value: "-X github.com/prometheus/common/version.${name}=${value}") setVars);
20+ in [
21+ "-ldflags=${varFlags} -s -w"
22+ ];
23+
24+ src = fetchFromGitHub {
25+ rev = commit;
26+ owner = "SuperQ";
27+ repo = "smokeping_prober";
28+ sha256 = "sha256:19596di2gzcvlcwiypsncq4zwbyb6d1r6wxsfi59wax3423i7ndg";
29+ };
30+ vendorSha256 = "sha256:1b2v3v3kn0m7dvjxbs8q0gw6zingksdqhm5g1frx0mymqk0lg889";
31+
32+ doCheck = true;
33+
34+ passthru.tests = { inherit (nixosTests.prometheus-exporters) smokeping; };
35+
36+ meta = with stdenv.lib; {
37+ description = "Prometheus exporter for sending continual ICMP/UDP pings";
38+ homepage = "https://github.com/SuperQ/smokeping_prober";
39+ license = licenses.asl20;
40+ maintainers = with maintainers; [ lukegb ];
41+ platforms = platforms.unix;
42+ };
43+}
pkgs/top-level/all-packages.nix+1
@@ -17712,6 +17712,7 @@ in
1771217712 prometheus-redis-exporter = callPackage ../servers/monitoring/prometheus/redis-exporter.nix { };
1771317713 prometheus-rabbitmq-exporter = callPackage ../servers/monitoring/prometheus/rabbitmq-exporter.nix { };
1771417714 prometheus-rtl_433-exporter = callPackage ../servers/monitoring/prometheus/rtl_433-exporter.nix { };
17715+ prometheus-smokeping-prober = callPackage ../servers/monitoring/prometheus/smokeping-prober.nix { };
1771517716 prometheus-snmp-exporter = callPackage ../servers/monitoring/prometheus/snmp-exporter.nix { };
1771617717 prometheus-sql-exporter = callPackage ../servers/monitoring/prometheus/sql-exporter.nix { };
1771717718 prometheus-tor-exporter = callPackage ../servers/monitoring/prometheus/tor-exporter.nix { };