~aasg/nixexprs

a0754c2ee00eeff61c47776c08d5850966caba0d — Aluísio Augusto Silva Gonçalves 1 year, 7 days ago cc3dd4f
prometheus-bird-exporter: init at 1.2.4
M modules/default.nix => modules/default.nix +1 -0
@@ 4,6 4,7 @@
  ipfs-cluster = ./services/cluster/ipfs-cluster.nix;
  matrix-appservice-irc = ./services/networking/matrix-appservice-irc.nix;
  postgresql-base-backup = ./services/databases/postgresql-base-backup.nix;
  prometheus-bird-exporter = ./services/monitoring/prometheus/exporters/bird.nix;
  trust-dns = ./services/networking/trust-dns.nix;
  wireguard-systemd = ./services/networking/wireguard-systemd.nix;
}

A modules/services/monitoring/prometheus/exporters/bird.nix => modules/services/monitoring/prometheus/exporters/bird.nix +61 -0
@@ 0,0 1,61 @@
{ config, lib, pkgs, ... }:
let
  inherit (lib) concatStringsSep mkEnableOption mkIf mkOption optionalString types;

  cfg = config.services.prometheus.birdExporter;
in
{

  options = {
    services.prometheus.birdExporter = {
      enable = mkEnableOption "the prometheus bird exporter";
      port = mkOption {
        description = "Port to listen on.";
        type = types.port;
        default = 9324;
      };
      listenAddress = mkOption {
        description = "Address to listen on.";
        type = types.str;
        default = "0.0.0.0";
      };
      extraFlags = mkOption {
        description = "Extra commandline options to pass to the bird exporter.";
        type = types.listOf types.str;
        default = [ ];
      };
      group = mkOption {
        type = types.str;
        default = "bird-exporter";
        description = "Group under which the bird exporter shall be run.";
      };
      birdVersion = mkOption {
        description = "Version of Bird to scrape.";
        type = types.enum [ "v1.ip4" "v1.ip6" "v1.ip46" "v2" ];
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.prometheus-bird-exporter = {
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" "bird.service" "bird6.service" "bird2.service" ];
      serviceConfig = {
        ExecStart = ''
          ${pkgs.prometheus-bird-exporter}/bin/bird_exporter -format.new \
            ${optionalString (cfg.birdVersion == "v1.ip4" || cfg.birdVersion == "v1.ip46") "-bird.ipv4"} \
            ${optionalString (cfg.birdVersion == "v1.ip6" || cfg.birdVersion == "v1.ip46") "-bird.ipv6"} \
            ${optionalString (cfg.birdVersion == "v2") "-bird.v2"} \
            -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
            ${concatStringsSep " \\\n  " cfg.extraFlags}
        '';
        Restart = "always";
        PrivateTmp = true;
        DynamicUser = true;
        Group = cfg.group;
      };
    };

  };

}

M pkgs/manifest.nix => pkgs/manifest.nix +1 -0
@@ 10,6 10,7 @@
  [ "linuxPackages" "rtl8723bu" ]
  [ "linuxPackages_latest" "rtl8723bu" ]
  [ "matrix-appservice-irc" ]
  [ "prometheus-bird-exporter" ]
  [ "python3Packages" "daemonocle" ]
  [ "shellharden" ]
  [ "trust-dns" ]

M pkgs/overlay.nix => pkgs/overlay.nix +2 -0
@@ 27,6 27,8 @@ final: prev:
    nodejs = final.nodejs-12_x;
  };

  prometheus-bird-exporter = final.callPackage ./servers/monitoring/prometheus/bird-exporter.nix { };

  python3 = prev.python3.override { packageOverrides = import ./development/python-modules; self = final.python3; };

  shellharden = final.callPackage ./development/tools/shellharden { };

A pkgs/servers/monitoring/prometheus/bird-exporter.nix => pkgs/servers/monitoring/prometheus/bird-exporter.nix +24 -0
@@ 0,0 1,24 @@
{ lib, buildGoModule, fetchFromGitHub }:

buildGoModule rec {
  pname = "bird_exporter";
  version = "1.2.4";

  src = fetchFromGitHub {
    owner = "czerwonk";
    repo = pname;
    rev = version;
    sha256 = "1kgymbk9npw5bdbawm8xvm81b267ag81862favfbnmg3xyl5sh81";
  };
  vendorSha256 = null;

  doCheck = true;

  meta = with lib; {
    description = "Bird protocol state exporter for bird routing daemon to use with Prometheus";
    homepage = "https://github.com/czerwonk/bird_exporter";
    license = licenses.mit;
    maintainers = with maintainers; [ AluisioASG ];
    platforms = platforms.unix;
  };
}