A simple Go app that reads NBMiner status REST API data and sends it to InfluxDB.
Using the reporter is quite easy, specially if you've already setup NBMiner before.
This app assumes your NBMiner is exposing status data through its REST API. If you haven't enable it, follow these simple steps:
-
Go NBMiner folder.
-
Open and edit the file you execute to start the miner (the one that has your wallet id in it).
-
At the end of the line, add the following flag
--api 127.0.0.1:8000
.What this flag does is enabling a REST API that exposes the miner status data, such as temp or hasrates.
You can check all the info at NBMiner official docs: here.
IMPORTANT: This API does exposes your wallet id, but is still only accessible from the machine. NBMiner Reporter WON'T send the wallet id to InfluxDB, that's the only field ignored while sending the data.
-
Save and close the file, and now restart the miner.
-
Let's check the API is working. Open a web browser, and go to http://localhost:8000.
You should see a website with a bunch of information about your miner, the same that is shown in the terminal while the miner is running, plus some extra data.
That's it, you're ready to continue with NBMiner Reporter installation.
-
Get the Windows files from the latests release: Download Now
-
Unzip the file on a separated folder than NBMiner.
-
Edit the
start_win_nbreporter.bat
file:- Change
rigX
with the friendly name you want your miner to be called - Change
influxdb.my.organization.net
URL with your InfluxDB server URL. - If you need to set a different InfluxDB port than default, use the option
-p 8080
. - If you need to set a different InfluxDB schema than default, use the option
-l https
. - If you are using InfluxDB 2 check the influx setup section, and be sure to use the
-t
option to provide the API Token.
- Change
-
Execute
start_win_nbreporter.bat
. A shell window will open, and you should see an output like the following:INFO[0000] NBMiner Status Reporter Initiated INFO[0000] Using Friendly Name: rigX INFO[0005] Checking Status.
That's it, you're now sending your miner status to InfluxDB.
-
Get the Linux files from the latests release: Download Now
-
Untar the file on a separated folder than NBMiner.
-
Edit the
start_lnx_nbreporter.sh
file:- Change
rigX
with the friendly name you want your miner to be called - Change
influxdb.my.organization.net
URL with your InfluxDB server URL. - If you need to set a different InfluxDB port than default, use the option
-p 8080
. - If you need to set a different InfluxDB schema than default, use the option
-l https
. - If you are using InfluxDB 2 check the influx setup section, and be sure to use the
-t
option to provide the API Token.
- Change
-
Execute
start_lnx_nbreporter.sh
. A terminal window will open, and you should see an output like the following:INFO[0000] NBMiner Status Reporter Initiated INFO[0000] Using Friendly Name: rigX INFO[0005] Checking Status.
That's it, you're now sending your miner status to InfluxDB.
You have to be sure that the organization and buckets given to NBReporter already exists in InfluxDB before running the app. Here is an example of how to do it.
If you're using InfluxDB 1.8.X you just need to create the Database. To do so, simply run the following command on Influx:
CREATE DATABASE miner WITH DURATION 7d REPLICATION 1 SHARD DURATION 1h
Here is an example to execute it using curl
:
curl -X POST localhost:8086/query --data-urlencode "q=CREATE DATABASE miner WITH DURATION 7d REPLICATION 1 SHARD DURATION 1h"
Be sure to change localhost:8086
with the host and port of you InfluxDB server.
If you're using InfluxDB 2.X you just need to create the Organization, and the Bucket. To do so, simply use the influx cli and the setup command:
influx setup \
--username miner \
--password miner-pass \
--org miner-org \
--bucket miner \
--retention 4w \
-f
You should get an output like the following:
User Organization Bucket
miner miner-org miner
Now create a API token for the reporter
influx auth create -o miner-org --write-buckets
You should get an output like this:
ID Description Token User Name User ID Permissions
088362ce9ff2b000 8xO2sKCy9LvNnCQBhFbpfCFmcPoTRS0an1_sB8pYJHRAIOD5jEoGZFQFIShOTLyeJs1jryo5zMGLTGhnl__9wg== miner 088362615672b000 [write:orgs/cc0045af7ecbbcb7/buckets]
Copy the token
and pass it to the reporter using the -t
option.
Or, if you have already done InfluxDB setup and just need to add a new organization and bucket:
influx org create --name miner-org --token <auth_token>
influx bucket create --name miner --org miner-org --retention 30d --token <auth_token>
Customize the way NBMiner Reporter works by using the following options:
nbreporter [-v] [-b string] [-f number] [-d number] [-h string] [-l string] [-n string] [-o string] [-p number] [-r strinumberng] [-s string] [-t string] [-c number] [--help]
Check the options details.
Short Flag | Long Flag | Description |
---|---|---|
-n | --name=string | A friendly name for miner. Default: hostname |
-f | --freq=number | Status check frequency in seconds. Default: 60 |
-d | --round=number | Round up the status timestamp seconds. Default: 1 |
-h | --ihost=string | InfluxDB Host. Default: localhost |
-p | --iport=number | InfluxDB Port. Default: 8086 |
-l | --iproto=string | InfluxDB Protocol. Default: http |
-t | --token=string | InfluxDB Access Token. |
-u | --username=string | InfluxDB Username (For v1.8.x). |
-w | --password=string | InfluxDB Password (For v1.8.x). |
-b | --bucket=string | InfluxDB Bucket. Default: miner |
-o | --org=string | InfluxDB Organization. Default: miner-org |
-r | --nbport=number | NBMiner API Port. Default: 8000 |
-s | --nbhost=string | NBMiner API Host. Default: localhost |
-c | --cache=number | Cache size. Set to 0 to disable Cache. Default: 60 |
-v | Run in Verbose mode. Default: false | |
--help | Show usage options. |
To run the reporter on local environment, meaning, both the miner and influx are running on the same machine, you can simply run:
nbreporter -n rigX
It'll send all the data using friendlyName "rigX".
If you have a remote Influx, under HTTPS, and security enable (you need a token to access it), you can run something like:
nbreporter -n rigX -h influxdb.my.organization.net -p 443 -l https -t Teojw8a9HHFPN0TR34L
Or, if you want to get data from a miner running on you local network:
nbreporter -n rigX -s 192.168.1.13
Use the InfluxDb and Grafana dashboards examples located at dashboards folder.
To use the InfluxDB dashboard, you'll have to import the variable first.
NBMiner Reporter has been tested using the following setups:
NBM Reporter Ver. | NBMiner Vers. | OS | InfluxDB |
---|---|---|---|
v1.2.X | 39.7 - 40.1 | Windows 10, HiveOS | 1.8.10, 2.0.x, 2.1.x |
v1.1.X | 39.7 - 40.1 | Windows 10, HiveOS | 1.8.10, 2.0.x, 2.1.x |
v1.0.X | 39.7 - 40.1 | Windows 10, HiveOS | 1.8.10, 2.0.x, 2.1.x |
To work on your local machine, and build the go app, we recommend using a docker container, so you don't have to install GO SDK if you don't have it, and ensure you have a clean environment to work with.
-
Fork this repo, and clone it in your computer.
-
Open a terminal, and move to the repository folder.
-
Use this command to start the container:
docker run --rm -it --name nbreporter -v `pwd`:/src -w /src golang:1.17.3-alpine3.14 sh
-
Once on the container, build the app by running
go build ./cmd/nbreporter/...
Now you have your app built, you need to be able to run it. This app takes data from a REST API, and sends it to an InfluxDB service, so in order to be able to test it, you'll need both services accessibe from the development machine.
Worry not, you won't need to access an actual miner rig, we got you covered. We've created a NBMiner Status Simulator, basically a very simple web app that exposes the same REST API as the NBMiner, but with random numbers. Enough for develpment and testing right? Also, we've set it up on a docker-compose file with an InfluxDB service to use.
-
Build the simulator image locally:
docker-compose build
-
Start the services:
docker-compose up
-
Back on your development container, run the app:
go run ./cmd/nbreporter/... -s host.docker.internal -t shhh-secret-token -f 5 -h host.docker.internal
-
Go to your browser and point it to http://localhost:8888. You should see a Cronograf UI wich you can use to query InfluxDB and check the data points.