Create get_throttled.py

This commit is contained in:
aiminick 2021-04-03 02:14:03 +08:00 committed by GitHub
parent ee47d0577f
commit 352ce3cc27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

32
scripts/get_throttled.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python
import subprocess
GET_THROTTLED_CMD = 'vcgencmd get_throttled'
MESSAGES = {
0: 'Under-voltage!',
1: 'ARM frequency capped!',
2: 'Currently throttled!',
3: 'Soft temperature limit active',
16: 'Under-voltage has occurred since last reboot.',
17: 'Throttling has occurred since last reboot.',
18: 'ARM frequency capped has occurred since last reboot.',
19: 'Soft temperature limit has occurred'
}
print("Checking for throttling issues since last reboot...")
throttled_output = subprocess.check_output(GET_THROTTLED_CMD, shell=True)
throttled_binary = bin(int(throttled_output.split('=')[1], 0))
warnings = 0
for position, message in MESSAGES.iteritems():
# Check for the binary digits to be "on" for each warning message
if len(throttled_binary) > position and throttled_binary[0 - position - 1] == '1':
print(message)
warnings += 1
if warnings == 0:
print("Looking good!")
else:
print("Houston, we may have a problem!")