l 3: add telegraf service

This commit is contained in:
lassulus 2017-01-09 17:07:59 +01:00
parent 91c4f86b31
commit 43eaeee506
2 changed files with 68 additions and 0 deletions

View File

@ -9,5 +9,6 @@ _:
./urxvtd.nix
./usershadow.nix
./xresources.nix
./telegraf.nix
];
}

View File

@ -0,0 +1,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