blob: 704c2577017259f3da822c890db71a86fb3aa612 [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";
13 version = "1.2.5";
14 src = pkgs.fetchFromGitHub {
15 owner = "czerwonk";
16 repo = "bird_exporter";
17 rev = version;
18 sha256 = "1qrhncy1f119f5rfgn2d1l6nvapaqkld4zb9bxzdqmmw6kicc7bs";
19 };
20
21 vendorSha256 = null;
22 };
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}