Skip to content

System monitoring program for Raspberry pi single board computers written in Python 3.

License

Notifications You must be signed in to change notification settings

gavinlyonsrepo/raspberrypi_tempmon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Donate

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 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. It is run in terminal and uses matplotlib plots for graph modes.

Table of contents

Installation

Latest version 3.0 (07-2024)

PyPi & pip , pipx

The program is present in python package index, Pypi. Install using pip or pipx to the location or environment of your choice. Package name = rpi-tempmon.py

Manually install from github

The package is also archived on github and can be manually download and installed via python and setup.py

curl -sL https://github.com/gavinlyonsrepo/raspberrypi_tempmon/archive/3.0.tar.gz | tar xz
cd raspberrypi_tempmon-3.0
python3 setup.py build 
python3 setup.py install --user

Usage

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]

Options list (Note: Options are stand alone, not designed to be combined):

Option Description
-h Print help information and exit
-v Print version information and exit
-c Enters continuous mode, optional number of seconds as a argument eg (-c 5)
-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 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
-ST Stress test CPU and measures temperature output to graph and csv file , optional number of test runs as a argument eg (-ST 5)

Files and setup

rpi_tempmon files needed are listed below:

File Path Description
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
README.md help file

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 destination of data from -m option.

Mail_Alert(one: mail alert enabled , zero: off)

The other settings are ALARM_MODE which should be set to one or zero(one: alarm on, zero: off)

CPU_UPPERLIMIT is the temperature limit of CPU in Centigrade, should be a positive integer. If alarm mode is on when CPU temperature goes above this limit, the alarm function will activate.

LED_MODE which should be set to one or zero(one: LED mode on, zero: off) if on an GPIO pin will switch on during an alarm state in continuous and normal mode. The RPI GPIO pin as defined by GPIO_LED number. You can connect an LED or another electronic component to this pin.

Make sure to include the [MAIN] header and all settings just as below or copy from the example file.

Settings:

[MAIN]

RPI_AuthUser=examplemail@gmail.com

MAIL_ALERT = 1

ALARM_MODE = 1

CPU_UPPERLIMIT = 60

LED_MODE = 0

GPIO_LED = 26

Screenshots, example config/log files are also available in documentation.

Output

The output folder for log files is currently fixed at:

$HOME/.cache/rpi_tempmon/

Dependencies

  1. simple MSMTP - Version: 1.6.6-1- Program which delivers email from a computer to a mailhost. MSMTP help Optional, ONLY used by mail functions. light SMTP client with support for server profiles client that can be used to send mails . (SMTP server), needed only for -m mail option. Also needs to install another few small dependencies (mpack etc) in order to send attachment. See mail mode in features for setup.
$ sudo apt install msmtp msmtp-mta mailutils mpack
  1. sysbench - Version 0.4.12-1.1 - benchmarking tool. sysbench Optional, ONLY used by stress test option -ST.
$ sudo apt install sysbench.
  1. libnotify-bin - Version 0.7.6-2 - sends desktop notifications to a notification daemon. libnotify Optional, This is ONLY needed if using the -n option which uses the notify-send command.
$ sudo apt install libnotify-bin
  1. matplotlib - Version: 2.2.2 - Python plotting package. matplotlib help The graph modules requires python module matplotlib to draw graphs, This is for -g and -ST options. Installed by rpi_tempmon setup.py during installation in theory.

  2. psutil - Version (2.1.1) - Library for retrieving info on PC. psutil Used to retrieve some CPU and memory information. Installed by setup.py during installation.

  3. gpiozero - version(2.0) - This package controls the GPIO on a Raspberry Pi. gpiozero GPIO Zero is installed by default in the Raspberry Pi OS desktop image, note before rpi_tempmon version 3.0 , rpi_tempmon used rpi.gpio.

Features

For a raspberry pi the official operating temperature limit is 85°C, and as a result the Raspberry Pi should start to thermally throttle performance around 82°C. The GPU and CPU are closely correlated to within a degree usually.

The program calculates the ARM CPU and GPU temperature of a Raspberry Pi and outputs them in Centigrade together with datetime stamp. Also shows CPU, RAM memory usage .

The program has ten features

  1. Normal mode - output to screen with optional GPIO output, prompt for update.
  2. Continuous mode - output to screen with optional GPIO output, updates based on timer.
  3. Logfile mode - output to single logfile(also mail mode if mail alert mode on and triggered).
  4. Logfolder mode - output to multiple logfile in separate folders.
  5. Mail mode - output to email.
  6. Graph mode - Displays a graph of logfile created in mode 3
  7. CSV mode - parses log.txt and converts it to log.csv for external use
  8. Data mode - parses log file and produces a small report.
  9. Notify mode - send notifications to desktop, Number argument to define behaviour
  10. Stress test mode - Stresses the CPU with math and records results in csv file and graph.

1. normal mode

Normal mode is run by running program with no command line arguments. In normal mode output, Data is sent to the terminal with prompt to repeat or quit. 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.

2. Continuous mode

Same as normal mode except in continuous mode. The program enters a delay between scan. This delay is set by positive integer argument placed after -c. For example "-c 30" will wait 30 seconds between scans. 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

3. & 4. Log modes

In logfile mode the data is appended into a file log.txt at output folder. With optional mail setup if alarm mode setup. For mode 3 an email is sent using mode 5 function, but with warning in title.

Sample output of logfile:

TS = 18-04-22 14:19:42
EP = 1524403183.0
GPU temperature = 48.3'C
CPU temperature = 48.3
Cpu usage = 40.4
RAM usage = 45.0
Swap usage = 98.6
Raspberry pi temperature monitor: raspberrypi

The log file is appended with "Warning:" text message if alarm state entered.

In logfolder mode in the output folder, a new sub-folder is created each time it is ran and a new log-file put in here. The sub-folder has following syntax 1250-02Jul17_RPIT HHMM-DDMMMYY_XXXX. This folder mode does not work with mail or graph mode at present.

Logging modes are designed to be used with UNIX automation like crontab. For example this crontab entry will run logfile mode once an hour, Note: The path to executable may differ on each users system.

0 * * * *  /usr/local/bin/rpi_tempmon.py -l >/dev/null 2>&1

5. Mail mode

In mail mode an email is sent using msmtp. The mail contains the data from logfile mode only, it will NOT work with sub-folders from logfolder mode.

msmtp is used rather than than python inbuilt smtplib module as this program was originally a bash program and this a legacy of that, also allows access to msmtp config file for greater portability and security. The program originally used ssmtp but this is now obsolete in latest raspbian software.

In order to get mail mode working you must complete 3-4 steps.

  1. Set settings in rpi_tempmon config file, see Files and setup section. 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 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. In 2024 in order to get gmail working with ssmtp mail ,you must first set up 2 step verification on your google account then request a App password for an App from 'apppasswords' section. Google will then generate a 16 character API password, like 'aaaa bbbb cccc dddd' , use this in the password field of your msmtp configuration file.

6. graph mode

In graph mode, the program using matplotlib (plotting library) creates a plot of various data versus time. 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-12 are live plots sampled every two seconds for 150 points, so five minutes of live data.

graph menu

Sample graph screenshot, screenshots of all others are in screenshot folder of repo.

graph mode 6

graph mode 12

7. CSV(comma-separated values) convert

New in Version 2.0. Run with -s on the CLI. Parses log.txt and creates log.csv. This csv file can be then used by user in another app. A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. This file can then be loaded into libreoffice calc. for further processing, for example.

sample output = time-data, CPU temp, GPU temp, CPU usage , RAM usage , swap usage

18-04-04 09:46:51,61.5,60.7,25.8,33.9,11.6

8. data mode

Parses log file created by logfile mode 3 and produces a data report on console.

9. notify mode

Send notifications to desktop, Numbered argument to define behaviour After installing notify-send, Additional packages or steps may be required to get notify-send working, depending on system. for example
Jessie

  • -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

10. Stress test mode

This mode uses the sysbench benchmarking tool. The test request consists in calculation of prime numbers up to a value of 20000. All calculations are performed using 64-bit integers. 4 worker threads are created. The number of test runs is passed on command line as integer max 50 min 2. CPU temperature and freq are recorded for each test run and are outputed to a csv file, called stresslog.csv . sample output = test run num, CPU temp, CPU usage.

1,56.9,27.1
2,61.3,99.7

At the end of test, there is an option to display results in a graph. Stress data carried out by rpi_tempmon can be found in repo here