services: prometheus: restructure a bit, extract node-exporter

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
This commit is contained in:
Christoph Heiss 2024-03-03 21:31:45 +01:00
parent dcd3379bb4
commit 9219504c20
Signed by: c8h4
GPG key ID: 73D5E7FDEE3DE49A
7 changed files with 54 additions and 40 deletions

View file

@ -27,6 +27,7 @@ in {
../services/fail2ban.nix
../services/matrix-hookshot.nix
../services/nginx.nix
../services/node-exporter.nix
../services/web/c8h4-io.nix
../system/virtual-machine.nix
];

View file

@ -11,6 +11,7 @@
../services/home-assistant.nix
../services/navidrome.nix
../services/nginx.nix
../services/node-exporter.nix
../services/paperless.nix
../services/postgresql.nix
../services/prometheus.nix
@ -108,4 +109,10 @@
listenAddress = "[::1]:8000";
appendOnly = true;
};
services.prometheus.exporters.zfs = {
enable = true;
listenAddress = "[::1]";
extraFlags = [ "--collector.dataset-snapshot" ];
};
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,34 @@
{ config, lib, ... }:
let
inherit (lib) mkOption types;
cfg = config.my.services.node-exporter;
in {
options.my.services.node-exporter = {
listenAddress = mkOption {
type = types.str;
default = "[::1]";
description = "Address to listen on.";
};
};
config = {
services.prometheus.exporters.node = {
enable = true;
inherit (cfg) listenAddress;
enabledCollectors = [ "systemd" ];
# disable a whole bunch of useless/unneeded collectors
disabledCollectors = [
"arp"
"bcache"
"bonding"
"fibrechannel"
"infiniband"
"ipvs"
"selinux"
"tapestats"
"xfs"
];
};
};
}

View file

@ -1,47 +1,17 @@
{ config, my, secrets, ... }:
{ my, secrets, ... }:
let
nodeExporter = config.services.prometheus.exporters.node;
zfsExporter = config.services.prometheus.exporters.zfs;
in {
{
services.prometheus = {
enable = true;
checkConfig = "syntax-only";
webExternalUrl = "http://${my.homelab.fqdn}/prometheus";
listenAddress = "[::1]";
exporters = {
node = {
enable = true;
listenAddress = "[::1]";
enabledCollectors = [ "systemd" ];
# disable a whole bunch of useless/unneeded collectors
disabledCollectors = [
"arp"
"bcache"
"bonding"
"fibrechannel"
"infiniband"
"ipvs"
"selinux"
"tapestats"
"xfs"
"zfs" # we got the dedicated zfs-exporter instead
];
};
zfs = {
enable = true;
listenAddress = "[::1]";
extraFlags = [ "--collector.dataset-snapshot" ];
};
};
scrapeConfigs = [
{
job_name = "zfs-exporter";
scrape_interval = "60s";
static_configs = [{
targets =
[ "${zfsExporter.listenAddress}:${toString zfsExporter.port}" ];
}];
static_configs =
[{ targets = [ "tank:${toString my.services.zfs-exporter.port}" ]; }];
# https://github.com/pdf/zfs_exporter/issues/24#issuecomment-1616802017
metric_relabel_configs = [
{
@ -61,8 +31,10 @@ in {
{
job_name = "node-exporter";
static_configs = [{
targets =
[ "${nodeExporter.listenAddress}:${toString nodeExporter.port}" ];
targets = map (x: "${x}:${toString my.services.node-exporter.port}") [
"fort"
"tank"
];
}];
}
{
@ -72,15 +44,15 @@ in {
metrics_path = "/api/prometheus";
authorization.credentials_file =
secrets.homeassistant-prometheus-token.destination;
scheme = "https";
static_configs =
[{ targets = [ my.homelab.services.homeassistant.host ]; }];
static_configs = [{
targets = [ "tank:${toString my.services.home-assistant.port}" ];
}];
}
{
job_name = "openwrt-exporter";
scrape_interval = "30s";
scheme = "https";
static_configs = [{ targets = [ my.homelab.services.openwrt.host ]; }];
static_configs = [{ targets = [ my.machines.wort.host ]; }];
}
];
};