Skip to content

Instantly share code, notes, and snippets.

@webcpu
Last active June 28, 2019 21:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webcpu/6cf00262db3a5618ec244471b9d94fd2 to your computer and use it in GitHub Desktop.
Save webcpu/6cf00262db3a5618ec244471b9d94fd2 to your computer and use it in GitHub Desktop.
Reboot ethOS when any miner's hash rate is too low.
#!/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()
@timothydv
Copy link

Where and how do i put this file ?

@webcpu
Copy link
Author

webcpu commented Mar 8, 2018

@timothydv /home/ethos/monitor.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment