@cryptotaxi247 / infra-1 / commits / 5ab455fb

eris: scrape Fastly for creds

Graham Christensen committed Sep 27, 2021 at 17:30 UTC 5ab455fbe03594a308291aa2108db81deb655227
2 files changed +57
delft/eris.nix
+34
@@ -319,6 +319,17 @@ in {
319 }
320 ];
321 }
322 + {
323 + job_name = "fastly";
324 + metrics_path = "/metrics";
325 + static_configs = [
326 + {
327 + targets = [
328 + "127.0.0.1:9118"
329 + ];
330 + }
331 + ];
332 + }
333 {
334 job_name = "rfc39";
335 metrics_path = "/";
@@ -551,4 +562,27 @@ in {
562 RestartSec = "60s";
563 };
564 };
565 +
566 + deployment.keys."fastly-read-only-api-token" = {
567 + keyFile = /home/deploy/src/nixos-org-configurations/fastly-read-only-api-token;
568 + };
569 +
570 + systemd.services.prometheus-fastly-exporter = let
571 + fastly = pkgs.callPackage ./prometheus/fastly.nix {};
572 + in {
573 + wantedBy = [ "multi-user.target" "prometheus.service" ];
574 + after = [ "network.target" ];
575 +
576 + script = ''
577 + export FASTLY_API_TOKEN=$(cat /run/keys/fastly-read-only-api-token)
578 + ${fastly}/bin/fastly-exporter \
579 + -endpoint http://127.0.0.1:9118/metrics
580 + '';
581 +
582 + serviceConfig = {
583 + Group = "keys";
584 + Restart = "always";
585 + RestartSec = "60s";
586 + };
587 + };
588 }
delft/prometheus/fastly.nix new
+23
@@ -0,0 +1,23 @@
1 +{ lib, buildGoModule, fetchFromGitHub }:
2 +# Introduced in PR #133726 and should be removed when the network updates
3 +# to 21.11 or later.
4 +buildGoModule rec {
5 + pname = "fastly-exporter";
6 + version = "6.1.0";
7 +
8 + src = fetchFromGitHub {
9 + owner = "peterbourgon";
10 + repo = pname;
11 + rev = "v${version}";
12 + sha256 = "0my0pcxix5rk73m5ciz513nwmjcm7vjs6r8wg3vddm0xixv7zq94";
13 + };
14 +
15 + vendorSha256 = "1w9asky8h8l5gc0c6cv89m38qw50hyhma8qbsw3zirplhk9mb3r2";
16 +
17 + meta = with lib; {
18 + description = "Prometheus exporter for the Fastly Real-time Analytics API";
19 + homepage = "https://github.com/peterbourgon/fastly-exporter";
20 + license = licenses.asl20;
21 + maintainers = teams.deshaw.members;
22 + };
23 +}