123 lines
3.7 KiB
Nix
123 lines
3.7 KiB
Nix
{ pkgs, lib, config, ... }:
|
|
let
|
|
cfg = config.stura.monitoring;
|
|
in {
|
|
options.stura.monitoring = {
|
|
extraLogFiles = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [];
|
|
description = "Additional log file paths for vector to scrape and forward to Loki.";
|
|
example = [ "/var/log/nginx/access.log" "/var/log/nginx/error.log" ];
|
|
};
|
|
|
|
extraGroups = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [];
|
|
description = "Supplementary groups added to the vector systemd service to allow reading protected log files.";
|
|
example = [ "nginx" "postfix" ];
|
|
};
|
|
|
|
extraMetricInputs = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [];
|
|
description = "Additional vector component IDs to feed into the mimir sink alongside host_metrics.";
|
|
example = [ "proxmox_normalize_metrics" ];
|
|
};
|
|
|
|
extraLogInputs = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [];
|
|
description = "Additional vector component IDs to feed into the loki sink alongside journald_logs.";
|
|
example = [ "proxmox_normalize_logs" ];
|
|
};
|
|
};
|
|
|
|
config = {
|
|
networking.hosts = {
|
|
# rewrite these host entries on each system, this does not go through proxy
|
|
"141.56.51.20" = [
|
|
"mon.adm.htw.stura-dresden.de"
|
|
"log.adm.htw.stura-dresden.de"
|
|
"met.adm.htw.stura-dresden.de"
|
|
];
|
|
};
|
|
services.vector = {
|
|
enable = true;
|
|
settings = {
|
|
sources = {
|
|
host_metrics = {
|
|
type = "host_metrics";
|
|
collectors = [
|
|
"cpu"
|
|
"disk"
|
|
"filesystem"
|
|
"load"
|
|
"host"
|
|
"memory"
|
|
"network"
|
|
"process"
|
|
];
|
|
};
|
|
|
|
journald_logs = {
|
|
type = "journald";
|
|
include_units = []; # empty = collect all units
|
|
};
|
|
} // lib.optionalAttrs (cfg.extraLogFiles != [] || config.services.nginx.enable) {
|
|
extra_log_files = {
|
|
type = "file";
|
|
include = lib.optional config.services.nginx.enable "/var/log/nginx/access.log"
|
|
++ cfg.extraLogFiles;
|
|
};
|
|
};
|
|
|
|
transforms = {
|
|
add_host_label_metrics = {
|
|
type = "remap";
|
|
inputs = [ "host_metrics" ];
|
|
source = ''
|
|
.tags.host = get_hostname!()
|
|
del(.tags.command)
|
|
'';
|
|
};
|
|
|
|
add_host_label_logs = {
|
|
type = "remap";
|
|
inputs = [ "journald_logs" ] ++ lib.optional (cfg.extraLogFiles != [] || config.services.nginx.enable) "extra_log_files";
|
|
source = ''
|
|
.host = get_hostname!()
|
|
.unit = string(."_SYSTEMD_UNIT") ?? "file"
|
|
'';
|
|
};
|
|
};
|
|
|
|
sinks = {
|
|
mimir = {
|
|
type = "prometheus_remote_write";
|
|
inputs = [ "add_host_label_metrics" ] ++ cfg.extraMetricInputs;
|
|
endpoint = "https://met.adm.htw.stura-dresden.de/api/v1/push";
|
|
tls.verify_certificate = false;
|
|
healthcheck.enabled = false;
|
|
};
|
|
|
|
loki = {
|
|
type = "loki";
|
|
inputs = [ "add_host_label_logs" ] ++ cfg.extraLogInputs;
|
|
endpoint = "https://log.adm.htw.stura-dresden.de";
|
|
labels = {
|
|
host = "{{ host }}";
|
|
unit = "{{ unit }}";
|
|
};
|
|
tls.verify_certificate = false;
|
|
encoding.codec = "json";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
systemd.services.vector.serviceConfig.SupplementaryGroups =
|
|
[ "systemd-journal" ]
|
|
++ lib.optional config.services.nginx.enable "nginx"
|
|
++ cfg.extraGroups;
|
|
};
|
|
}
|