Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 1 | # Prometheus configuration for a BIRD-enabled router. |
| 2 | |
| 3 | { config, pkgs, lib, ... }: |
| 4 | |
| 5 | with lib; |
| 6 | |
| 7 | let |
| 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 | |
| 24 | in { |
| 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 | } |