Add detection for undervoltage and throttling on Raspis

This commit is contained in:
Taylor Helsper 2020-09-09 22:10:14 -05:00
parent 62f1e28cfc
commit 5437bc0170
11 changed files with 203 additions and 190 deletions

View File

@ -0,0 +1,20 @@
# myNode background service
# /etc/systemd/system/background.service
[Unit]
Description=myNode Background Checks
Wants=mynode.service
After=mynode.service
[Service]
Type=simple
KillMode=control-group
TimeoutSec=30
Restart=always
RestartSec=30
ExecStart=/usr/bin/mynode_background.sh
User=root
Group=root
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
set -x
source /usr/share/mynode/mynode_config.sh
source /usr/share/mynode/mynode_app_versions.sh
COUNTER=0
while true; do
# Check for under voltage, throttling, etc... every 2 min on Raspis
if [ $(( $COUNTER % 2 )) -eq 0 ]; then
if [ $IS_RASPI -eq 1 ]; then
STATUS=$(vcgencmd get_throttled)
STATUS=${STATUS#*=}
echo $STATUS > /tmp/get_throttled_data
fi
fi
# Increment counter and sleep 1 min
COUNTER=$((COUNTER+1))
sleep 1m
done

View File

@ -630,6 +630,7 @@ apt-get clean
# Enable any new/required services
systemctl enable check_in
systemctl enable background
systemctl enable docker
systemctl enable bitcoind
systemctl enable seed_bitcoin_peers

View File

@ -79,6 +79,32 @@ def check_and_mark_reboot_action(tmp_marker):
raise RequestRedirect("/")
os.system("touch /tmp/{}".format(tmp_marker))
def reload_throttled_data():
global cached_data
if os.path.isfile("/tmp/get_throttled_data"):
cached_data["get_throttled_data"] = get_file_contents("/tmp/get_throttled_data")
def get_throttled_data():
global cached_data
if "get_throttled_data" in cached_data:
data = cached_data["get_throttled_data"]
hex_data = int(data, 16)
r = {}
r["RAW_DATA"] = data
r["UNDERVOLTED"] = 1 if hex_data & 0x1 else 0
r["CAPPED"] = 1 if hex_data & 0x2 else 0
r["THROTTLED"] = 1 if hex_data & 0x4 else 0
r["SOFT_TEMPLIMIT"] = 1 if hex_data & 0x8 else 0
r["HAS_UNDERVOLTED"] = 1 if hex_data & 0x10000 else 0
r["HAS_CAPPED"] = 1 if hex_data & 0x20000 else 0
r["HAS_THROTTLED"] = 1 if hex_data & 0x40000 else 0
r["HAS_SOFT_TEMPLIMIT"] = 1 if hex_data & 0x80000 else 0
return r
else:
r = {}
r["RAW_DATA"] = "MISSING"
return r
#==================================
# Manage Versions and Upgrades
#==================================

View File

@ -1,5 +1,5 @@
from config import *
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash, current_app
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from bitcoind import is_bitcoind_synced
from bitcoin_info import using_bitcoin_custom_config
@ -111,6 +111,7 @@ def page_settings():
"uptime": uptime,
"date": date,
"local_ip": local_ip,
"throttled_data": get_throttled_data(),
"drive_usage": get_drive_usage(),
"cpu_usage": get_cpu_usage(),
"ram_usage": get_ram_usage(),
@ -269,6 +270,7 @@ def page_status():
"uptime": uptime,
"date": date,
"local_ip": local_ip,
"throttled_data": get_throttled_data(),
"drive_usage": get_drive_usage(),
"cpu_usage": get_cpu_usage(),
"ram_usage": get_ram_usage(),

View File

@ -0,0 +1,66 @@
<div class="settings_block_subheader">
Info
</div>
<table border="0">
<tr>
<td>Serial Number</td>
<td style="padding-left: 20px;">{{serial_number}}</td>
</tr>
<tr>
<td>Product Key</td>
<td style="padding-left: 20px;">
{% if product_key_skipped %}
{{product_key}}
&nbsp;<a href="/product-key" class="ui-button ui-widget ui-corner-all settings_button_small">Enter Product Key</a>
{% else %}
<button id="show_product_key" class="ui-button ui-widget ui-corner-all settings_button_small">Show</button>
<span id="product_key" style="display: none;">{{product_key}}</span>
&nbsp;<a href="/product-key" class="ui-button ui-widget ui-corner-all settings_button_small">Change</a>
{% endif %}
</td>
</tr>
<tr>
<td>Device Type</td>
<td style="padding-left: 20px;">{{device_type}}</td>
</tr>
<tr>
<td>Device RAM</td>
<td style="padding-left: 20px;">{{device_ram}} GB</td>
</tr>
<tr>
<td>Local IP</td>
<td style="padding-left: 20px;">{{local_ip}}</td>
</tr>
{% if throttled_data['RAW_DATA'] != "0x0" and throttled_data['RAW_DATA'] != "MISSING" %}
{% if throttled_data['UNDERVOLTED'] or throttled_data['CAPPED'] or throttled_data['THROTTLED'] or throttled_data['SOFT_TEMPLIMIT'] %}
<tr>
<td>Active Throttling Data</td>
<td style="padding-left: 20px; color: red; font-size: 10px">
{% if throttled_data['UNDERVOLTED'] %}Undervolted<br/>{% endif %}
{% if throttled_data['CAPPED'] %}Capped CPU<br/>{% endif %}
{% if throttled_data['THROTTLED'] %}Throttled CPU<br/>{% endif %}
{% if throttled_data['SOFT_TEMPLIMIT'] %}Hit Soft Temp Limit<br/>{% endif %}
</td>
</tr>
{% endif %}
{% if throttled_data['HAS_UNDERVOLTED'] or throttled_data['HAS_CAPPED'] or throttled_data['HAS_THROTTLED'] or throttled_data['HAS_SOFT_TEMPLIMIT'] %}
<tr>
<td>Historic Throttling Data<br/><span style="font-size: 10px;">*Occurred since last reboot</span></td>
<td style="padding-left: 20px; color: red; font-size: 10px;">
{% if throttled_data['HAS_UNDERVOLTED'] %}Undervolted<br/>{% endif %}
{% if throttled_data['HAS_CAPPED'] %}Capped CPU<br/>{% endif %}
{% if throttled_data['HAS_THROTTLED'] %}Throttled CPU<br/>{% endif %}
{% if throttled_data['HAS_SOFT_TEMPLIMIT'] %}Hit Soft Temp Limit<br/>{% endif %}
</td>
</tr>
{% endif %}
{% endif %}
{% if has_checkin_error %}
<tr>
<td>Server</td>
<td style="padding-left: 20px; color: red;"><b>Error contacting mynodebtc.com via Tor!</b><br/>You may have issues checking for new versions or saving product keys.</td>
</tr>
{% endif %}
</table>
<div class="divider"></div>

View File

@ -0,0 +1,53 @@
<div class="settings_block_subheader">Status</div>
<table border="0">
<tr>
<td>Details</td>
<td style="padding-left: 20px;">
{% if is_netdata_enabled %}
{% if is_bitcoin_synced %}
{% if not is_installing_docker_images %}
<a id="netdata" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Netdata</a>
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Docker</a>
{% endif %}
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Bitcoin</a>
{% endif %}
{% endif %}
<a id="glances" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Glances</a>
</td>
</tr>
<tr>
<td>Manage</td>
<td style="padding-left: 20px;">
<a id="linux_terminal" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Linux Terminal</a>
</td>
</tr>
<tr>
<td>Disk Usage</td>
<td style="padding-left: 20px;">{{drive_usage}}</td>
</tr>
<tr>
<td>CPU</td>
<td style="padding-left: 20px;">{{cpu_usage}}</td>
</tr>
<tr>
<td>RAM</td>
<td style="padding-left: 20px;">{{ram_usage}}</td>
</tr>
{% if device_temp != '...' %}
<tr>
<td>Temperature</td>
<td style="padding-left: 20px;">{{device_temp}} &deg;C</td>
</tr>
{% endif %}
<tr>
<td>Uptime</td>
<td style="padding-left: 20px;">{{uptime}}</td>
</tr>
<tr>
<td>Date</td>
<td style="padding-left: 20px;">{{date}}</td>
</tr>
</table>
<div class="divider"></div>

View File

@ -446,103 +446,9 @@
<div class="divider"></div>
{% include 'includes/info_table.html' %}
<div class="settings_block_subheader">
Info
</div>
<table border="0">
<tr>
<td>Serial Number</td>
<td style="padding-left: 20px;">{{serial_number}}</td>
</tr>
<tr>
<td>Product Key</td>
<td style="padding-left: 20px;">
{% if product_key_skipped %}
{{product_key}}
&nbsp;<a href="/product-key" class="ui-button ui-widget ui-corner-all settings_button_small">Enter Product Key</a>
{% else %}
<button id="show_product_key" class="ui-button ui-widget ui-corner-all settings_button_small">Show</button>
<span id="product_key" style="display: none;">{{product_key}}</span>
&nbsp;<a href="/product-key" class="ui-button ui-widget ui-corner-all settings_button_small">Change</a>
{% endif %}
</td>
</tr>
<tr>
<td>Device Type</td>
<td style="padding-left: 20px;">{{device_type}}</td>
</tr>
<tr>
<td>Device RAM</td>
<td style="padding-left: 20px;">{{device_ram}} GB</td>
</tr>
<tr>
<td>Local IP</td>
<td style="padding-left: 20px;">{{local_ip}}</td>
</tr>
{% if has_checkin_error %}
<tr>
<td>Server</td>
<td style="padding-left: 20px; color: red;"><b>Error contacting mynodebtc.com via Tor!</b><br/>You may have issues checking for new versions or saving product keys.</td>
</tr>
{% endif %}
</table>
<div class="divider"></div>
<div class="settings_block_subheader">Status</div>
<table border="0">
<tr>
<td>Details</td>
<td style="padding-left: 20px;">
{% if is_netdata_enabled %}
{% if is_bitcoin_synced %}
{% if not is_installing_docker_images %}
<a id="netdata" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Netdata</a>
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Docker</a>
{% endif %}
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Bitcoin</a>
{% endif %}
{% endif %}
<a id="glances" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Glances</a>
</td>
</tr>
<tr>
<td>Manage</td>
<td style="padding-left: 20px;">
<a id="linux_terminal" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Linux Terminal</a>
</td>
</tr>
<tr>
<td>Disk Usage</td>
<td style="padding-left: 20px;">{{drive_usage}}</td>
</tr>
<tr>
<td>CPU</td>
<td style="padding-left: 20px;">{{cpu_usage}}</td>
</tr>
<tr>
<td>RAM</td>
<td style="padding-left: 20px;">{{ram_usage}}</td>
</tr>
{% if device_temp != '...' %}
<tr>
<td>Temperature</td>
<td style="padding-left: 20px;">{{device_temp}} &deg;C</td>
</tr>
{% endif %}
<tr>
<td>Uptime</td>
<td style="padding-left: 20px;">{{uptime}}</td>
</tr>
<tr>
<td>Date</td>
<td style="padding-left: 20px;">{{date}}</td>
</tr>
</table>
<div class="divider"></div>
{% include 'includes/status_table.html' %}
<div class="settings_block_subheader">Change Log</div>
<button id="show_mynode_changelog" class="ui-button ui-widget ui-corner-all settings_button">View Change Log</button>

View File

@ -175,100 +175,9 @@
</table>
<div class="divider"></div>
{% include 'includes/info_table.html' %}
<div class="settings_block_subheader">Info</div>
<table border="0">
<tr>
<td>Serial Number</td>
<td style="padding-left: 20px;">{{serial_number}}</td>
</tr>
<tr>
<td>Product Key</td>
<td style="padding-left: 20px;">
{% if product_key_skipped %}
{{product_key}}
{% else %}
<button id="show_product_key" class="ui-button ui-widget ui-corner-all settings_button_small">Show</button>
<span id="product_key" style="display: none;">{{product_key}}</span>
{% endif %}
</td>
</tr>
<tr>
<td>Device Type</td>
<td style="padding-left: 20px;">{{device_type}}</td>
</tr>
<tr>
<td>Device RAM</td>
<td style="padding-left: 20px;">{{device_ram}} GB</td>
</tr>
<tr>
<td>Local IP</td>
<td style="padding-left: 20px;">{{local_ip}}</td>
</tr>
{% if has_checkin_error %}
<tr>
<td>Server</td>
<td style="padding-left: 20px; color: red;"><b>Error contacting mynodebtc.com via Tor!</b><br/>You may have issues checking for new versions or saving product keys.</td>
</tr>
{% endif %}
</table>
<div class="divider"></div>
<div class="settings_block_subheader">Status</div>
<table border="0">
<tr>
<td>Details</td>
<td style="padding-left: 20px;">
{% if is_netdata_enabled %}
{% if is_bitcoin_synced %}
{% if not is_installing_docker_images %}
<a id="netdata" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Netdata</a>
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Docker</a>
{% endif %}
{% else %}
<a class="ui-button ui-widget ui-corner-all settings_button_small" href="#" disabled>Netdata - Waiting on Bitcoin</a>
{% endif %}
{% endif %}
<a id="glances" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Open Glances</a>
</td>
</tr>
<tr>
<td>Manage</td>
<td style="padding-left: 20px;">
<a id="linux_terminal" class="ui-button ui-widget ui-corner-all settings_button_small" href="#">Linux Terminal</a>
</td>
</tr>
<tr>
<td>Disk Usage</td>
<td style="padding-left: 20px;">{{drive_usage}}</td>
</tr>
<tr>
<td>CPU</td>
<td style="padding-left: 20px;">{{cpu_usage}}</td>
</tr>
<tr>
<td>RAM</td>
<td style="padding-left: 20px;">{{ram_usage}}</td>
</tr>
{% if device_temp != '...' %}
<tr>
<td>Temperature</td>
<td style="padding-left: 20px;">{{device_temp}} &deg;C</td>
</tr>
{% endif %}
<tr>
<td>Uptime</td>
<td style="padding-left: 20px;">{{uptime}}</td>
</tr>
<tr>
<td>Date</td>
<td style="padding-left: 20px;">{{date}}</td>
</tr>
</table>
<div class="divider"></div>
{% include 'includes/status_table.html' %}
<div class="settings_block_subheader">Settings</div>
<a href="/settings" class="ui-button ui-widget ui-corner-all settings_button">Settings</a>

View File

@ -54,6 +54,9 @@ def update_device_info():
# Get drive info
try:
# Get throttled info (raspi only)
reload_throttled_data()
# Get drive actual usage
#results = subprocess.check_output(["du","-sh","/mnt/hdd/mynode/"])
#drive_usage = results.split()[0]

View File

@ -719,6 +719,7 @@ fi
# Setup myNode Startup Script
systemctl daemon-reload
systemctl enable check_in
systemctl enable background
systemctl enable docker
systemctl enable mynode
systemctl enable quicksync