1
0
forked from c3d2/nix-config
nix-config/modules/stats.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.6 KiB
Nix
Raw Permalink Normal View History

{ config, lib, libC, pkgs, ... }:
let
cfg = config.c3d2.hq.statistics;
isMetal =
!config.boot.isContainer &&
!(config ? microvm);
2023-07-02 05:16:27 +02:00
nginxStatusPort = 9100;
in
{
options.c3d2.hq.statistics = {
enable = lib.mkEnableOption "statistics collection";
};
config = {
networking.firewall.allowedTCPPorts = [ 9100 ];
2023-07-02 05:16:27 +02:00
services = {
collectd = lib.mkIf cfg.enable {
enable = true;
extraConfig = ''
FQDNLookup false
Interval 10
'';
buildMinimalPackage = true;
plugins = {
logfile = ''
LogLevel info
File STDOUT
'';
network = ''
Server "grafana.serv.zentralwerk.org" "25826"
'';
memory = "";
processes = "";
disk = "";
df = "";
cpu = "";
entropy = "";
load = "";
swap = "";
cgroups = "";
vmem = "";
interface = "";
} // lib.optionalAttrs isMetal {
sensors = "";
cpufreq = "";
irq = "";
ipmi = "";
thermal = "";
} // lib.optionalAttrs config.services.nginx.enable {
nginx = ''
URL "http://localhost:${toString nginxStatusPort}/nginx_status"
'';
};
2023-07-02 05:16:27 +02:00
};
2023-07-02 05:16:27 +02:00
nginx = lib.mkMerge [
(lib.mkIf config.services.nginx.enable {
virtualHosts.localhost = {
listen = [
{ addr = "127.0.0.1"; port = nginxStatusPort; }
{ addr = "[::1]"; port = nginxStatusPort; }
];
locations."/nginx_status".extraConfig = ''
stub_status;
access_log off;
allow 127.0.0.1;
allow ::1;
deny all;
'';
};
2023-07-02 05:16:27 +02:00
})
2023-07-02 05:16:27 +02:00
(lib.mkIf (pkgs.system != "riscv64-linux") {
enable = true;
virtualHosts."_" = {
2023-07-02 05:16:27 +02:00
listen = let port = 9100; in [
{ addr = "0.0.0.0"; inherit port; }
{ addr = "[::]"; inherit port; }
];
locations."/metrics" = {
proxyPass = "http://127.0.0.1:${toString config.services.prometheus.exporters.node.port}/metrics";
extraConfig = libC.hqNetworkOnly;
};
};
2023-07-02 05:16:27 +02:00
})
];
2023-07-02 05:16:27 +02:00
prometheus.exporters.node = lib.mkIf (pkgs.system != "riscv64-linux") {
enable = true;
enabledCollectors = [ "ethtool" "systemd" ];
listenAddress = "127.0.0.1";
openFirewall = true;
port = 9101;
};
};
};
}