network monitoring

This commit is contained in:
Alex Tau 2025-06-07 15:59:05 +03:00
parent 8af7b683b6
commit 8b18d407d7
21 changed files with 434 additions and 53 deletions

View file

@ -60,6 +60,15 @@ package:
warning_percentage = warningPercentage;
critical_percentage = criticalPercentage;
};
net.interfaces = lib.mapAttrs (_: interfaceCfg: {
warning_threshold_sent_bytes = interfaceCfg.warningThresholdSentBytes;
critical_threshold_sent_bytes = interfaceCfg.criticalThresholdSentBytes;
warning_threshold_recv_bytes = interfaceCfg.warningThresholdRecvBytes;
critical_threshold_recv_bytes = interfaceCfg.warningThresholdRecvBytes;
warning_threshold_comb_bytes = interfaceCfg.warningThresholdCombBytes;
critical_threshold_comb_bytes = interfaceCfg.criticalThresholdCombBytes;
}) cfg.checks.net.interfaces;
};
};
in lib.mkIf cfg.enable {

View file

@ -6,6 +6,7 @@
let
tempSensorOptions = (import ./suboptions/tempSensorOptions.nix) { inherit lib; };
vulnixWhitelistRule = (import ./suboptions/vulnixWhitelistRule.nix) { inherit lib; };
netInterfaceOptions = (import ./suboptions/netInterfaceOptions.nix) { inherit lib; };
in
{
options.services.lego-monitoring = {
@ -32,6 +33,7 @@ in
"cpu"
"ram"
"temp"
"net"
"vulnix"
]);
@ -96,12 +98,12 @@ in
cpu = {
warningPercentage = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = 80.0;
description = "CPU load percentage for a warning alert to be sent. Null means never generate a CPU warning alert.";
};
criticalPercentage = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = 90.0;
description = "CPU load percentage for a critical alert to be sent. Null means never generate a CPU critical alert.";
};
@ -109,16 +111,31 @@ in
ram = {
warningPercentage = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = 80.0;
description = "RAM usage percentage for a warning alert to be sent. Null means never generate a RAM warning alert.";
};
criticalPercentage = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = 90.0;
description = "RAM usage percentage for a critical alert to be sent. Null means never generate a RAM critical alert.";
};
};
net = {
interfaces = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule netInterfaceOptions);
default = { };
description = "Per-interface configuration of IO byte thresholds.";
example = lib.literalExpression ''
{
br0 = {
warningThresholdCombBytes = 700 * 1024 * 128; # 700 Megabits
criticalThresholdCombBytes = 1 * 1024 * 1024 * 128; # 1 Gigabit
};
}'';
};
};
};
};
}

View file

@ -0,0 +1,39 @@
{
lib,
...
}:
{
options = {
warningThresholdSentBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Sent bytes per second threshold for a warning alert to be sent. If null, this threshold is disabled and not checked.";
};
criticalThresholdSentBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Sent bytes per second threshold for a critical alert to be sent. If null, this threshold is disabled and not checked.";
};
warningThresholdRecvBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Received bytes per second threshold for a warning alert to be sent. If null, this threshold is disabled and not checked.";
};
criticalThresholdRecvBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Received bytes per second threshold for a critical alert to be sent. If null, this threshold is disabled and not checked.";
};
warningThresholdCombBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Combined (sent + received) bytes per second threshold for a warning alert to be sent. If null, this threshold is disabled and not checked.";
};
criticalThresholdCombBytes = lib.mkOption {
type = lib.types.nullOr lib.types.ints.positive;
default = null;
description = "Combined (sent + received) bytes per second threshold for a critical alert to be sent. If null, this threshold is disabled and not checked.";
};
};
}

View file

@ -16,12 +16,12 @@ let
description = "Whether this reading is enabled.";
};
warningTemp = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = null;
description = "Warning temperature threshold.";
};
criticalTemp = lib.mkOption {
type = lib.types.nullOr lib.types.float;
type = lib.types.nullOr lib.types.numbers.positive;
default = null;
description = "Critical temperature threshold.";
};