Monitoring

The YouTube video is in German.

Installing Grafana server:

Official documentation: https://grafana.com/docs/grafana/latest/installation/debian/

sudo adduser grafana
sudo usermod -aG sudo grafana
sudo su grafana
cd ~
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/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana-enterprise
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
Build MQTT data source:

GitHub issue explanation: https://github.com/grafana/mqtt-datasource/issues/15#issuecomment-894477802

Install Go:

wget -O -https://raw.githubusercontent.com/mauleyzaola/scripts/master/go/go.install.sh | sh
source ~/.bashrc

Install Mage:

sudo apt install git
git clone https://github.com/magefile/mage
cd mage
go run bootstrap.go

Install NodeJS 16:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

Enable yarn:

sudo corepack enable

Configure Grafana:

sudo nano /etc/grafana/grafana.ini

Change the following values:

plugins = /var/lib/grafana/plugins
allow_loading_unsigned_plugins = grafana-mqtt-datasource

Create Grafana plugin directory:

mkdir /var/lib/grafana/plugins

Change into the plugin directory and start the build process:

mkdir /var/lib/grafana/plugins
cd /var/lib/grafana/plugins
git clone https://github.com/grafana/mqtt-datasource.git
cd mqtt-datasource
yarn add @grafana/toolkit
yarn build
yarn install
sudo systemctl restart grafana-server
Install and configure Mosquitto:

Create service account and install Mosquitto

sudo adduser mosquitto
sudo usermod -aG sudo mosquitto
sudo su mosquitto
cd ~
sudo apt install mosquitto
sudo systemctl enable mosquitto
sudo systemctl start mosquitto

Create the config file:

sudo nano /etc/mosquitto/conf.d/mosquitto.conf

Insert the following config:

listener 1883 0.0.0.0
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/pwfile

Create the password file:

sudo nano /etc/mosquitto/pwfile

Type the username and password in this format:

username:password

Hash the password:

sudo mosquitto_passwd -U /etc/mosquitto/pwfile
sudo systemctl restart mosquitto
Install and configure Prometheus; Add a node to Prometheus:

Create service account and install Prometheus:

sudo adduser prometheus
sudo usermod -aG sudo prometheus
sudo su prometheus
cd ~
wget https://github.com/prometheus/prometheus/releases/download/v2.36.0/prometheus-2.36.0.linux-amd64.tar.gz
tar -xzvf prometheus-2.36.0.linux-amd64.tar.gz
mv prometheus-2.36.0.linux-amd64/ prometheus/

Create the prometheus service:

sudo nano /etc/systemd/system/prometheus.service

Add service config:

[Unit]
Description=Prometheus Server
After=network-online.target

[Service]
User=prometheus
Restart=on-failure
ExecStart=/home/prometheus/prometheus/prometheus \
--config.file=/home/prometheus/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus/prometheus/data

[Install]
WantedBy=multi-user.target

Reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl enable prometheus
Install the node exporter:

Create service account (if it doesn’t exist yet):

sudo usermod -aG sudo prometheus 
sudo adduser prometheus
sudo su prometheus

Install the node exporter:

cd ~
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar -xzvf node_exporter-1.3.1.linux-amd64.tar.gz
mv node_exporter-1.3.1.linux-amd64/ node_exporter/

Create the service for the node exporter:

sudo nano /etc/systemd/system/node_exporter.service

Paste service config:

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
ExecStart=/home/prometheus/node_exporter/node_exporter

[Install]
WantedBy=default.target

Reload systemd and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable node_exporter

Configure Prometheus data source:

sudo su prometheus
cd ~
nano ./prometheus/prometheus.yml

Paste at the end of the config file:

- job_name: 'node_exporter'
  static_configs:
   - targets: ['localhost:9100']

Restart prometheus:

sudo systemctl restart prometheus

Now you have to import the node exporter dashboard (ID: 1860) to Grafana.

You’re done installing a up and running open source monitoring system.

Leave a Reply

Your email address will not be published. Required fields are marked *