mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-27 10:36:12 +01:00
73 lines
1.9 KiB
Nix
73 lines
1.9 KiB
Nix
|
{ config, lib, pkgs, ... }:
|
||
|
with lib;
|
||
|
let
|
||
|
cfg = config.services.telegraf-magic;
|
||
|
|
||
|
settingsFormat = pkgs.formats.toml {};
|
||
|
configFile = settingsFormat.generate "config.toml" cfg.settings;
|
||
|
in {
|
||
|
options = {
|
||
|
services.telegraf-magic = {
|
||
|
enable = mkEnableOption (lib.mdDoc "telegraf server");
|
||
|
|
||
|
package = mkOption {
|
||
|
default = pkgs.telegraf;
|
||
|
defaultText = literalExpression "pkgs.telegraf";
|
||
|
description = lib.mdDoc "Which telegraf derivation to use";
|
||
|
type = types.package;
|
||
|
};
|
||
|
|
||
|
settings = mkOption {
|
||
|
default = {};
|
||
|
description = lib.mdDoc "Extra configuration options for telegraf";
|
||
|
type = settingsFormat.type;
|
||
|
example = {
|
||
|
outputs.influxdb = {
|
||
|
urls = ["http://localhost:8086"];
|
||
|
database = "telegraf";
|
||
|
};
|
||
|
inputs.statsd = {
|
||
|
service_address = ":8125";
|
||
|
delete_timings = true;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
systemd = mkOption {
|
||
|
default = {};
|
||
|
description = lib.mdDoc "Applied to `systemd.services.telegraf`.";
|
||
|
type = types.unspecified;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config = mkIf cfg.enable {
|
||
|
systemd.services.telegraf = mkMerge [
|
||
|
(cfg.systemd)
|
||
|
{
|
||
|
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";
|
||
|
RuntimeDirectory = "telegraf";
|
||
|
User = "telegraf";
|
||
|
Group = "telegraf";
|
||
|
Restart = "on-failure";
|
||
|
# for ping probes
|
||
|
AmbientCapabilities = [ "CAP_NET_RAW" ];
|
||
|
};
|
||
|
}
|
||
|
];
|
||
|
|
||
|
users.users.telegraf = {
|
||
|
uid = config.ids.uids.telegraf;
|
||
|
group = "telegraf";
|
||
|
description = "telegraf daemon user";
|
||
|
};
|
||
|
|
||
|
users.groups.telegraf = {};
|
||
|
};
|
||
|
}
|