blob: d878673266821c2d47003e675d17ee8a773cd3f6 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.telegraf;
configFile = pkgs.runCommand "config.toml" {
buildInputs = [ pkgs.remarshal ];
preferLocalBuild = true;
} ''
remarshal -if json -of toml \
< ${pkgs.writeText "config.json" (builtins.toJSON cfg.extraConfig)} \
> $out
'';
in {
###### interface
options = {
services.telegraf = {
enable = mkEnableOption "telegraf server";
package = mkOption {
default = pkgs.telegraf;
defaultText = "pkgs.telegraf";
description = "Which telegraf derivation to use";
type = types.package;
};
extraConfig = mkOption {
default = {};
description = "Extra configuration options for telegraf";
type = types.attrs;
example = {
outputs = {
influxdb = {
urls = ["http://localhost:8086"];
database = "telegraf";
};
};
inputs = {
statsd = {
service_address = ":8125";
delete_timings = true;
};
};
};
};
};
};
###### implementation
config = mkIf config.services.telegraf.enable {
systemd.services.telegraf = {
description = "Telegraf Agent";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
ExecStart=''${cfg.package}/bin/telegraf -config "${configFile}"'';
ExecReload="${pkgs.coreutils}/bin/kill -HUP $MAINPID";
User = "telegraf";
Restart = "on-failure";
};
};
users.users = [{
name = "telegraf";
uid = config.ids.uids.telegraf;
description = "telegraf daemon user";
}];
};
}
|