nixos-config/nixos/machines/chungus/telemetry/telegraf.nix

92 lines
2.7 KiB
Nix
Raw Normal View History

2023-05-15 09:30:42 +02:00
{ config, pkgs, ... }:
2023-04-29 23:29:05 +02:00
let
urls = [
{ url = "https://bitwarden.ingolf-wagner.de"; path = ""; }
{ url = "https://flix.ingolf-wagner.de"; path = "web/index.html"; }
{ url = "https://git.ingolf-wagner.de"; path = ""; }
{ url = "https://ingolf-wagner.de"; path = ""; }
{ url = "https://nextcloud.ingolf-wagner.de"; path = "login"; }
{ url = "https://tech.ingolf-wagner.de"; path = ""; }
2024-04-01 18:37:18 +02:00
{ url = "https://matrix.ingolf-wagner.de"; path = ""; }
2023-04-29 23:29:05 +02:00
];
in
{
systemd.services.telegraf.path = [ pkgs.inetutils ];
services.telegraf = {
enable = true;
extraConfig = {
2024-05-14 22:36:08 +02:00
#outputs.prometheus_client = {
# listen = ":9273";
# metric_version = 2;
#};
outputs.influxdb_v2 = {
urls = [ "http://127.0.0.1:8088" ];
2023-04-29 23:29:05 +02:00
};
2024-05-14 22:36:08 +02:00
global_tags = {
service = "telegraf";
server = config.networking.hostName;
};
2023-04-29 23:29:05 +02:00
# https://github.com/influxdata/telegraf/tree/master/plugins/inputs < all them plugins
inputs = {
cpu = { };
diskio = { };
2023-05-15 09:30:42 +02:00
smart.attributes = true;
2023-04-29 23:29:05 +02:00
x509_cert = [{
sources = (map (url: "${url.url}:443") urls);
interval = "30m"; # agent.interval = "10s" is default
}];
http_response =
let fullUrls = map ({ url, path }: "${url}/${path}") urls;
in [{ urls = fullUrls; }];
processes = { };
2023-09-19 15:49:49 +02:00
system = { };
2023-04-29 23:29:05 +02:00
systemd_units = { };
2024-02-13 18:10:29 +01:00
internet_speed.interval = "10m";
2023-04-29 23:29:05 +02:00
nginx.urls = [ "http://localhost/nginx_status" ];
ping = [{ urls = [ "10.100.0.1" ]; }]; # actually important to make pepe visible over wireguard
};
};
};
2024-05-14 22:36:08 +02:00
# todo : do this prometheus
2023-04-29 23:29:05 +02:00
services.prometheus.ruleFiles = [
(pkgs.writeText "telegraf.yml" (builtins.toJSON {
groups = [
{
name = "telegraf";
rules = [
{
alert = "HttpResponseNotOk";
expr = "0 * (http_response_http_response_code != 200) + 1";
for = "5m";
labels.severity = "page";
annotations = {
summary = "{{ $labels.exported_server }} does not return Ok";
description = "{{ $labels.exported_server }} does not return Ok for more than 5 minutes";
};
}
{
alert = "CertificatExpires";
expr = ''x509_cert_expiry{issuer_common_name="R3"} < ${toString (60 * 60 * 24 * 5)}'';
for = "1d";
labels.severity = "page";
annotations = {
summary = "{{ $labels.san }} does Expire Soon";
description = "{{ $labels.san }} does expire in less than 5 days";
};
}
];
}
];
}))
];
}