add temp monitoring

This commit is contained in:
Alex Tau 2025-05-02 15:25:27 +03:00
parent 19ee6f487b
commit 758438382d
13 changed files with 272 additions and 25 deletions

View file

@ -7,17 +7,21 @@ package:
...
}:
let
tempSensorOptions = (import ./submodules/tempSensorOptions.nix) { inherit lib; };
in
{
options.services.lego-monitoring = {
enable = lib.mkEnableOption "lego-monitoring service.";
enabledCheckerSets = lib.mkOption {
enabledCheckSets = lib.mkOption {
type = lib.types.listOf (lib.types.enum [
"start"
"stop"
"temp"
]);
default = [ ];
description = "List of enabled checker sets. Each checker set is a module which checks something and generates alerts based on check results.";
description = "List of enabled check sets. Each check set is a module which checks something and generates alerts based on check results.";
};
telegram = {
@ -30,17 +34,61 @@ package:
description = "ID of chat where to send alerts.";
};
};
checks = {
temp = {
sensors = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule tempSensorOptions);
default = { };
description = ''
Temp sensor override definitions. Sensors not defined here, or missing options in definitions, will be read with default parameters.
To get list of sensors and their default configurations, run `lego-monitoring --print-temp`.'';
example = lib.literalExpression ''
{
amdgpu.readings.edge.label = "Integrated GPU";
k10temp.readings = {
Tctl = {
label = "AMD CPU";
criticalTemp = 95.0;
};
Tccd1.enabled = false;
Tccd2.enabled = false;
};
nvme.readings = {
"Sensor 1".enabled = false;
"Sensor 2".enabled = false;
};
}
'';
};
};
};
};
config = let
cfg = config.services.lego-monitoring;
json = pkgs.formats.json {};
serviceConfigFile = json.generate "config.json" {
enabled_checker_sets = cfg.enabledCheckerSets;
enabled_check_sets = cfg.enabledCheckSets;
telegram = with cfg.telegram; {
creds_secret_path = credsSecretPath;
room_id = roomId;
};
checks = {
temp.sensors = lib.mapAttrs (_: sensorCfg: {
inherit (sensorCfg) name enabled;
readings = lib.mapAttrs (_: readingCfg: {
inherit (readingCfg) label enabled;
warning_temp = readingCfg.warningTemp;
critical_temp = readingCfg.criticalTemp;
}) sensorCfg.readings;
}) cfg.checks.temp.sensors;
};
};
in lib.mkIf cfg.enable {
systemd.services.lego-monitoring = {