A Python Snippet to check the HIVEON pool & rig health

in #python2 months ago (edited)

If you have a rig mining at Hiveon, then this script may help you to do automations & notifications. Checking the rig health from this is not the best but I've needed a quick solution for now. (Still delaying to play with HiveOS at API level.)

heh.jpeg

Notification example on my mobile


I was looking for a quick way to restart the rig automatically if it's not sharing to the pool anymore. But cut these logic & lines from here and only left the notifications part.

Here is the logic:

  • Check rig stats from Hiveon
  • if the hash rate is 0 or the rig looks like it's not connected, then send a notification about the status. Notifications are handled w/ Pushover.
  • Repeat (Even though, repeat side should be handled via a crontab entry.)

import requests
import sys

from pushover import Client

PUSHOVER_TOKEN = "<pushover_token>"

machines = [{
    "name": "Rig 2.0",
    "wallet": "<wallet>",
    "pushover_client_key": "<receiver_key>"
}]


def send_notification(message, client_key):
    Client(
        client_key,
        api_token=PUSHOVER_TOKEN
    ).send_message(message, title="HiveON Alert")


def check_miners(name, wallet, pushover_client_key):
    r = requests.get(f"https://hiveon.net/api/v0/miner/{wallet}?currency=ETH")
    r.raise_for_status()
    data = r.json().get("data")
    hash_rate = int(data.get("hashrate"))
    if not hash_rate or data.get("offlineWorkerCount") > 0:
        message = f"{name} is not mining! Check the rig."
        send_notification(message, pushover_client_key)
        sys.exit(-1)
    else:
        mh = round(hash_rate / 1e6, 2)
        bill = requests.get(
            f"https://hiveon.net/api/v0/miner/{wallet}/bill?currency=ETH")
        bill.raise_for_status()
        stats = bill.json().get("stats")
        balance = stats.get("balance")
        message = f"{name} is currently mining with " \
                  f"{mh} mH. Balance: {balance} ETH."
        print(message)

if __name__ == '__main__':
    for rig in machines:
        check_miners(rig["name"], rig["wallet"], rig["pushover_client_key"])

Screen Shot 2020-09-20 at 22.38.29.png


Requires Python3.7+ and requests library. Note that, Hiveon API calls mentioned here are just reverse engineereed. They may change at any time and point. Use the script at your own risk.