nix/nixos/common/services/telegraf.nix

78 lines
1.9 KiB
Nix
Raw Normal View History

2024-04-07 08:42:00 +09:00
{ pkgs, ... }: {
2023-07-05 19:04:30 +09:00
# Telegraf Monitoring
2023-07-06 13:23:15 +09:00
# Set up the secrets file for the token:
2023-09-19 13:49:23 +09:00
sops.secrets."services/telegraf" = {
2023-07-05 19:04:30 +09:00
owner = "telegraf";
2023-08-23 17:21:11 +09:00
sopsFile = ../../../secrets/secrets.yaml;
2023-07-05 19:04:30 +09:00
restartUnits = [ "telegraf.service" ];
};
# 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
2024-01-23 14:45:04 +09:00
nvme-cli
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-12-10 18:54:57 +09:00
path = [
pkgs.lm_sensors # sensors
pkgs.smartmontools # smartctl
pkgs.sudo # sudo
2024-01-23 14:45:04 +09:00
pkgs.nvme-cli # nvme command for smartctl
2023-12-10 18:56:37 +09:00
"/run/current-system/sw/bin/nixos-version"
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-09-19 13:49:23 +09:00
environmentFiles = [ /run/secrets/services/telegraf ];
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 = {};
net = {};
2023-08-23 23:23:14 +09:00
# nvidia_smi = {};
2023-07-05 19:47:56 +09:00
sensors = {};
smart = {
2023-07-05 19:54:39 +09:00
timeout = "30s";
2023-07-05 19:47:56 +09:00
};
temp = {};
wireless = {};
2023-12-10 18:25:00 +09:00
exec = {
2023-12-10 18:58:55 +09:00
commands = [ "/run/current-system/sw/bin/nixos-version" ];
2023-12-10 18:45:11 +09:00
name_suffix = "_nixos-version";
2023-12-10 18:25:00 +09:00
data_format = "value";
data_type = "string";
};
2023-07-05 19:47:56 +09:00
};
2023-07-05 19:04:30 +09:00
};
};
2024-04-07 08:42:00 +09:00
}