dotfiles/nixos/modules/public/telegraf.nix
Magic_RB 5532262053
Fix telegraf module
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2023-03-07 23:36:15 +01:00

72 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 = {};
};
}