aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/networking/trickster.nix
blob: 8760dd5a93827d8578b1d18a315bfba4d61abe78 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.trickster;
in
{

  options = {
    services.trickster = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Enable Trickster.
        '';
      };

      package = mkOption {
        type = types.package;
        default = pkgs.trickster;
        defaultText = "pkgs.trickster";
        description = ''
          Package that should be used for trickster.
        '';
      };

      configFile = mkOption {
        type = types.nullOr types.path;
        default = null;
        description = ''
          Path to configuration file.
        '';
      };

      instance-id = mkOption {
        type = types.nullOr types.int;
        default = null;
        description = ''
          Instance ID for when running multiple processes (default null).
        '';
      };

      log-level = mkOption {
        type = types.str;
        default = "info";
        description = ''
          Level of Logging to use (debug, info, warn, error) (default "info").
        '';
      };

      metrics-port = mkOption {
        type = types.port;
        default = 8082;
        description = ''
          Port that the /metrics endpoint will listen on.
        '';
      };

      origin = mkOption {
        type = types.str;
        default = "http://prometheus:9090";
        description = ''
          URL to the Prometheus Origin. Enter it like you would in grafana, e.g., http://prometheus:9090 (default http://prometheus:9090).
        '';
      };

      profiler-port = mkOption {
        type = types.nullOr types.port;
        default = null;
        description = ''
          Port that the /debug/pprof endpoint will listen on.
        '';
      };

      proxy-port = mkOption {
        type = types.port;
        default = 9090;
        description = ''
          Port that the Proxy server will listen on.
        '';
      };

    };
  };

  config = mkIf cfg.enable {
    systemd.services.trickster = {
      description = "Dashboard Accelerator for Prometheus";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        DynamicUser = true;
        ExecStart = ''
          ${cfg.package}/bin/trickster \
          -log-level ${cfg.log-level} \
          -metrics-port ${toString cfg.metrics-port} \
          -origin ${cfg.origin} \
          -proxy-port ${toString cfg.proxy-port} \
          ${optionalString (cfg.configFile != null) "-config ${cfg.configFile}"} \
          ${optionalString (cfg.profiler-port != null) "-profiler-port ${cfg.profiler-port}"} \
          ${optionalString (cfg.instance-id != null) "-instance-id ${cfg.instance-id}"}
        '';
        ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
        Restart = "always";
      };
    };

  };  
}