LATEST RELEASE: FPP 8.4 - Download from here - https://github.com/FalconChristmas/fpp/releases/tag/8.4
Host Name: Lighting1
CPU Temperature: 49C
CPU Usage: 3%
Disk Usage: 23%
Memory Usage: 47%
Power OK.
Fuse Failure!
Case Temperature 44.9C
Battery Voltage 11.43 Volts
Fan On
Cooling Off
Host Name: Lighting1
CPU Temperature: 49C
CPU Usage: 3%
Disk Usage: 23%
Memory Usage: 47%
Power OK.
Fuse Status: Unknown
Case Temperature 44.9C
Battery Voltage 11.43 Volts
Fan On
Cooling Off
#! /usr/bin/python3
# pi_monitor.py
# Scan / print the health of a Raspberry Pi and
# report any issues to the phone or email list
import psutil, subprocess, email, smtplib, ssl, SendMessage
from time import sleep
from sys import argv, exit
from os import uname
from gpiozero import CPUTemperature
import RPi.GPIO as GPIO
Degrees = "\u00B0C" # Degree symbol UTF-16
Degrees = "C"
HighCPUUsage = 90 # High CPU usage in %
HighCPUTemp = 65 # High CPU temperature in Celsius
CritCPUTemp = 80 # Critical CPU temperature in Celsius
HighMemUsage = 70 # High Memory utilization
HighDiskUsage = 60 # High Disk utilization
Uname = uname().nodename
phones = [["##########", "Consumer Cellular", True],["##########", "Sprint", True], ["#######", "##########", False]]
# runDef = [ Script Name, Delay in seconds, Send to stdout, Send email / sms ]
runDef = [["start", 30, False, True], ["check", 0, False, False], ["print", 0, True, False], ["flash", 0, True, True], ["mail", 0, False, True]]
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
GPIO.setup(17,GPIO.IN)
Fuse = GPIO.input(4)
Power = GPIO.input(17)
if len(argv) > 0: # Should always be non-zero if called from CLI
envString = argv[0] # Contains the name by which the script was called
for runVal in runDef:
scriptName, scriptDelay, scriptPrint, scriptMail, *rest = runVal
if envString.find(scriptName) > 0: # Check if script called with this runVal value
sleep(scriptDelay)
break
else:
print("WTF?") # Not called from CLI
exit(1)
def pi_status(): # Main routine: always called by script
# Gather information about system
result1 = getTemperature()
result2 = getCPU()
result3 = getDiskUsage()
result4 = getMemUsage()
if scriptMail: # Called with Mail Send request: send email
if scriptName == "start":
sendText = "Raspberry Pi Startup notification\r\n"
else:
sendText = "Raspberry Pi Monitor Mail\r\n"
sendText = sendText + "Host Name: " + Uname + "\r\n"
sendText = sendText + result1+ "\r\n"
sendText = sendText + result2+ "\r\n"
sendText = sendText + result3+ "\r\n"
sendText = sendText + result4+ "\r"
sendMessage(sendText)
if scriptPrint: # Called with display request: send to stdout
print("Host Name: " + Uname)
print(result1)
print(result2)
print(result3)
print(result4)
def getTemperature():
cpuTemp = int(CPUTemperature().temperature)
Ctemp = "CPU Temperature: " + str(cpuTemp) + Degrees
if cpuTemp > CritCPUTemp:
sendText = "CRITICAL ALARM FROM HOST " + Uname + "!\r\nALERT: Critical temperature " + str(Ctemp) + ".\r\nShutting system down...\r"
sendMessage(sendText)
sleep(10)
subprocess.run(["shutdown", "-h", "0"])
elif cpuTemp > HighCPUTemp:
sendText = "Alarm From Host " + Uname + "!\r\nWarning: High temperature " + str(Ctemp) + ".\r"
sendMessage(sendText)
return Ctemp
def getCPU():
cpuPercent = int(psutil.cpu_percent(1))
Cusage = "CPU Usage: " + str(cpuPercent) + "%"
if cpuPercent > HighCPUUsage:
# Sending alert on high cpu usage."
sendText = "Alert From HOST " + Uname + "!\r\nWarning: High CPU Utilization " + str(cpuPercent) + "%\r"
sendMessage(sendText)
return Cusage
def getDiskUsage():
for dp in psutil.disk_partitions():
diskUsagePercent = int(psutil.disk_usage(dp.mountpoint).percent)
diskPercent = "Disk Usage: " + str(diskUsagePercent) + "%"
if (diskUsagePercent > HighDiskUsage):
sendText = "Warning From Host " + Uname + "!\r\nWarning: High Disk Usage " + str(diskUsagePercent) + "%.\r"
sendMessage(sendText)
return diskPercent
def getMemUsage():
memUsagePercent = int(psutil.virtual_memory().percent)
if (memUsagePercent > HighMemUsage):
sendText = "Alert From Host " + Uname + "!\r\nWarning: High Memory Usage " + str(memUsagePercent) + "%.\r"
sendMessage(alertMsg)
memUse = "Memory Usage: " +str(memUsagePercent) + "%"
return memUse
def getPower():
if not Fuse:
if not Power:
Text = "Main power failure. Shutdown will occur shortly."
else:
Text = "Fuse failure."
SendMessage(Text)
pi_status()
No Fuses and No Expansion Port
by munu
Today at 07:12:42 PM |
F48 v1 & F16v5
by munu
Today at 07:00:58 PM |
Swapped PiCap V1 with V2 - Pixels will not light in test
by CaptainMurdoch
Today at 05:29:18 PM |
Does the Falcon PiCap v2 support Renard Output?
by CaptainMurdoch
Today at 05:27:42 PM |
FPP 8.4 released!
by lrhorer
Today at 11:30:42 AM |
K2-Pi-Servo
by breese
January 17, 2025, 01:47:06 PM |
Big button url question
by darylc
January 14, 2025, 05:54:32 PM |
Display TEXT to LED Panels form REST API
by CaptainMurdoch
January 14, 2025, 11:55:25 AM |
Differential Board: PSU & Enclosure
by jnealand
January 14, 2025, 07:42:55 AM |
wine from matrix with octoscroller control
by Poporacer
January 12, 2025, 10:40:05 AM |
Page created in 0.048 seconds with 33 queries.