create account

A Python Snippet to check the HIVEON pool & rig health by emrebeyler

View this thread on: hive.blogpeakd.comecency.com
· @emrebeyler · (edited)
$9.85
A Python Snippet to check the HIVEON pool & rig health
If you have a rig mining at [Hiveon](https://hiveon.net), 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.) 


<center>![heh.jpeg](https://images.hive.blog/DQmRcP8YEN4KGM3LX21nHfUWBamkdtJUfKB4v686P127Z9c/heh.jpeg)</center>
<center>Notification example on my mobile</center>

***

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](https://pushover.net/).
- 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"])
```
***

<center>![Screen Shot 2020-09-20 at 22.38.29.png](https://images.hive.blog/DQmTYkvAqBNGicr2ZSK35M7AwNP57a8DWc9DY5mW9WZSGTC/Screen%20Shot%202020-09-20%20at%2022.38.29.png)</center>
***

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.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 167 others
properties (23)
authoremrebeyler
permlinka-python-snippet-to-check-the-hiveon-pool-and-rig-health
categorypython
json_metadata{"tags":["hiveon"],"image":["https://images.hive.blog/DQmRcP8YEN4KGM3LX21nHfUWBamkdtJUfKB4v686P127Z9c/heh.jpeg","https://images.hive.blog/DQmTYkvAqBNGicr2ZSK35M7AwNP57a8DWc9DY5mW9WZSGTC/Screen%20Shot%202020-09-20%20at%2022.38.29.png"],"links":["https://hiveon.net","https://pushover.net/"],"app":"hiveblog/0.1","format":"markdown"}
created2020-09-20 20:41:12
last_update2020-09-20 20:42:30
depth0
children0
last_payout2020-09-27 20:41:12
cashout_time1969-12-31 23:59:59
total_payout_value5.586 HBD
curator_payout_value4.262 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,627
author_reputation448,535,049,068,622
root_title"A Python Snippet to check the HIVEON pool & rig health"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,732,297
net_rshares41,168,872,547,516
author_curate_reward""
vote details (231)