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。的主要内容,如果未能解决你的问题,请参考以下文章

当我的视图控制器上的按钮放置得太低时,为啥我的按钮停止工作?

当任何文件发生更改时,在 Docker 容器中重新启动 Python 脚本

为啥微信小程序拍摄图片信息异常

区块链入门到实战之区块链 – 链接区块

GEC矿工“哈希算法”百科。GEC区块链查询上线……

重新加载页面上有哈希值