python 当任何矿工的哈希率太低时重新启动ethOS。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 当任何矿工的哈希率太低时重新启动ethOS。相关的知识,希望对你有一定的参考价值。

#!/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()

以上是关于python 当任何矿工的哈希率太低时重新启动ethOS。的主要内容,如果未能解决你的问题,请参考以下文章