update -d output to be more informative and pretty

This commit is contained in:
Hristo
2024-01-27 23:02:20 +02:00
parent af40ed593c
commit c9c3177f5c
2 changed files with 63 additions and 29 deletions

View File

@@ -143,19 +143,26 @@ Run Raspberry Pi MQTT Monitor (you might need to update the path in the command
Once you run Raspberry Pi MQTT monitor you should see something like this:
```
:: Device Information
Model Name: Intel(R) Pentium(R) Silver J5040 CPU @ 2.00GHz
Manufacturer: GenuineIntel
OS: Ubuntu 23.10
Hostname: ubuntu-pc
CPU Load: 30.8
CPU Temp: 66
IP Address: 192.168.0.200
:: Measured values
CPU Load: 71.0
CPU Temp: 68
Used Space: 11
Voltage: False
CPU Clock Speed: False
Swap: False
Memory: 65
Memory: 67
Uptime: 0
Wifi Signal: False
Wifi Signal dBm: False
RPI5 Fan Speed: False
Git Update: on
Git Update: off
```
## Schedule Raspberry Pi MQTT Monitor execution as a service

View File

@@ -153,6 +153,44 @@ def check_git_update():
return(git_update)
def get_network_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP
def print_values():
print(":: Device Information")
print(" Model Name: " + check_model_name().strip())
print(" Manufacturer: " + get_manufacturer().strip())
print(" OS: " + get_os().strip())
print(" Hostname: " + hostname)
print(" IP Address: " + get_network_ip())
if args.service:
print(" Service Sleep Time: " + str(config.service_sleep_time))
print("")
print(":: Measured values")
print(" CPU Load: " + str(cpu_load))
print(" CPU Temp: " + str(cpu_temp))
print(" Used Space: " + str(used_space))
print(" Voltage: " + str(voltage))
print(" CPU Clock Speed: " + str(sys_clock_speed))
print(" Swap: " + str(swap))
print(" Memory: " + str(memory))
print(" Uptime: " + str(uptime_days))
print(" Wifi Signal: " + str(wifi_signal))
print(" Wifi Signal dBm: " + str(wifi_signal_dbm))
print(" RPI5 Fan Speed: " + str(rpi5_fan_speed))
print(" Git Update: " + str(git_update))
print("")
def config_json(what_config):
model_name = check_model_name()
manufacturer = get_manufacturer()
@@ -357,6 +395,7 @@ def bulk_publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_cl
client.disconnect()
if __name__ == '__main__':
# parse arguments
parser = argparse.ArgumentParser()
@@ -400,21 +439,9 @@ if __name__ == '__main__':
if config.git_update:
git_update = check_git_update()
# Display collected values on screen if --display option is used
if args.display:
print("Hostname: " + hostname)
print("CPU Load: " + str(cpu_load))
print("CPU Temp: " + str(cpu_temp))
print("Used Space: " + str(used_space))
print("Voltage: " + str(voltage))
print("CPU Clock Speed: " + str(sys_clock_speed))
print("Swap: " + str(swap))
print("Memory: " + str(memory))
print("Uptime: " + str(uptime_days))
print("Wifi Signal: " + str(wifi_signal))
print("Wifi Signal dBm: " + str(wifi_signal_dbm))
print("RPI5 Fan Speed: " + str(rpi5_fan_speed))
print("Git Update: " + str(git_update))
print("")
print_values()
# Publish messages to MQTT
if hasattr(config, 'group_messages') and config.group_messages: