1{ config, lib, pkgs, options }:
2
3with lib;
4
5let
6 cfg = config.services.prometheus.exporters.buildkite-agent;
7in
8{
9 port = 9876;
10 extraOpts = {
11 tokenPath = mkOption {
12 type = types.nullOr types.path;
13 apply = final: if final == null then null else toString final;
14 description = lib.mdDoc ''
15 The token from your Buildkite "Agents" page.
16
17 A run-time path to the token file, which is supposed to be provisioned
18 outside of Nix store.
19 '';
20 };
21 interval = mkOption {
22 type = types.str;
23 default = "30s";
24 example = "1min";
25 description = lib.mdDoc ''
26 How often to update metrics.
27 '';
28 };
29 endpoint = mkOption {
30 type = types.str;
31 default = "https://agent.buildkite.com/v3";
32 description = lib.mdDoc ''
33 The Buildkite Agent API endpoint.
34 '';
35 };
36 queues = mkOption {
37 type = with types; nullOr (listOf str);
38 default = null;
39 example = literalExpression ''[ "my-queue1" "my-queue2" ]'';
40 description = lib.mdDoc ''
41 Which specific queues to process.
42 '';
43 };
44 };
45 serviceOpts = {
46 script =
47 let
48 queues = concatStringsSep " " (map (q: "-queue ${q}") cfg.queues);
49 in
50 ''
51 export BUILDKITE_AGENT_TOKEN="$(cat ${toString cfg.tokenPath})"
52 exec ${pkgs.buildkite-agent-metrics}/bin/buildkite-agent-metrics \
53 -backend prometheus \
54 -interval ${cfg.interval} \
55 -endpoint ${cfg.endpoint} \
56 ${optionalString (cfg.queues != null) queues} \
57 -prometheus-addr "${cfg.listenAddress}:${toString cfg.port}" ${concatStringsSep " " cfg.extraFlags}
58 '';
59 serviceConfig = {
60 DynamicUser = false;
61 RuntimeDirectory = "buildkite-agent-metrics";
62 };
63 };
64}