During development of our Relay@Home project we created a CPU monitor dashboard using Grafana so that we could evaluate the performance of the Raspberry Pi. This guide shows a modified version of the dashboard that can be setup on any Ark Bridgechain Relay running on a VPS. This could be useful tool for network operators.
Live Dashboard running on one of our Ark Relays: https://grafana.littleyus.com/d/sF7d-FHZz/relay-cpu-monitor
Screenshot of dashboard
Software Installation
The visualization suite is comprised of three open source software applications:
- InfluxDB is an open-source time series database.
- Telegraf is an agent for collecting metrics from systems.
- Grafana is an open source data visualization tool.
Add Repositories
InfluxDB Ubuntu 18.04
echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
InfluxDB Ubuntu 20.04/21.04
echo "deb https://repos.influxdata.com/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
Grafana 18.04/20.04/21.04
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
Installation
Install Grafana, InfluxDB and Telegraf
sudo apt-get update
sudo apt-get install -y grafana influxdb telegraf
Enable services
sudo systemctl enable influxdb grafana-server telegraf
sudo systemctl start influxdb grafana-server telegraf
The successful start can be verified via:
sudo systemctl status telegraf.service
sudo systemctl status influxdb.service
sudo systemctl status grafana-server.service
Configuration
Configure InfluxDB
We are going to create a database with the following parameters:
- database name: telegraf
- Database retention: four weeks
- user: telegrafuser
- password: telegrafpassword23
Start Influx CLI:influx
Create database> create database telegraf
> use telegraf
> create user telegrafuser with password 'telegrafpassword23' with all privileges
> grant all privileges on telegraf to telegrafuser
> create retention policy "4Weeks" on "telegraf" duration 4w replication 1 default
> exit
Configure Telegraf
Open Telegraf configuration filesudo nano /etc/telegraf/telegraf.conf
To send local agent data to InfluxDB, uncomment and/or alter the following sections of the central Telegraf configuration file.
[[outputs.influxdb]]
urls = ["http://127.0.0.1:8086"]
## For UDP url endpoint database needs to be configured on server side.
database = "telegraf"
## HTTP Basic Auth
username = "telegrafuser"
password = "telegrafpassword23"
To complement the default Telegraf configuration we will add a few more parameters to monitor by creating a new custom configuration file.
create and open file:sudo nano /etc/telegraf/telegraf.d/relay.conf
Copy the following to the file:
[[inputs.net]]
[[inputs.netstat]]
Reload Telegraf Servicesudo systemctl reload telegraf.service
Check the status of the service for errorssudo systemctl status telegraf.service
Check that data is being written to database
Start Influx CLIsudo influx
Select Database> use telegraf
Display measurements stored in Database> show measurements
You should see the following result:
name: measurements
name
----
cpu
disk
diskio
kernel
mem
net
netstat
processes
swap
system
>
Display the last 5 data points from “system” measurement:> select * from system limit 5
You should see results similar to the following:
name: system
time host load1 load15 load5 n_cpus n_users uptime uptime_format
---- ---- ----- ------ ----- ------ ------- ------ -------------
1618891060000000000 Ubuntu18-DashboardTest 0.16 0.15 0.29 1 1 359 0:05
1618891070000000000 Ubuntu18-DashboardTest 0.13 0.15 0.28 1 1 369 0:06
1618891080000000000 Ubuntu18-DashboardTest 0.11 0.15 0.27 1 1 379 0:06
1618891090000000000 Ubuntu18-DashboardTest 0.09 0.15 0.26 1 1 389 0:06
1618891100000000000 Ubuntu18-DashboardTest 0.08 0.14 0.26 1 1 399 0:06
Configure Grafana
Add JSON API data source pluginsudo grafana-cli plugins install marcusolsson-json-datasource
Reload Grafana Servicesudo systemctl restart grafana-server
It is assumed that UFW is being used as your firewall. Open port on firewallsudo ufw allow 3000
Open the following URL in your webbrowser to reach the login screen: http://your_IP_address:3000
Default Login info is:
username: admin
password: admin
It will immediately ask you to change the password.
Add InfluxDB as a data source
menu: Configuration->Data Sources
Select: “Add data source”
Select: ‘InfluxDB”
Configure the following parameters
Name: InfluxDB
URL = http://localhost:8086
Database: telegraf
User: telegrafuser
Password: telegrafpassword23
HTTP Method: GET
Press “Save & Test”: You should get message that says “Data source is working”
Add JSON API as a data source
menu: Configuration->Data Sources
Select: “Add data source”
Select: ‘JSON API”
Configure the following parameters (Change the API port number specific to your chain)
Name: JSON API Local
URL = http://127.0.0.1:4003
Add Dashboard
Download Reference CPU Monitor Dashboard:
https://gist.github.com/PhillipJacobsen/859a33d429882edd466a9bd2a8b58331
menu: Dashboard->Manage
Select: Import
Select: Upload JSON file
Upload the JSON file previously downloaded.
Select “InfluxDB” and “JSON API Local” as the data sources.
Set as your default home dashboard
menu: Dashboards->Home
Under “Recently viewed dashboards” you will see the new dashboard you created. Star it.
menu: Configuration->Preferences
You can select the new dashboard as the “Home Dashboard”
Now the CPU monitor dashboard will load immediately when logging in.
Configure Grafana Dashboards to be viewable by public without login (OPTIONAL)
By default Grafana is configured so that you need to be logged in to edit or view dashboards. Often I want dashboards to be viewable by others without a login.
- Make Grafana dashboard public without login. Edit Grafana config file
nano /etc/grafana/grafana.ini
- in the [auth.anonymous] section make the following changes.
[auth.anonymous]
# enable anonymous access
enabled = true
# specify organization name that should be used for unauthenticated users
org_name = Main Org.
# specify role for unauthenticated users
org_role = Viewer
- Restart Grafana
service grafana-server restart