nixos-config/systems/LoutreOS/monitoring.nix

128 lines
3.6 KiB
Nix
Raw Normal View History

2019-11-01 15:24:50 +01:00
{ config, lib, pkgs, ... }:
let
domaine = "nyanlout.re";
in
{
services = {
smartd = {
enable = true;
2022-06-30 18:58:34 +02:00
defaults.monitored = "-a -o on -s (S/../.././02|L/../15/./02)";
2019-11-01 15:24:50 +01:00
notifications.mail = {
enable = true;
recipient = "paul@nyanlout.re";
};
};
influxdb = {
enable = true;
dataDir = "/var/db/influxdb";
};
telegraf = {
enable = true;
extraConfig = {
inputs = {
zfs = { poolMetrics = true; };
net = { interfaces = [ "eno1" "eno2" "eno3" "eno4" ]; };
netstat = {};
cpu = { totalcpu = true; };
kernel = {};
mem = {};
processes = {};
system = {};
disk = {};
cgroup = [
{
paths = [
2021-10-11 15:35:02 +02:00
"/sys/fs/cgroup/system.slice/*"
];
2021-10-11 15:35:02 +02:00
files = ["memory.current" "cpu.stat"];
}
];
2019-11-01 15:24:50 +01:00
ipmi_sensor = { path = "${pkgs.ipmitool}/bin/ipmitool"; };
smart = {
path = "${pkgs.writeShellScriptBin "smartctl" "/run/wrappers/bin/sudo ${pkgs.smartmontools}/bin/smartctl $@"}/bin/smartctl";
};
exec= [
{
commands = [
"${pkgs.python3}/bin/python ${pkgs.writeText "zpool.py" ''
import json
from subprocess import check_output
2019-11-02 13:54:12 +01:00
columns = ["NAME", "SIZE", "ALLOC", "FREE", "CKPOINT", "EXPANDSZ", "FRAG", "CAP", "DEDUP", "HEALTH", "ALTROOT"]
2019-11-01 15:24:50 +01:00
health = {'ONLINE':0, 'DEGRADED':11, 'OFFLINE':21, 'UNAVAIL':22, 'FAULTED':23, 'REMOVED':24}
stdout = check_output(["${pkgs.zfs}/bin/zpool", "list", "-Hp"],encoding='UTF-8').split('\n')
parsed_stdout = list(map(lambda x: dict(zip(columns,x.split('\t'))), stdout))[:-1]
for pool in parsed_stdout:
for item in pool:
if item in ["SIZE", "ALLOC", "FREE", "FRAG", "CAP"]:
pool[item] = int(pool[item])
if item in ["DEDUP"]:
pool[item] = float(pool[item])
if item == "HEALTH":
pool[item] = health[pool[item]]
print(json.dumps(parsed_stdout))
''}"
];
tag_keys = [ "NAME" ];
data_format = "json";
name_suffix = "_python_zpool";
}
];
};
outputs = {
influxdb = { database = "telegraf"; urls = [ "http://localhost:8086" ]; };
};
};
};
udev.extraRules = ''
KERNEL=="ipmi*", MODE="660", OWNER="telegraf"
'';
grafana = {
enable = true;
dataDir = "/var/lib/grafana";
2022-12-30 15:08:20 +01:00
settings = {
server = {
http_addr = "127.0.0.1";
root_url = "https://grafana.${domaine}";
};
smtp = {
enabled = true;
from_address = "grafana@${domaine}";
skip_verify = true;
};
auth = {
disable_signout_menu = true;
};
"auth.basic" = {
enabled = false;
};
"auth.proxy" = {
enabled = true;
header_name = "X-WEBAUTH-USER";
};
2019-11-01 15:24:50 +01:00
};
};
2020-04-08 12:53:30 +02:00
zfs.zed.settings = {
ZED_EMAIL_ADDR = [ "paul@nyanlout.re" ];
ZED_NOTIFY_VERBOSE = true;
};
2019-11-01 15:24:50 +01:00
};
2022-10-10 23:05:21 +02:00
systemd.services.influxdb.serviceConfig = {
TimeoutStartSec = "10min";
};
2019-11-01 15:24:50 +01:00
security.sudo.extraRules = [
{ commands = [ { command = "${pkgs.smartmontools}/bin/smartctl"; options = [ "NOPASSWD" ]; } ]; users = [ "telegraf" ]; }
];
}