create account

Create Fancy Graph with metrics from XMRIG (2/3) by master-lamps

View this thread on: hive.blogpeakd.comecency.com
· @master-lamps ·
$0.84
Create Fancy Graph with metrics from XMRIG (2/3)
In [my last post](https://steemit.com/monero/@masterlamps/create-fancy-graph-with-metrics-from-xmrig-1-3) I showed how to configure the [HTTP API](https://github.com/xmrig/xmrig/blob/master/doc/API.md) of [XMRIG](https://github.com/xmrig/xmrig/releases/tag/v5.11.1) and query it with [curl](https://curl.haxx.se/), now I will use my [Raspberry Pi 2 Model B](https://www.raspberrypi.org/products/raspberry-pi-2-model-b/) to query my rigs and store the retrieved data in an [InfluxDB](https://www.influxdata.com/products/influxdb-overview/).

# Install [InfluxDB](https://www.influxdata.com/products/influxdb-overview/) 

[InfluxDB](https://www.influxdata.com/products/influxdb-overview/) is an time series database develeped by [InfluxData](https://www.influxdata.com/). It is written in Go and glorified for being a single binary and optimized for fast, high-availability storage and retrieval of time series data from different source like IoT devices, application metrics or network operation monitoring. It provides a SQL like querie language and differnt accees like API calls or CLI.

## Add the [InfluxDB](https://www.influxdata.com/products/influxdb-overview/) repository to the rpi
Dependening on the version of Debian is running on your Raspberry Pi different Urls are necessary to be added to the respository of the paket manager. The following code will add Url according to the used Debian version.
<code>wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/os-release
test $VERSION_ID = "7" && echo "deb https://repos.influxdata.com/debian wheezy stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "10" && echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update</code>

### Install [InfluxDB](https://www.influxdata.com/products/influxdb-overview/)
<code>sudo apt-get install influxdb</code>

### Start service provided from the installation package
<code>sudo service influxdb start</code>

### Configure [InfluxDB](https://www.influxdata.com/products/influxdb-overview/)
[InfluxDB](https://www.influxdata.com/products/influxdb-overview/) come with multiple configuration options and default configuration can beviewed with <code>influxd config</code>. The service use the configuration file stored in /etc/influxdb/influxdb.conf, but most of the options are commented out. [InfluxDB](https://www.influxdata.com/products/influxdb-overview/) uses for uncommented options the defaults settings. 
In order to enable HTTP requests with configuration of the service needs to be changed. For this remove the # for options **enabled, bind-address and auth-enabled** in configuration file.
To change the configuration of the service open it with a text:
<code>sudo nano /etc/influxdb/influxdb.conf</code>
![image.png](https://images.esteem.app/DQmWX6NqMyTu8R1sHPVE69MCsnZNBBJgpRpkFHrP3NGZLZs/image.png)

After that restart the service so the change can be take effect.
<code>sudo service influxdb restart</code>

### Connect to [InfluxDB](https://www.influxdata.com/products/influxdb-overview/) instance
The backend is now setup now for access the data managed by the service an additional package is necessary. For access the databases in CLI install **influxdb-client**.
<code>sudo apt-get install influxdb</code>
![image.png](https://images.esteem.app/DQmVKAJTi6WgszM2n3qyYfVaTK32sJAGaoLXB7Q6BXjWPXA/image.png)

### Access the databases
The managed databases by [InfluxDB](https://www.influxdata.com/products/influxdb-overview/) are accessable by
<code>show databases</code>
![image.png](https://images.esteem.app/DQmUNSBcP6tqT6MBVNdUAaGRCp3yvVtRZPK2f7xAVBY9wWJ/image.png)

### Create database for the metrics
The metrics of the rigs shall be stored in their own database called **rigs**. Databases are created with <code>CREATE DATABASE rigs</code>.
![image.png](https://images.esteem.app/DQmcUjxXXW3YhjHeTeDeSCqsuWZdWiMXL5AVocUKbrp2oyS/image.png)

### Test database
Before you can insert or select data, you have to select on databases with <code>use rigs</code>.
![image.png](https://images.esteem.app/DQmUQ4QprtbsExHtpvZmBwLDBSUSz6JmRiRzgozxz5c9HSC/image.png)
[InfluxDB](https://www.influxdata.com/products/influxdb-overview/) provides a SQL like language and INSERT statement like this:
<code>insert xmrigs,rig=testrick,currency=rx/0 value=12344.32</code>
This statement will create table called xmrigs with attributes rig, currency and the measure value 12344.32. The time stamp will be automatically added by the database.
The data can queried by:
<code>select * from xmrigs</code>
![image.png](https://images.esteem.app/DQmcNEeFkePWnV5pHu23inruAZ3SeN81xSMPabbvrQy4cLz/image.png)

# Collect metrics from [XMRIG](https://github.com/xmrig/xmrig/releases/tag/v5.11.1) rigs
The data will be collected by a script for each rig, which queries the rig HTTP API, parse HTTP result and store the date in database. The data will be queried periodcally by cronjobs.
## Query rigs API
First I created the script with collecting the data from the [XMRIG HTTP API](https://github.com/xmrig/xmrig/blob/master/doc/API.md), parse the resulting [JSON](https://en.wikipedia.org/wiki/JSON), and extract with [jq](https://stedolan.github.io/jq/) the fields I need. [XMRIG](https://github.com/xmrig/xmrig/releases/tag/v5.11.1) offers diffrent endpoints, I will use /1/summary. From this endpoint I will collect the **worker-id, algo and first entry the hashrate table**. 
<code>#collect data from API
json=$(curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer wWhearsgoL4w6zPT" http://x.x.x.x:9971/1/summary)
#extract hashrate, worker_id, currency
hashrate=$(echo $json  | jq -r '.hashrate.total[0]')
workerid=$(echo $json  | jq -r '.worker_id')
currency=$(echo $json | jq -r '.algo')</code>

## Store Data in [InfluxDB](https://www.influxdata.com/products/influxdb-overview/)
After that I extended that script with a call to the HTTP API of [InfluxDB](https://www.influxdata.com/products/influxdb-overview/). For writing data, the endpoint /write is used. It is uses as query option the database you want to write to and takes as binary data the data to write. 
<code>curl -i -XPOST 'http://localhost:8086/write?db=rigs' --data-binary "xmrigs,rig=$workerid,currency=$currency value=$hashrate"</code>
## Create cronjobs for data retrieval
The periodacal execution of the retrieval script, I will do with cronjobs. The metrics shall be queried every minute, which 5 * for each script call. To open the crontab call <code>crontab -e</code>.
![image.png](https://images.esteem.app/DQmcJcTJ1swr9xbqq5L34EjEzqJNVec8brkajfY3vAX2v7g/image.png)

After some time the database should be filled with some entries from different rigs.
![image.png](https://images.esteem.app/DQmaktDBrxXGAgKteTJjJYw5GF7Yf3RsbchJwzPDV3mprrZ/image.png)

Now the database is setup and filled with data on timely manner. Installing [Grafana](https://grafana.com/) and creating a dashboard for the data I will do in another post.

Please up vote, comment and resteem my post. If you like this please donate to 42D2sPUubqCCqK3MD8BnDDSyjgNqbrLH6HcHXrZWaqYZfUqyoDcRsfTQNp345N1NSDLr8qBJ5QqjQ4V95nix6qH9Je8BX2U
Thank you so much in advance.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authormaster-lamps
permlinkcreate-fancy-graph-with-metrics-from-xmrig-2-3
categorymonero
json_metadata{"links":["https://steemit.com/monero/@masterlamps/create-fancy-graph-with-metrics-from-xmrig-1-3","https://github.com/xmrig/xmrig/blob/master/doc/API.md","https://github.com/xmrig/xmrig/releases/tag/v5.11.1","https://curl.haxx.se/","https://www.raspberrypi.org/products/raspberry-pi-2-model-b/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/","https://www.influxdata.com/products/influxdb-overview/","https://repos.influxdata.com/influxdb.key","https://repos.influxdata.com/debian","https://repos.influxdata.com/debian","https://repos.influxdata.com/debian","https://repos.influxdata.com/debian","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","https://github.com/xmrig/xmrig/releases/tag/v5.11.1","https://github.com/xmrig/xmrig/blob/master/doc/API.md","https://en.wikipedia.org/wiki/JSON","https://stedolan.github.io/jq/","https://github.com/xmrig/xmrig/releases/tag/v5.11.1","http://x.x.x.x:9971/1/summary","https://www.influxdata.com/products/influxdb-overview/","https://www.influxdata.com/products/influxdb-overview/","http://localhost:8086/write?db=rigs","https://grafana.com/"],"image":["https://images.esteem.app/DQmWX6NqMyTu8R1sHPVE69MCsnZNBBJgpRpkFHrP3NGZLZs/image.png","https://images.esteem.app/DQmVKAJTi6WgszM2n3qyYfVaTK32sJAGaoLXB7Q6BXjWPXA/image.png","https://images.esteem.app/DQmUNSBcP6tqT6MBVNdUAaGRCp3yvVtRZPK2f7xAVBY9wWJ/image.png","https://images.esteem.app/DQmcUjxXXW3YhjHeTeDeSCqsuWZdWiMXL5AVocUKbrp2oyS/image.png","https://images.esteem.app/DQmUQ4QprtbsExHtpvZmBwLDBSUSz6JmRiRzgozxz5c9HSC/image.png","https://images.esteem.app/DQmcNEeFkePWnV5pHu23inruAZ3SeN81xSMPabbvrQy4cLz/image.png","https://images.esteem.app/DQmcJcTJ1swr9xbqq5L34EjEzqJNVec8brkajfY3vAX2v7g/image.png","https://images.esteem.app/DQmaktDBrxXGAgKteTJjJYw5GF7Yf3RsbchJwzPDV3mprrZ/image.png"],"tags":["monero","xmrig","xmr","influxdb","grafana","raspberrypi","metrics"],"app":"esteem/2.2.7-surfer","format":"markdown+html","community":"esteem.app"}
created2020-05-21 15:30:03
last_update2020-05-21 15:30:03
depth0
children3
last_payout2020-05-28 15:30:03
cashout_time1969-12-31 23:59:59
total_payout_value0.414 HBD
curator_payout_value0.425 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,520
author_reputation64,188,838,587,049
root_title"Create Fancy Graph with metrics from XMRIG (2/3)"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,505,856
net_rshares2,386,205,262,041
author_curate_reward""
vote details (32)
@esteemapp ·
**Yay!** <br>Your post has been **boosted with ESTM**. Keep up the good work! <br>Dear reader, Install Android: https://android.esteem.app, iOS: https://ios.esteem.app mobile app or desktop app for Windows, Mac, Linux: https://desktop.esteem.app<br>Learn more: https://esteem.app <br>Join our discord: https://discord.me/esteem
👍  
properties (23)
authoresteemapp
permlinkre-2020522t81617872z
categorymonero
json_metadata{"tags":["esteem"],"app":"esteem/2.2.6-welcome","format":"markdown+html","community":"hive-125125"}
created2020-05-22 06:16:18
last_update2020-05-22 06:16:18
depth1
children0
last_payout2020-05-29 06:16:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length327
author_reputation420,443,679,514,793
root_title"Create Fancy Graph with metrics from XMRIG (2/3)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,517,112
net_rshares0
author_curate_reward""
vote details (1)
@hivebuzz ·
Congratulations @master-lamps! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@master-lamps/upvotes.png?202005312047"></td><td>You distributed more than 400 upvotes. Your next target is to reach 500 upvotes.</td></tr>
</table>

<sub>_You can view [your badges on your board](https://hivebuzz.me/@master-lamps) And compare to others on the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Do not miss the last post from @hivebuzz:**
<table><tr><td><a href="/hivebuzz/@hivebuzz/shop"><img src="https://images.hive.blog/64x128/https://i.imgur.com/soiD80C.png"></a></td><td><a href="/hivebuzz/@hivebuzz/shop">Introducing HiveBuzz Shop - Offer gifts with your favorite badges</a></td></tr></table>

###### Support the HiveBuzz project. [Vote for our proposal](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22109%22%5D&approve=true)!
👍  
properties (23)
authorhivebuzz
permlinkhivebuzz-notify-master-lamps-20200531t211913000z
categorymonero
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2020-05-31 21:19:12
last_update2020-05-31 21:19:12
depth1
children0
last_payout2020-06-07 21:19:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,094
author_reputation369,474,964,709,674
root_title"Create Fancy Graph with metrics from XMRIG (2/3)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,698,726
net_rshares0
author_curate_reward""
vote details (1)
@masterlamps ·
Great work.
👍  
properties (23)
authormasterlamps
permlinkre-master-lamps-2020521t23746821z
categorymonero
json_metadata{"tags":["monero","xmrig","xmr","influxdb","grafana","raspberrypi","metrics"],"app":"esteem/2.2.7-surfer","format":"markdown+html","community":"esteem.app"}
created2020-05-21 21:07:51
last_update2020-05-21 21:07:51
depth1
children0
last_payout2020-05-28 21:07:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length11
author_reputation220,443,053
root_title"Create Fancy Graph with metrics from XMRIG (2/3)"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,510,885
net_rshares8,665,606
author_curate_reward""
vote details (1)