nix/services/telegraf.nix

89 lines
2.3 KiB
Nix
Raw Normal View History

2023-07-05 19:04:30 +09:00
{ config, pkgs, hostname, ... }: {
# Telegraf Monitoring
2023-07-06 13:23:15 +09:00
# Set up the secrets file for the token:
2023-07-05 19:47:56 +09:00
sops.secrets.telegraf-token = {
2023-07-05 19:04:30 +09:00
owner = "telegraf";
sopsFile = ../secrets/secrets.yaml;
restartUnits = [ "telegraf.service" ];
};
2023-07-06 13:23:15 +09:00
# Add telegraf to "wheel" to allow the use of sudo:
2023-07-06 12:36:04 +09:00
users.users.telegraf = {
2023-07-06 15:01:30 +09:00
extraGroups = [ "root" ];
2023-07-06 13:16:24 +09:00
isSystemUser = true;
2023-07-06 12:35:33 +09:00
};
2023-07-06 13:16:24 +09:00
# Allow the telegraf account to invoke sudo without a password
security.sudo.extraConfig = ''
2023-07-06 13:19:09 +09:00
Cmnd_Alias FAIL2BAN = /run/current-system/sw/bin/fail2ban-client status, /run/current-system/sw/bin/fail2ban-client status *
2023-07-06 13:16:24 +09:00
telegraf ALL=(root) NOEXEC: NOPASSWD: FAIL2BAN
Defaults!FAIL2BAN !logfile, !syslog, !pam_session
'';
2023-07-05 19:04:30 +09:00
# Install the package
environment.systemPackages = with pkgs; [
2023-07-05 19:55:15 +09:00
lm_sensors
2023-07-05 19:04:30 +09:00
telegraf
2023-07-05 21:26:30 +09:00
smartmontools
2023-07-06 14:13:15 +09:00
fail2ban
2023-07-05 19:04:30 +09:00
];
2023-07-05 21:24:39 +09:00
# Allow telegraf to talk to other executables it requires:
2023-07-05 21:04:12 +09:00
systemd.services.telegraf = {
2023-07-05 21:04:53 +09:00
path = with pkgs; [
2023-07-05 21:26:30 +09:00
lm_sensors # sensors
2023-07-06 14:54:53 +09:00
# fail2ban # fail2ban-client
2023-07-05 21:26:30 +09:00
linuxPackages.nvidia_x11 # nvidia-smi
smartmontools # smartctl
2023-07-06 13:02:15 +09:00
sudo # sudo
2023-07-05 21:04:12 +09:00
];
};
2023-07-05 21:03:36 +09:00
2023-07-05 19:04:30 +09:00
# Configure the package:
services.telegraf = {
enable = true;
2023-07-05 19:52:22 +09:00
environmentFiles = [ /run/secrets/telegraf-token ];
2023-07-05 19:04:30 +09:00
extraConfig = {
2023-07-05 19:47:56 +09:00
outputs = {
influxdb_v2 = {
urls = [ "https://influx.sysctl.io/" ];
2023-07-05 19:53:01 +09:00
token = "$TELEGRAF_TOKEN";
2023-07-05 19:47:56 +09:00
organization = "default";
bucket = "telegrafdb";
2023-07-05 20:45:21 +09:00
http_headers = { Authorization = "Token $TELEGRAF_TOKEN"; };
2023-07-05 19:47:56 +09:00
};
};
inputs = {
cpu = {
percpu = true;
totalcpu = true;
collect_cpu_time = false;
report_active = false;
};
2023-07-05 20:24:09 +09:00
disk = {
2023-07-05 20:30:54 +09:00
ignore_fs = ["tmpfs" "devtmpfs" "devfs" "iso9660" "overlay" "aufs" "squashfs"];
2023-07-05 20:24:09 +09:00
};
2023-07-05 19:47:56 +09:00
diskio = {};
kernel = {};
mem = {};
processes = {};
swap = {};
system = {};
2023-07-06 13:00:49 +09:00
fail2ban = {
2023-07-06 15:01:30 +09:00
# use_sudo = true;
2023-07-06 14:59:21 +09:00
socket = "/var/run/fail2ban/fail2ban.sock";
2023-07-06 13:00:49 +09:00
};
2023-07-05 19:47:56 +09:00
intel_powerstat = {};
net = {};
nvidia_smi = {};
sensors = {};
smart = {
2023-07-05 19:54:39 +09:00
timeout = "30s";
2023-07-05 19:47:56 +09:00
};
temp = {};
wireless = {};
};
2023-07-05 19:04:30 +09:00
};
};
}