2017-01-09 16:07:59 +00:00
|
|
|
{ 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";
|
|
|
|
};
|
2017-01-30 21:56:12 +00:00
|
|
|
outputs = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ''
|
|
|
|
[outputs.influxdb]
|
|
|
|
urls = ["http://localhost:8086"]
|
|
|
|
database = "all_data"
|
|
|
|
user_agent = "telegraf"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
inputs = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [
|
|
|
|
''
|
|
|
|
[cpu]
|
|
|
|
percpu = false
|
|
|
|
totalcpu = true
|
|
|
|
drop = ["cpu_time"]
|
|
|
|
''
|
|
|
|
];
|
|
|
|
};
|
2017-01-09 16:07:59 +00:00
|
|
|
config = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
#TODO: find a good default
|
|
|
|
default = ''
|
|
|
|
[agent]
|
|
|
|
interval = "1s"
|
|
|
|
|
|
|
|
[outputs]
|
|
|
|
|
2017-01-30 21:56:12 +00:00
|
|
|
${cfg.outputs}
|
|
|
|
|
|
|
|
${concatStringsSep "\n" cfg.inputs}
|
2017-01-09 16:07:59 +00:00
|
|
|
|
|
|
|
'';
|
|
|
|
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
|