WIP: extend to monitor mulriple paths for disk usage

This commit is contained in:
2025-12-25 13:56:09 +01:00
parent f5a6458677
commit c1ea85d532
2 changed files with 39 additions and 4 deletions

16
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
}
]
}

View File

@@ -90,7 +90,7 @@ def check_swap():
def check_memory(): def check_memory():
full_cmd = 'free -b | awk \'NR==2 {printf "%.2f\\n", $3/$2 * 100}\'' full_cmd = 'LANG=C free -b | awk \'NR==2 {printf "%.2f\\n", $3/$2 * 100}\''
memory = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] memory = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
if memory: if memory:
@@ -723,10 +723,23 @@ def publish_to_mqtt(monitored_values):
for key, value in monitored_values.items(): for key, value in monitored_values.items():
if key not in non_standard_values and key in config.__dict__ and config.__dict__[key]: if key not in non_standard_values and key in config.__dict__ and config.__dict__[key]:
if config.discovery_messages: if config.discovery_messages:
if isinstance(value, dict):
for k2,v2 in value.items():
k3 = key+'_'+k2
client.publish(f"{config.mqtt_discovery_prefix}/sensor/{config.mqtt_topic_prefix}/{hostname}_{k3}/config",
config_json(key), qos=config.qos)
print('FiX config_JSON!')
else:
client.publish(f"{config.mqtt_discovery_prefix}/sensor/{config.mqtt_topic_prefix}/{hostname}_{key}/config", client.publish(f"{config.mqtt_discovery_prefix}/sensor/{config.mqtt_topic_prefix}/{hostname}_{key}/config",
config_json(key), qos=config.qos) config_json(key), qos=config.qos)
if config.use_availability: if config.use_availability:
client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{key}_availability", 'offline' if value is None else 'online', qos=config.qos) client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{key}_availability", 'offline' if value is None else 'online', qos=config.qos)
if isinstance(value, dict):
for k2,v2 in value.items():
k3 = key+'_'+k2
client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{k3}", v2, qos=config.qos, retain=config.retain)
pass
else:
client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{key}", value, qos=config.qos, retain=config.retain) client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{key}", value, qos=config.qos, retain=config.retain)
# Publish non standard values # Publish non standard values
@@ -899,6 +912,12 @@ def collect_monitored_values():
if config.cpu_temp: if config.cpu_temp:
monitored_values["cpu_temp"] = check_cpu_temp() monitored_values["cpu_temp"] = check_cpu_temp()
if config.used_space: if config.used_space:
if isinstance(config.used_space_path, dict):
monitored_values['used_space'] = {}
for k in config.used_space_path.keys():
v = config.used_space_path[k]
monitored_values[f'used_space'][k] = check_used_space(v)
else:
monitored_values["used_space"] = check_used_space(config.used_space_path) monitored_values["used_space"] = check_used_space(config.used_space_path)
if config.voltage: if config.voltage:
monitored_values["voltage"] = check_voltage() monitored_values["voltage"] = check_voltage()