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