From 6b06536d0bf3b770ec4e78eec8a4c3347b56dafe Mon Sep 17 00:00:00 2001 From: Masoko Date: Thu, 17 Dec 2020 20:00:01 +0200 Subject: [PATCH] Delete rpi-cpu2mqtt-3.py --- src/rpi-cpu2mqtt-3.py | 143 ------------------------------------------ 1 file changed, 143 deletions(-) delete mode 100644 src/rpi-cpu2mqtt-3.py diff --git a/src/rpi-cpu2mqtt-3.py b/src/rpi-cpu2mqtt-3.py deleted file mode 100644 index 696eb52..0000000 --- a/src/rpi-cpu2mqtt-3.py +++ /dev/null @@ -1,143 +0,0 @@ -# Python 2 script to check cpu load, cpu temperature and free space, -# on a Raspberry Pi computer and publish the data to a MQTT server. -# RUN pip install paho-mqtt -# RUN sudo apt-get install python-pip - -from __future__ import division -import subprocess, time, socket, os -import paho.mqtt.client as paho -import json -import config - -# get device host name - used in mqtt topic -hostname = socket.gethostname() - - -def check_used_space(path): - st = os.statvfs(path) - free_space = st.f_bavail * st.f_frsize - total_space = st.f_blocks * st.f_frsize - used_space = int(100 - ((free_space / total_space) * 100)) - return used_space - -def check_cpu_load(): - # bash command to get cpu load from uptime command - p = subprocess.Popen("uptime", shell=True, stdout=subprocess.PIPE).communicate()[0] - cores = subprocess.Popen("nproc", shell=True, stdout=subprocess.PIPE).communicate()[0] - cpu_load = str(p).split("average:")[1].split(",")[0].replace(' ', '') - cpu_load = float(cpu_load)/int(cores)*100 - cpu_load = round(float(cpu_load), 1) - return cpu_load - -def check_voltage(): - full_cmd = "vcgencmd measure_volts | cut -f2 -d= | sed 's/000//'" - voltage = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - voltage = voltage.strip()[:-1] - return voltage - -def check_swap(): - full_cmd = "free -t | awk 'NR == 3 {print $3/$2*100}'" - swap = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - swap = round(float(swap), 1) - return swap - -def check_memory(): - full_cmd = "free -t | awk 'NR == 2 {print $3/$2*100}'" - memory = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - memory = round(float(memory), 1) - return memory - -def check_cpu_temp(): - full_cmd = "vcgencmd measure_temp" - p = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] - cpu_temp = str(p).replace('\n', ' ').replace('\r', '').split("=")[1].split("'")[0] - return cpu_temp - -def check_sys_clock_speed(): - full_cmd = "awk '{printf (\"%0.0f\",$1/1000); }'