blob: 1ebb4359e88c0d44731374bb01264427d0731c14 [file] [log] [blame]
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02001# Prometheus configuration for a BIRD-enabled router.
2
3{ config, pkgs, lib, ... }:
4
5with lib;
6
7let
8 nodeExporterPort = 9100;
9 birdExporterPort = 9101;
10
11 birdExporter = pkgs.buildGoModule rec {
12 pname = "bird-exporter";
Serge Bazanski0fc01a92021-07-19 22:11:08 +020013 version = "1.2.6";
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020014 src = pkgs.fetchFromGitHub {
15 owner = "czerwonk";
16 repo = "bird_exporter";
17 rev = version;
Serge Bazanski0fc01a92021-07-19 22:11:08 +020018 sha256 = "1yqizzlvwyxlrd2priqd1jx9s87yvsypqkmk81dacm1ra4xrs0nd";
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020019 };
20
Serge Bazanski0fc01a92021-07-19 22:11:08 +020021 vendorSha256 = "0wczj3g0c917hwjkz23xg5blb4z5a04v3wbx6kg0wfyb09c9bwx3";
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020022 };
23
24in {
25 systemd.services.bird_exporter = {
26 wantedBy = [ "multi-user.target" ];
27 serviceConfig = {
28 Type = "simple";
29 ExecStart = "${birdExporter}/bin/bird_exporter -format.new=true -bird.v2=true -web.listen-address=127.0.0.1:${toString birdExporterPort}";
30 Restart = "always";
31 RestartSec = "60";
32 };
33 };
34
35 services.prometheus.exporters.node = {
36 enable = true;
37 listenAddress = "127.0.0.1";
38 port = nodeExporterPort;
39 };
40
41 services.nginx.enable = true;
42 services.nginx.virtualHosts."${config.networking.hostName}.${config.networking.domain}" = let
43 allowMonitoring = ''
44 allow 209.250.231.127; # monitoring.hackerspace.pl
45 deny all;
46 '';
47 in {
48 locations."/metrics-node" = {
49 proxyPass = "http://127.0.0.1:${toString nodeExporterPort}/metrics";
50 extraConfig = allowMonitoring;
51 };
52 locations."/metrics-bird" = {
53 proxyPass = "http://127.0.0.1:${toString birdExporterPort}/metrics";
54 extraConfig = allowMonitoring;
55 };
56 };
57}