WIP: extend to monitor mulriple paths for disk usage
This commit is contained in:
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal 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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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,11 +723,24 @@ 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:
|
||||||
client.publish(f"{config.mqtt_discovery_prefix}/sensor/{config.mqtt_topic_prefix}/{hostname}_{key}/config",
|
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",
|
||||||
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)
|
||||||
client.publish(f"{config.mqtt_uns_structure}{config.mqtt_topic_prefix}/{hostname}/{key}", value, qos=config.qos, retain=config.retain)
|
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)
|
||||||
|
|
||||||
# Publish non standard values
|
# Publish non standard values
|
||||||
if config.restart_button:
|
if config.restart_button:
|
||||||
@@ -899,7 +912,13 @@ 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:
|
||||||
monitored_values["used_space"] = check_used_space(config.used_space_path)
|
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)
|
||||||
if config.voltage:
|
if config.voltage:
|
||||||
monitored_values["voltage"] = check_voltage()
|
monitored_values["voltage"] = check_voltage()
|
||||||
if config.sys_clock_speed:
|
if config.sys_clock_speed:
|
||||||
|
|||||||
Reference in New Issue
Block a user