summaryrefslogtreecommitdiffstats
path: root/lass/3modules/telegraf.nix
blob: 64b323460f8476eebf42ab412cfc6b213fc1abee (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
{ config, lib, pkgs, ... }:

with builtins;
with lib;

let
  cfg = config.lass.telegraf;

  out = {
    options.lass.telegraf = api;
    config = mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "telegraf";
    dataDir = mkOption {
      type = types.str;
      default = "/var/lib/telegraf";
    };
    user = mkOption {
      type = types.str;
      default = "telegraf";
    };
    config = mkOption {
      type = types.str;
      #TODO: find a good default
      default = ''
        [agent]
            interval = "1s"

        [outputs]

        # Configuration to send data to InfluxDB.
        [outputs.influxdb]
            urls = ["http://localhost:8086"]
            database = "kapacitor_example"
            user_agent = "telegraf"

        # Collect metrics about cpu usage
        [cpu]
            percpu = false
            totalcpu = true
            drop = ["cpu_time"]
      '';
      description = "configuration telegraf is started with";
    };
  };

  configFile = pkgs.writeText "telegraf.conf" cfg.config;

  imp = {

    systemd.services.telegraf = {
      description = "telegraf";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      restartIfChanged = true;

      serviceConfig = {
        Restart = "always";
        ExecStart = "${pkgs.telegraf}/bin/telegraf -config ${configFile}";
      };
    };
  };

in out