about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/fastly.nix
blob: 2a8b7fc0818d52e83ccad014fb3b7622c27ebc6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ config
, lib
, pkgs
, options
}:

let
  inherit (lib)
    escapeShellArgs
    mkOption
    optionals
    types
  ;

  cfg = config.services.prometheus.exporters.fastly;
in
{
  port = 9118;
  extraOpts = with types; {
    configFile = mkOption {
      type = nullOr path;
      default = null;
      example = "./fastly-exporter-config.txt";
      description = ''
        Path to a fastly-exporter configuration file.
        Example one can be generated with `fastly-exporter --config-file-example`.
      '';
    };

    tokenPath = mkOption {
      type = path;
      description = ''
        A run-time path to the token file, which is supposed to be provisioned
        outside of Nix store.
      '';
    };
  };
  serviceOpts = {
    serviceConfig = {
      LoadCredential = "fastly-api-token:${cfg.tokenPath}";
    };
    script = let
      call = escapeShellArgs ([
        "${pkgs.prometheus-fastly-exporter}/bin/fastly-exporter"
        "-listen" "${cfg.listenAddress}:${toString cfg.port}"
      ] ++ optionals (cfg.configFile != null) [
        "--config-file" cfg.configFile
      ] ++ cfg.extraFlags);
    in ''
      export FASTLY_API_TOKEN="$(cat $CREDENTIALS_DIRECTORY/fastly-api-token)"
      ${call}
    '';
  };
}