dotfiles/nixos/modules/public/telegraf.nix
Magic_RB 25a8e23045
Add new public modules: grafana, envoy, telegraf
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2023-03-06 00:31:31 +01:00

73 lines
2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.telegraf-magic;
settingsFormat = pkgs.formats.toml {};
configFile = settingsFormat.generate "config.toml" cfg.extraConfig;
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 = type.unspecified;
};
};
};
config = mkIf cfg.enable {
systemd.services.telegraf = mkMerge [
{
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" ];
};
}
(config.services.telegraf.systemd)
];
users.users.telegraf = {
uid = config.ids.uids.telegraf;
group = "telegraf";
description = "telegraf daemon user";
};
users.groups.telegraf = {};
};
}