Skip to content

Commit

Permalink
version 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed May 6, 2022
1 parent e437790 commit 2982a57
Show file tree
Hide file tree
Showing 32 changed files with 158 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ Version control history:
* Users using mail mode option will have to install and configure msmtp.
* Details in Readme.

* version 2.3-4 05-05-202
* added new graph mode option 12 GPU & CPU% & RAM% versus live time
* Automated creation of config file if missing (on start up new user)
2 changes: 1 addition & 1 deletion Documentation/rpi_tempmon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
RPI_AuthUser[email protected]
MAIL_ALERT=1
ALARM_MODE=1
CPU_UPPERLIMIT=70
CPU_UPPERLIMIT=20
LED_MODE=1
GPIO_LED=26
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added Documentation/screenshots/graphmode12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
55 changes: 25 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ Overview
--------------------------------------------
* Name: rpi_tempmon
* Title : Display the ARM CPU and GPU temperature of Raspberry Pi
* Description: This python program will display the ARM CPU and
* Description:

This python program will display the ARM CPU and
GPU temperature of a Raspberry Pi
features include command line display, GPIO (LED) output, logging, alarm limit,
graphing, desktop notification, stress tests and e-mailing options.
The program is written in python 3. It is run in terminal and uses matplotlib
plots for graph modes. This software was built and tested on a raspberry pi 3 model B,
running Linux, Raspbian 8.0 jessie, LXDE lxpanel 0.7.2, Python 3.4.2.
It is run in terminal and uses matplotlib
plots for graph modes.

* Author: Gavin Lyons
* URL: https://github.com/gavinlyonsrepo/raspeberrypi_tempmon
* History: [Changelog is at repository in documentation section](Documentation/CHANGELOG.md)
* Copyright: Copyright (C) 2017 - Gavin Lyons - GPLv3 [License is at repository in documentation section](Documentation/LICENSE.txt)
* Toolchain: RPI 3 model B, Raspbian 10 Buster, LXDE lxpanel 0.10.0,
Python 3.7.3.

Table of contents
---------------------------
Expand All @@ -30,25 +32,17 @@ Installation
-----------------------------------------------

For Linux OS users. raspberrypi_tempmon is a python 3 program
Make sure that:

* python3
* pip3

Have been installed on your machine,

Then Install with:
Make sure that: python3 & pip3 Have been installed on your machine,
Then Install form PyPi with:

```sh
sudo pip3 install rpi_tempmon.py
```


Usage
-------------------------------------------
Program is a python 3 package.

Run in a terminal by typing rpi_tempmon.py or python3 rpi_tempmon.py:
Program is a python 3 package. Run in a terminal
by typing rpi_tempmon.py or python3 rpi_tempmon.py:

rpi_tempmon.py -[options][arguments]

Expand All @@ -62,7 +56,7 @@ Options list *(Note: Options are standalone, not designed to be combined)*:
| -l | Creates and/or appends to log file at output folder |
| -L | Creates a sub-folder at output folder with date/time stamp and puts a log file in it |
| -m | Sends the log file to an email account |
| -g | graph mode, Generate a menu where 11 types of graphs can be selected |
| -g | graph mode, Generate a menu where 12 types of graphs can be selected |
| -a | parse log file and produces a data report in terminal |
| -n | send notifications to desktop, Number argument to define behaviour |
| -s | CSV mode , parses log.txt and converts it to log.csv, CSV file |
Expand All @@ -77,12 +71,12 @@ rpi_tempmon files needed are listed below:
| rpi_tempmon.py | The main python script |
| RpiTempmonWork.py| python module containing various utility functions used by main |
| RpiTempmonGraph.py | python module dealing with graph output by matplotlib |
| $HOME/.config/rpi_tempmon/rpi_tempmon.cfg | config file, user made, NOT installed |
| $HOME/.config/rpi_tempmon/rpi_tempmon.cfg | config file |
| README.md | help file |


Config file: The user **MUST** create a config file at path in table above.
The config file is NOT installed by setup. A dummy config file is available in documentation folder at repositry
Config file: The config file with dummy values is created if missing.
A dummy config file is available in documentation folder at repository
, used for -m mail option, GPIO/LED feature and the alarm function.

The setting "RPI_AuthUser" the is email address
Expand Down Expand Up @@ -220,7 +214,7 @@ Data is sent to terminal screen.
The GPIO pin in config file will be turned on
and Data in red is displayed in screen for an Alarm state, if setup in config file.

![ScreenShot cont mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/main_screen.jpg)
![ScreenShot cont mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/main_screen.jpg)

**3. & 4. Log modes**

Expand Down Expand Up @@ -277,9 +271,10 @@ This file allows for user to set an email address without access to msmtp
config file which should be set up just for root account.
2. Install msmtp and dependencies as per installation section
3. Configure msmtp configuration file [MSMTP help](https://wiki.archlinux.org/index.php/Msmtp)
A working example msmtprc config file for gmail is in documentation folder, see link for details.
A working example msmtprc config file for gmail is in documentation folder, "example_msmtprc".
4. Optional, It is also possible you may need to configure your email account to accept msmtp mails
this was the case for gmail and ssmtp. See here [Login credentials not working with Gmail SMTP](https://stackoverflow.com/questions/16512592/login-credentials-not-working-with-gmail-smtp#27515883)
"Less secure app access" in google mail to On.
**6. graph mode**
Expand All @@ -289,14 +284,14 @@ The logfile.txt created by logfile mode 3 is used for data for graph 1-8.
graphs 1-4 use time-date stamp as yaxis value
graphs 5-8 use Unix Epoch stamp as yaxis value, this is better for irregular data
points across multiple dates.
The graphs 9-11 are live plots sampled every two seconds for 150 points,
The graphs 9-12 are live plots sampled every two seconds for 150 points,
so five minutes of live data.
![graph menu](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphoptionsmenu.jpg)
![graph menu](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphoptionsmenu.jpg)
Sample graph screenshot, screenshots of all others are in [screenshot folder of repo](screenshots/).
![graph mode 6](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphmode2.jpg)
![graph mode 6](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphmode2.jpg)
**7. CSV(comma-separated values) convert**
Expand Down Expand Up @@ -330,7 +325,7 @@ depending on system. for example
* -n 2 = argument 2 = If run always display CPU temperature , no warning.
* -n 3 = argument 3 = If run only display if CPU temperature exceeds limit
![notify mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/nyalarm.jpg)
![notify mode](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/nyalarm.jpg)
**10. Stress test mode**
Expand All @@ -349,6 +344,6 @@ called stresslog.csv . sample output = test run num, CPU temp, CPU usage.
At the end of test, there is an option to display results in a graph.
![stress test results](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/graphstresstest.jpg)
![stress test results](https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/Documentation/screenshots/graphstresstest.jpg)
Stress data carried out by rpi_tempmon for a RPi 3 can be found in repo [here](stresstestdata/stresstest.md)
Stress data carried out by rpi_tempmon for a RPi 3 can be found in repo [here](Documentation/stresstestdata/stresstest.md)
79 changes: 72 additions & 7 deletions rpiTempMod/RpiTempmonGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
mpl.use('tkagg')
import matplotlib.pyplot as plt
import matplotlib.dates as md

# My modules
from . import RpiTempmonWork as Work



class MatplotGraph(object):
"""
class with 6 methods to display graphs with matplotlib
Expand Down Expand Up @@ -95,11 +95,12 @@ def display_menu(self):
menu.append("CPU usage versus live Time")
menu.append("GPU Temperature versus live Time")
menu.append("RAM usage versus live Time")
menu.append("CPU GPU & RAM usage versus live time")
menu.append("Exit")
try:
while True:
print("\n")
Work.msg_func("blue", "Graph Menu Options")
Work.msg_func("blue", "RPI_tempmon :: Graph Menu Options")
Work.msg_func("line", "")
for number, string in enumerate(menu):
print(number+1, string)
Expand All @@ -117,6 +118,9 @@ def display_menu(self):
self.graph_live_data("RAM")
break
elif self.selection == '12':
self.graph_all_live_data()
break
elif self.selection == '13':
quit()
else:
Work.msg_func("red", "\n ** Warning : Unknown Option Selected! **")
Expand Down Expand Up @@ -169,8 +173,72 @@ def draw_graph(self, timelist, yaxis_list1,
plt.grid(True)
plt.show()

def graph_all_live_data(self):
""" Draw a live graph of pi GPU/CPU/RAM """
print("Drawing graph of all data usage versus live time")
print("Press CTRL+c to quit.")
try:
time_cpu_axis = []
time_ram_axis = []
time_gpu_axis = []
yaxis_cpu_data = 0
yaxis_ram_data = 0
yaxis_gpu_data = 0
plt.ion()
labels = ()

# pre-load dummy data
for i in range(0, 150):
time_cpu_axis.append(.5)
time_ram_axis.append(.5)
time_gpu_axis.append(.5)

while True:
# get data
yaxis_cpu_data = Work.get_cpu_use()
yaxis_cpu_data = float(yaxis_cpu_data)
yaxis_ram_data = Work.get_ram_info()
yaxis_ram_data = float(yaxis_ram_data)
ostemp = os.popen('vcgencmd measure_temp').readline()
yaxis_gpu_data = (ostemp.replace("temp=", "").replace("'C\n", ""))
yaxis_gpu_data = float(yaxis_gpu_data)

# update the graph
labels = "GPU Temp + CPU & RAM usage", "CPU-% RAM-% GPU-'C", "CPU-%", "RAM-%", "GPU-'C"
time_cpu_axis.append(yaxis_cpu_data)
time_ram_axis.append(yaxis_ram_data)
time_gpu_axis.append(yaxis_gpu_data)
time_cpu_axis.pop(0)
time_ram_axis.pop(0)
time_gpu_axis.pop(0)
self.plot_all_now(time_cpu_axis, time_ram_axis, time_gpu_axis, labels)
plt.pause(2)

except Exception as error:
print(error)
Work.msg_func("bold", "Real-time matplotlib plot shutdown")
quit()

def plot_all_now(self, time_cpu_axis, time_ram_axis, time_gpu_axis, labels):
""" Called from method graph_all_live_data to draw graph"""

title, y_label, plot_cpu_label, plot_ram_label, plot_gpu_label = labels
plt.clf()

plt.ylim([1, 100])
plt.ylabel(y_label, color='red')

plt.title(self.name + title, color='green')
plt.grid(True)
plt.xlabel("Time (last 300 seconds)", color='red')
plt.plot(time_cpu_axis, color='blue', marker='', label=plot_cpu_label)
plt.plot(time_ram_axis, color='red', marker='', label=plot_ram_label)
plt.plot(time_gpu_axis, color='green', marker='', label=plot_gpu_label)
plt.legend(loc='upper right', fancybox=True, shadow=True)
plt.show()

def graph_live_data(self, choice):
""" Draw a live graph of pi GPU """
""" Draw a live graph of pi GPU or CPU or RAM """
try:
time_axis = []
yaxis_data = 0
Expand All @@ -181,9 +249,6 @@ def graph_live_data(self, choice):
time_axis.append(.5)

while True:

time_axis.append(yaxis_data)
time_axis.pop(0)
if choice == "GPU":
ostemp = os.popen('vcgencmd measure_temp').readline()
yaxis_data = (ostemp.replace("temp=", "").replace("'C\n", ""))
Expand All @@ -199,7 +264,7 @@ def graph_live_data(self, choice):
time_axis.append(yaxis_data)
time_axis.pop(0)
self.plot_now(time_axis, labels)
else: # RAM
elif choice == 'RAM':
yaxis_data = Work.get_ram_info()
yaxis_data = float(yaxis_data)
labels = (" RAM live usage", "Usage (%)", "RAM")
Expand Down
9 changes: 4 additions & 5 deletions rpiTempMod/RpiTempmonWork.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_cpu_tempfunc():
def get_gpu_tempfunc():
""" Return GPU temperature as a character string"""
res = os.popen('/opt/vc/bin/vcgencmd measure_temp').readline()
return res.replace("temp=", "")
return (res.replace("\n", "").replace("temp=", ""))


def get_cpu_use():
Expand Down Expand Up @@ -165,7 +165,7 @@ def logging_func(choice, mail_alert, cpu_limit, mailuser, destlog, alarm_mode):
with open("log.txt", "a+") as mylogfile:
mylogfile.write("TS = " + str(today) + '\n')
mylogfile.write("EP = " + str(round(time.time(), 0)) + '\n')
mylogfile.write("GPU temperature = " + get_gpu_tempfunc())
mylogfile.write("GPU temperature = " + get_gpu_tempfunc() + '\n')
mylogfile.write("CPU temperature = " + get_cpu_tempfunc() + '\n')
mylogfile.write("Cpu usage = " + get_cpu_use() + '\n')
mylogfile.write("RAM usage = " + get_ram_info() + '\n')
Expand Down Expand Up @@ -193,7 +193,7 @@ def mail_func(sub, mailu, destlog):
os.chdir(destlog)
if os.path.exists("log.txt"):
# Command to send mail from bash
os.system('echo "Datafile log.txt attached" > body.txt')
os.system('echo "Datafile log.txt attached" > body.txt')
os.system('mpack -s "raspberry-PI-temperature {}" -d body.txt log.txt {}'.format(sub, mailu))
else:
msg_func("red", "Error: log file is not there {}".format(destlog))
Expand Down Expand Up @@ -337,7 +337,7 @@ def msg_func(myprocess, mytext):
OUTPUT yesno prompt return 1 or 0"""

# colours for printf
blue = '\033[94m'
blue = '\033[96m'
green = '\033[92m'
yellow = '\033[93m'
red = '\033[91m'
Expand Down Expand Up @@ -385,7 +385,6 @@ def importtest(text):
"""import print test statement"""
# print(text)
pass

# ===================== MAIN ===============================


Expand Down
Loading

0 comments on commit 2982a57

Please sign in to comment.