Last active
June 28, 2019 21:28
-
-
Save webcpu/6cf00262db3a5618ec244471b9d94fd2 to your computer and use it in GitHub Desktop.
Reboot ethOS when any miner's hash rate is too low.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
# 1. Save this file in /home/ethos/monitor.py on your ethOS | |
# 2. Change permission to make it executable | |
# chmod 0755 /home/ethos/monitor.py | |
# 3. Run crontab | |
# # crontab -e | |
# 4. Schedule a cron task to execute every 5 minutes | |
""" | |
## runs this script every 5 minutes | |
*/5 * * * * /home/ethos/monitor.py | |
""" | |
def main(): | |
def should_reboot(): | |
def count_low_hashrate_miners(): | |
def miner_hashrates(): | |
def read_lastline(filename): | |
with open(filename) as f: | |
xs = f.readlines() | |
return xs[-1] | |
def read_numbers(s): | |
xs = s.strip().split(' ') | |
return [float(x) for x in xs] | |
filename = "/var/run/ethos/miner_hashes.file" | |
return read_numbers(read_lastline(filename)) | |
def is_low_hashrate(x): | |
low_hashrate_threshold = 10.0 | |
return x < low_hashrate_threshold | |
def filter_list(f, xs): | |
return list(filter(f, xs)) | |
return filter_list(is_low_hashrate, miner_hashrates()) | |
def has_bad_miners(hs): | |
return len(hs) > 0 | |
return has_bad_miners(count_low_hashrate_miners()) | |
def reboot(): | |
print("rebooting...") | |
os.system("/opt/ethos/bin/r") | |
if should_reboot(): | |
reboot() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where and how do i put this file ?