From fa09a124a7911e78055288b6d5bb60b8d7e2c06c Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 15 Jul 2021 09:46:10 -0700 Subject: [PATCH 1/2] buildkite-agent-metrics: init at 5.2.1 --- .../buildkite-agent-metrics/default.nix | 42 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 44 insertions(+) create mode 100644 pkgs/servers/monitoring/buildkite-agent-metrics/default.nix diff --git a/pkgs/servers/monitoring/buildkite-agent-metrics/default.nix b/pkgs/servers/monitoring/buildkite-agent-metrics/default.nix new file mode 100644 index 000000000000..8112feb75fed --- /dev/null +++ b/pkgs/servers/monitoring/buildkite-agent-metrics/default.nix @@ -0,0 +1,42 @@ +{ lib +, buildGoModule +, fetchFromGitHub +, fetchpatch +}: +buildGoModule rec { + pname = "buildkite-agent-metrics"; + version = "5.2.1"; + + outputs = [ "out" "lambda" ]; + + src = fetchFromGitHub { + owner = "buildkite"; + repo = "buildkite-agent-metrics"; + rev = "v${version}"; + sha256 = "XZYVCSJ/DIwoLrz37aQ3yW3RUhOhorY8L1AsAWxywcg="; + }; + + vendorSha256 = "UIkU3i45IEXWHdiakTj7f4W9kR49k4A93msfkqeXmQQ="; + + patches = [ + # Necessary to support passing the agent token in an env var, rather than on + # the command line. Should be removed upon the next release. + (fetchpatch { + name = "BUILDKITE_AGENT_TOKEN-env-var.patch"; + url = "https://github.com/buildkite/buildkite-agent-metrics/commit/6c40b478b95f0e05fc12b87158222a9ff68169e0.patch"; + sha256 = "Y4m9qGyPIROSqOY6G6xRQfFENEG4bFF3q5dZcHI4XiY="; + }) + ]; + + postInstall = '' + mkdir -p $lambda/bin + mv $out/bin/lambda $lambda/bin + ''; + + meta = with lib; { + description = "A command-line tool (and Lambda) for collecting Buildkite agent metrics"; + homepage = "https://github.com/buildkite/buildkite-agent-metrics"; + license = licenses.mit; + maintainers = teams.determinatesystems.members; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c5024a4d8d3a..173b2d1b9d71 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13206,6 +13206,8 @@ in buildkite-agent2 = throw "pkgs.buildkite-agent2 has been discontinued. Please use pkgs.buildkite-agent (v3.x)"; buildkite-agent3 = callPackage ../development/tools/continuous-integration/buildkite-agent { }; + buildkite-agent-metrics = callPackage ../servers/monitoring/buildkite-agent-metrics { }; + buildkite-cli = callPackage ../development/tools/continuous-integration/buildkite-cli { }; bump = callPackage ../development/tools/github/bump { }; From 88fb6d25d87f5ff6e75d471809bb61463e1c5cc6 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 15 Jul 2021 10:37:54 -0700 Subject: [PATCH 2/2] nixos/prometheus-buildkite-agent-exporter: init --- .../from_md/release-notes/rl-2111.section.xml | 8 +++ .../manual/release-notes/rl-2111.section.md | 1 + .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/buildkite-agent.nix | 64 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/buildkite-agent.nix diff --git a/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml index 88d075a9a482..fc1cec16ef90 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2111.section.xml @@ -99,6 +99,14 @@ services.hockeypuck. + + + buildkite-agent-metrics, + a command-line tool for collecting Buildkite agent metrics, + now has a Prometheus exporter available as + services.prometheus.exporters.buildkite-agent. + +
diff --git a/nixos/doc/manual/release-notes/rl-2111.section.md b/nixos/doc/manual/release-notes/rl-2111.section.md index f7275480ff81..9303393aba34 100644 --- a/nixos/doc/manual/release-notes/rl-2111.section.md +++ b/nixos/doc/manual/release-notes/rl-2111.section.md @@ -30,6 +30,7 @@ In addition to numerous new and upgraded packages, this release has the followin - [Hockeypuck](https://github.com/hockeypuck/hockeypuck), a OpenPGP Key Server. Available as [services.hockeypuck](#opt-services.hockeypuck.enable). +- [buildkite-agent-metrics](https://github.com/buildkite/buildkite-agent-metrics), a command-line tool for collecting Buildkite agent metrics, now has a Prometheus exporter available as [services.prometheus.exporters.buildkite-agent](#opt-services.prometheus.exporters.buildkite-agent.enable). ## Backward Incompatibilities {#sec-release-21.11-incompatibilities} diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 6bd075697fa2..d648de6a4148 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -27,6 +27,7 @@ let "bird" "bitcoin" "blackbox" + "buildkite-agent" "collectd" "dnsmasq" "domain" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/buildkite-agent.nix b/nixos/modules/services/monitoring/prometheus/exporters/buildkite-agent.nix new file mode 100644 index 000000000000..7557480ac062 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/buildkite-agent.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.buildkite-agent; +in +{ + port = 9876; + extraOpts = { + tokenPath = mkOption { + type = types.nullOr types.path; + apply = final: if final == null then null else toString final; + description = '' + The token from your Buildkite "Agents" page. + + A run-time path to the token file, which is supposed to be provisioned + outside of Nix store. + ''; + }; + interval = mkOption { + type = types.str; + default = "30s"; + example = "1min"; + description = '' + How often to update metrics. + ''; + }; + endpoint = mkOption { + type = types.str; + default = "https://agent.buildkite.com/v3"; + description = '' + The Buildkite Agent API endpoint. + ''; + }; + queues = mkOption { + type = with types; nullOr (listOf str); + default = null; + example = literalExample ''[ "my-queue1" "my-queue2" ]''; + description = '' + Which specific queues to process. + ''; + }; + }; + serviceOpts = { + script = + let + queues = concatStringsSep " " (map (q: "-queue ${q}") cfg.queues); + in + '' + export BUILDKITE_AGENT_TOKEN="$(cat ${toString cfg.tokenPath})" + exec ${pkgs.buildkite-agent-metrics}/bin/buildkite-agent-metrics \ + -backend prometheus \ + -interval ${cfg.interval} \ + -endpoint ${cfg.endpoint} \ + ${optionalString (cfg.queues != null) queues} \ + -prometheus-addr "${cfg.listenAddress}:${toString cfg.port}" ${concatStringsSep " " cfg.extraFlags} + ''; + serviceConfig = { + DynamicUser = false; + RuntimeDirectory = "buildkite-agent-metrics"; + }; + }; +}