diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 683dc0390c59..cec7b89aaa31 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -23,6 +23,7 @@ let exporterOpts = genAttrs [ "apcupsd" "bind" + "bird" "blackbox" "collectd" "dnsmasq" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/bird.nix b/nixos/modules/services/monitoring/prometheus/exporters/bird.nix new file mode 100644 index 000000000000..d8a526eafcea --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/bird.nix @@ -0,0 +1,46 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.bird; +in +{ + port = 9324; + extraOpts = { + birdVersion = mkOption { + type = types.enum [ 1 2 ]; + default = 2; + description = '' + Specifies whether BIRD1 or BIRD2 is in use. + ''; + }; + birdSocket = mkOption { + type = types.path; + default = "/var/run/bird.ctl"; + description = '' + Path to BIRD2 (or BIRD1 v4) socket. + ''; + }; + newMetricFormat = mkOption { + type = types.bool; + default = true; + description = '' + Enable the new more-generic metric format. + ''; + }; + }; + serviceOpts = { + serviceConfig = { + SupplementaryGroups = singleton (if cfg.birdVersion == 1 then "bird" else "bird2"); + ExecStart = '' + ${pkgs.prometheus-bird-exporter}/bin/bird_exporter \ + -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ + -bird.socket ${cfg.birdSocket} \ + -bird.v2=${if cfg.birdVersion == 2 then "true" else "false"} \ + -format.new=${if cfg.newMetricFormat then "true" else "false"} \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index ffa7f420c093..938607e0b7bf 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -96,6 +96,31 @@ let ''; }; + bird = { + exporterConfig = { + enable = true; + }; + metricProvider = { + services.bird2.enable = true; + services.bird2.config = '' + protocol kernel MyObviousTestString { + ipv4 { + import all; + export none; + }; + } + + protocol device { + } + ''; + }; + exporterTest = '' + wait_for_unit("prometheus-bird-exporter.service") + wait_for_open_port(9324) + succeed("curl -sSf http://localhost:9324/metrics | grep -q 'MyObviousTestString'") + ''; + }; + blackbox = { exporterConfig = { enable = true; diff --git a/pkgs/servers/monitoring/prometheus/bird-exporter.nix b/pkgs/servers/monitoring/prometheus/bird-exporter.nix new file mode 100644 index 000000000000..39daab618b39 --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/bird-exporter.nix @@ -0,0 +1,24 @@ +{ stdenv, buildGoModule, fetchFromGitHub, nixosTests }: + +buildGoModule rec { + pname = "bird-exporter"; + version = "1.3.5-git"; + + src = fetchFromGitHub { + owner = "czerwonk"; + repo = "bird_exporter"; + rev = "019fc09804625658d452a8e043cc16559c3b5b84"; + sha256 = "1iym46368k8zzy4djx511m926dg8x5mg3xi91f65sknqv26zfggb"; + }; + + vendorSha256 = null; + + passthru.tests = { inherit (nixosTests.prometheus-exporters) bird; }; + + meta = with stdenv.lib; { + description = "Prometheus exporter for the bird routing daemon"; + homepage = "https://github.com/czerwonk/bird_exporter"; + license = licenses.mit; + maintainers = with maintainers; [ lukegb ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 512b21c12e26..d6b057fedc7e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17672,6 +17672,7 @@ in prometheus-apcupsd-exporter = callPackage ../servers/monitoring/prometheus/apcupsd-exporter.nix { }; prometheus-aws-s3-exporter = callPackage ../servers/monitoring/prometheus/aws-s3-exporter.nix { }; prometheus-bind-exporter = callPackage ../servers/monitoring/prometheus/bind-exporter.nix { }; + prometheus-bird-exporter = callPackage ../servers/monitoring/prometheus/bird-exporter.nix { }; prometheus-blackbox-exporter = callPackage ../servers/monitoring/prometheus/blackbox-exporter.nix { }; prometheus-collectd-exporter = callPackage ../servers/monitoring/prometheus/collectd-exporter.nix { }; prometheus-cups-exporter = callPackage ../servers/monitoring/prometheus/cups-exporter.nix { };