16
.editorconfig
Normal file
16
.editorconfig
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# EditorConfig is awesome: http://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
[LICENSE]
|
||||||
|
indent_style = none
|
||||||
|
indent_size = none
|
||||||
@@ -19,21 +19,21 @@ import update
|
|||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
|
|
||||||
def check_wifi_signal(format):
|
def check_wifi_signal(format):
|
||||||
try:
|
try:
|
||||||
full_cmd = "ls /sys/class/ieee80211/*/device/net/"
|
full_cmd = "ls /sys/class/ieee80211/*/device/net/"
|
||||||
interface = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].strip().decode("utf-8")
|
interface = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].strip().decode("utf-8")
|
||||||
full_cmd = "/sbin/iwconfig {} | grep -i quality".format(interface)
|
full_cmd = "/sbin/iwconfig {} | grep -i quality".format(interface)
|
||||||
wifi_signal = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
wifi_signal = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
if format == 'dbm':
|
if format == 'dbm':
|
||||||
wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[4].split('=')[1]
|
wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[4].split('=')[1]
|
||||||
else:
|
else:
|
||||||
wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[1].split('=')[1].split('/')[0]
|
wifi_signal = wifi_signal.decode("utf-8").strip().split(' ')[1].split('=')[1].split('/')[0]
|
||||||
wifi_signal = round((int(wifi_signal) / 70)* 100)
|
wifi_signal = round((int(wifi_signal) / 70)* 100)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
wifi_signal = 0
|
wifi_signal = 0
|
||||||
|
|
||||||
return wifi_signal
|
return wifi_signal
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ def check_used_space(path):
|
|||||||
free_space = st.f_bavail * st.f_frsize
|
free_space = st.f_bavail * st.f_frsize
|
||||||
total_space = st.f_blocks * st.f_frsize
|
total_space = st.f_blocks * st.f_frsize
|
||||||
used_space = int(100 - ((free_space / total_space) * 100))
|
used_space = int(100 - ((free_space / total_space) * 100))
|
||||||
|
|
||||||
return used_space
|
return used_space
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ def check_cpu_load():
|
|||||||
cpu_load = str(p).split("average:")[1].split(", ")[0].replace(' ', '').replace(',', '.')
|
cpu_load = str(p).split("average:")[1].split(", ")[0].replace(' ', '').replace(',', '.')
|
||||||
cpu_load = float(cpu_load) / int(cores) * 100
|
cpu_load = float(cpu_load) / int(cores) * 100
|
||||||
cpu_load = round(float(cpu_load), 1)
|
cpu_load = round(float(cpu_load), 1)
|
||||||
|
|
||||||
return cpu_load
|
return cpu_load
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ def check_voltage():
|
|||||||
voltage = voltage.strip()[:-1]
|
voltage = voltage.strip()[:-1]
|
||||||
except Exception:
|
except Exception:
|
||||||
voltage = 0
|
voltage = 0
|
||||||
|
|
||||||
return voltage.decode('utf8')
|
return voltage.decode('utf8')
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ def check_swap():
|
|||||||
full_cmd = "free -t |grep -i swap | awk 'NR == 1 {print $3/$2*100}'"
|
full_cmd = "free -t |grep -i swap | awk 'NR == 1 {print $3/$2*100}'"
|
||||||
swap = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
swap = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||||
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)
|
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)
|
||||||
|
|
||||||
return swap
|
return swap
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ def check_memory():
|
|||||||
full_cmd = "free -t | awk 'NR == 2 {print $3/$2*100}'"
|
full_cmd = "free -t | awk 'NR == 2 {print $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]
|
||||||
memory = round(float(memory.decode("utf-8").replace(",", ".")))
|
memory = round(float(memory.decode("utf-8").replace(",", ".")))
|
||||||
|
|
||||||
return memory
|
return memory
|
||||||
|
|
||||||
|
|
||||||
@@ -90,19 +90,19 @@ def check_cpu_temp():
|
|||||||
cpu_temp = p.decode("utf-8").strip()
|
cpu_temp = p.decode("utf-8").strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
cpu_temp = 0
|
cpu_temp = 0
|
||||||
|
|
||||||
return cpu_temp
|
return cpu_temp
|
||||||
|
|
||||||
|
|
||||||
def check_sys_clock_speed():
|
def check_sys_clock_speed():
|
||||||
full_cmd = "awk '{printf (\"%0.0f\",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
|
full_cmd = "awk '{printf (\"%0.0f\",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
|
||||||
|
|
||||||
return subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
return subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
|
|
||||||
def check_uptime():
|
def check_uptime():
|
||||||
full_cmd = "awk '{print int($1/3600/24)}' /proc/uptime"
|
full_cmd = "awk '{print int($1/3600/24)}' /proc/uptime"
|
||||||
|
|
||||||
return int(subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0])
|
return int(subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0])
|
||||||
|
|
||||||
|
|
||||||
@@ -113,14 +113,14 @@ def check_model_name():
|
|||||||
full_cmd = "cat /proc/cpuinfo | grep 'name'| uniq"
|
full_cmd = "cat /proc/cpuinfo | grep 'name'| uniq"
|
||||||
model_name = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
model_name = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
||||||
model_name = model_name.split(':')[1]
|
model_name = model_name.split(':')[1]
|
||||||
|
|
||||||
return model_name
|
return model_name
|
||||||
|
|
||||||
|
|
||||||
def check_rpi5_fan_speed():
|
def check_rpi5_fan_speed():
|
||||||
full_cmd = "cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input"
|
full_cmd = "cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input"
|
||||||
rpi5_fan_speed = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8").strip()
|
rpi5_fan_speed = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8").strip()
|
||||||
|
|
||||||
return rpi5_fan_speed
|
return rpi5_fan_speed
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ def get_os():
|
|||||||
full_cmd = 'cat /etc/os-release | grep -i pretty_name'
|
full_cmd = 'cat /etc/os-release | grep -i pretty_name'
|
||||||
pretty_name = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
pretty_name = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
||||||
pretty_name = pretty_name.split('=')[1].replace('"', '').replace('\n', '')
|
pretty_name = pretty_name.split('=')[1].replace('"', '').replace('\n', '')
|
||||||
|
|
||||||
return(pretty_name)
|
return(pretty_name)
|
||||||
|
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ def get_manufacturer():
|
|||||||
pretty_name = pretty_name.split(':')[1]
|
pretty_name = pretty_name.split(':')[1]
|
||||||
else:
|
else:
|
||||||
pretty_name = 'Raspberry Pi'
|
pretty_name = 'Raspberry Pi'
|
||||||
|
|
||||||
return(pretty_name)
|
return(pretty_name)
|
||||||
|
|
||||||
|
|
||||||
@@ -154,13 +154,13 @@ def check_git_update(script_dir):
|
|||||||
git_update = 'off'
|
git_update = 'off'
|
||||||
else:
|
else:
|
||||||
git_update = 'on'
|
git_update = 'on'
|
||||||
|
|
||||||
return(git_update)
|
return(git_update)
|
||||||
|
|
||||||
def check_git_version(script_dir):
|
def check_git_version(script_dir):
|
||||||
full_cmd = "git -C {} describe --tags `git -C {} rev-list --tags --max-count=1`".format(script_dir, script_dir)
|
full_cmd = "git -C {} describe --tags `git -C {} rev-list --tags --max-count=1`".format(script_dir, script_dir)
|
||||||
git_version = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
git_version = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
||||||
|
|
||||||
return(git_version)
|
return(git_version)
|
||||||
|
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ def parse_arguments():
|
|||||||
if args.update:
|
if args.update:
|
||||||
version = check_git_version_remote(script_dir).strip()
|
version = check_git_version_remote(script_dir).strip()
|
||||||
git_update = check_git_update(script_dir)
|
git_update = check_git_update(script_dir)
|
||||||
|
|
||||||
if git_update == 'on':
|
if git_update == 'on':
|
||||||
git_update = True
|
git_update = True
|
||||||
else:
|
else:
|
||||||
@@ -448,7 +448,7 @@ def parse_arguments():
|
|||||||
print("No update available")
|
print("No update available")
|
||||||
exit()
|
exit()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
@@ -460,10 +460,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# delay the execution of the script
|
# delay the execution of the script
|
||||||
if hasattr(config, 'random_delay'): time.sleep(config.random_delay)
|
if hasattr(config, 'random_delay'): time.sleep(config.random_delay)
|
||||||
|
|
||||||
if hasattr(config, 'used_space_path'): used_space_path = config.used_space_path
|
if hasattr(config, 'used_space_path'): used_space_path = config.used_space_path
|
||||||
else: used_space_path = '/'
|
else: used_space_path = '/'
|
||||||
|
|
||||||
# collect the monitored values
|
# collect the monitored values
|
||||||
if config.cpu_load:
|
if config.cpu_load:
|
||||||
cpu_load = check_cpu_load()
|
cpu_load = check_cpu_load()
|
||||||
@@ -489,11 +489,11 @@ if __name__ == '__main__':
|
|||||||
rpi5_fan_speed = check_rpi5_fan_speed()
|
rpi5_fan_speed = check_rpi5_fan_speed()
|
||||||
if config.git_update:
|
if config.git_update:
|
||||||
git_update = check_git_update(script_dir)
|
git_update = check_git_update(script_dir)
|
||||||
|
|
||||||
# Display collected values on screen if --display option is used
|
# Display collected values on screen if --display option is used
|
||||||
if args.display:
|
if args.display:
|
||||||
print_measured_values()
|
print_measured_values()
|
||||||
|
|
||||||
# Publish messages to MQTT
|
# Publish messages to MQTT
|
||||||
if hasattr(config, 'group_messages') and config.group_messages:
|
if hasattr(config, 'group_messages') and config.group_messages:
|
||||||
bulk_publish_to_mqtt(cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, wifi_signal, wifi_signal_dbm, rpi5_fan_speed, git_update)
|
bulk_publish_to_mqtt(cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, wifi_signal, wifi_signal_dbm, rpi5_fan_speed, git_update)
|
||||||
|
|||||||
Reference in New Issue
Block a user