Community discussions

MikroTik App
 
bruins0437
newbie
Topic Author
Posts: 33
Joined: Thu Jul 13, 2017 4:30 am
Location: New Hampshire

[GUIDE] Grafana, Prometheus, and snmp_exporter

Fri Feb 17, 2023 10:53 pm

This guide is for Ubuntu Server 22.04 and what I call Promstack (Grafana, Prometheus, and snmp_exporter).

Have an installed, updated Ubuntu 18.04 or newer (preferably 22.04).

Prep for Prometheus install:
sudo apt update && sudo apt dist-upgrade -y
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
sudo mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
sudo apt update
sudo apt -y install wget curl

----------------------------------------------------------------------------------------

Install Prometheus:

mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
tar xvf prometheus*version*.tar.gz (say prometheus-2.18.0)

cd prometheus*version*/
sudo mv prometheus promtool /usr/local/bin/

prometheus --version
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/

----------------------------------------------------------------------------------------

Create Prometheus Service File

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

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
#ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

Adjust directory permissions:
for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done

Create, Enable and Start Prometheus:
sudo chown -R prometheus:prometheus /var/lib/prometheus/
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl status prometheus

----------------------------------------------------------------------------------------

With Prometheus now running we can get snmp_exporter installed. Version 0.21.0 was latest at time of writing this.
snmp_exporter page [url]https://github.com/prometheus/snmp_exporter[/url]

wget https://github.com/prometheus/snmp_exporter/releases/download/v0.21.0/snmp_exporter-0.21.0.linux-amd64.tar.gz
tar xvf snmp_exporter-0.21.0.linux-amd64.tar.gz
sudo mv snmp_exporter-0.21.0.linux-amd64 /etc/prometheus/snmp_exporter

----------------------------------------------------------------------------------------

Create snmp_exporter service file:
sudo nano /etc/systemd/system/snmp_exporter.service

[Unit]
Description=Mikrotik SNMP Exporter

[Service]
User=prometheus
ExecStart=/etc/prometheus/snmp_exporter/snmp_exporter --config.file="/etc/prometheus/snmp_exporter/snmp.yml"

[Install]
WantedBy=default.target

----------------------------------------------------------------------------------------

Edit /etc/prometheus/prometheus.yml 
You can clear out the existing file and copy the contents of the sample prometheus.yml file attached to this post.

Edit /etc/prometheus/prometheus/snmp_exporter/snmp.yml  (I typically delete the existing file and copy the contents of the snmp.yml file attached to this post.) [b]Do not forget to adjust the SNMP_COMMUNITY near the top of the snmp.yml file.[/b]

----------------------------------------------------------------------------------------

Create, Enable and Start snmp_exporter:

sudo systemctl daemon-reload
sudo systemctl enable --now snmp_exporter
sudo systemctl status snmp_exporter
sudo systemctl restart prometheus
----------------------------------------------------------------------------------------

Lastly we install Grafana. Version 9.3.6 was the latest at the time of writing this.

sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_9.3.6_amd64.deb
sudo dpkg -i grafana-enterprise_9.3.6_amd64.deb

sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

You will need to open port tcp/3000 on Ubuntu Server UFW to allow access to grafana.
sudo ufw allow 3000

----------------------------------------------------------------------------------------

Login to Grafana with default creds admin/admin.  It will ask you to change admin password.

Once in Grafana, go to Settings (gear icon) on lower left side and select Data Sources.

Click Add New Data Source and select prometheus.

Under HTTP fill in URL = http://localhost:9090

Scroll down and click Save Test.  You should get a success message.

----------------------------------------------------------------------------------------

With Prometheus, snmp_exporter and Grafana running and configured you should be collecting SNMP data from your Mikrotik(s).  There are a few pre built dashboards out there.  I ended up building my own.

You do not have the required permissions to view the files attached to this post.
 
Dizzya
just joined
Posts: 1
Joined: Mon Mar 20, 2023 8:50 pm

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Tue Mar 21, 2023 6:24 pm

Thank you, @bruins0437! That is straight forward and clear step-by-step instruction. Really appreciate your kind insight!
 
theQuikest
just joined
Posts: 1
Joined: Tue Mar 21, 2023 7:34 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Fri Mar 24, 2023 1:13 pm

Thanks from me alse @bruins0437! I already had things running, but needed to update snmp_exporter and Prometheus and for the life of me couldn't remember how I did it. Documented it this time :D

Might I add that running SNMP v2 isen't secured and SNMP v3 is supported both by MikroTik and snmp_exporter.

On MikroTik terminal:
/snmp community add addresses=::/0 name=prometheus security=authorized read-access=yes write-access=no authentication-protocol=MD5 encryption-protocol=DES authentication-password=AUTH-PASS encryption-password=ENCR-PASS
Edit "name", "AUTH-PASS", "ENCR-PASS" and addresess=<IP-ADDRESS-OF-PROMETHEUS-SERVER"
/snmp set contact=<your-e-mail@example.com enabled=yes engine-id=mikrotik location="<location-of-MikroTik>" trap-community=prometheus trap-target=<ip-address-of-Mikrotik> trap-version=3
"Contact" and "Location" are optional, "trap-target" is MikroTik's IP address

On the Prometheus/snmp_exporter/Grafana server:
Then place this code block to the top of snmp.yml replacing AUTH-PASS, ENCR-PASS and username with:
version: 3
  auth:
    security_level: authNoPriv
#    community: prometheus
    username: prometheus
    password: AUTH-PASS
    auth_protocol: MD5
    priv_protocol: AES
    priv_password: ENCR-PASS
    context_name: mikrotik
Last edited by theQuikest on Sat Mar 25, 2023 9:44 am, edited 1 time in total.
 
beginer0504
just joined
Posts: 20
Joined: Tue Jul 31, 2018 11:39 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Mon Apr 03, 2023 6:59 am

Hi bruins0437
Could you please give me your Grafana dashboard ID
Tks,
 
bruins0437
newbie
Topic Author
Posts: 33
Joined: Thu Jul 13, 2017 4:30 am
Location: New Hampshire

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Fri Apr 07, 2023 6:28 pm

Might I add that running SNMP v2 isen't secured and SNMP v3 is supported both by MikroTik and snmp_exporter.
Awesome! I will give this a try.
 
bruins0437
newbie
Topic Author
Posts: 33
Joined: Thu Jul 13, 2017 4:30 am
Location: New Hampshire

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Fri Apr 07, 2023 8:47 pm

Hi bruins0437
Could you please give me your Grafana dashboard ID
Tks,
Grafana Dashboard ID: 18460

It looks like it may not have posted yet. I did recently upload it.
 
vitaly2016
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Wed Jan 20, 2016 9:26 am
Location: Ukraine

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Wed Apr 19, 2023 11:07 am

Grafana Dashboard ID: 18460

It looks like it may not have posted yet. I did recently upload it.
May I ask you how did you generate your own snmp.yml?

My Mikrotik router is CCR2004 and it seems to me that many of OIDs in your snmp.yml are not working with my CCR2004
I repeated all your steps, imported 18460 Dashboard at final step and have working only some things in Grafana: Model,Board Name, System load, Board ver, Interface Colored Table.
But anything below Interface Table is not working. For example all ethernet "Traffic" panels are empty. They have real ethernet names but have no data.
 
gr3g0ps
just joined
Posts: 1
Joined: Wed Apr 19, 2023 4:08 pm

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Tue Apr 25, 2023 10:29 pm

@bruins0437 - Is there any issue with the present data for WAN Traffic?
I have empty boxes ( No Data).
 
bruins0437
newbie
Topic Author
Posts: 33
Joined: Thu Jul 13, 2017 4:30 am
Location: New Hampshire

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Thu May 04, 2023 4:37 am

@bruins0437 - Is there any issue with the present data for WAN Traffic?
I have empty boxes ( No Data).
Did you adjust the query for the interface that is your WAN? It doesn’t auto detect / select your WAN interface.
 
shiblysi
just joined
Posts: 1
Joined: Sun Aug 06, 2023 1:27 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Thu Aug 10, 2023 9:18 pm

@bruins0437 I am very new to this, so all I can do is copy-paste and cross my fingers that it works. I managed to work this out somewhat for my HEX lite.

I wanted to have a panel that shows data consumed per month for each interface, mainly the pppoe ones. Can you please help me by explaining the steps?

Thanks.
 
nemke
Member Candidate
Member Candidate
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Sat Oct 21, 2023 11:46 pm

Can't make it work. If I use module[mikrotik] state on prometeus is DOWN.
And don't see any param on Grafana

Any help ?
You do not have the required permissions to view the files attached to this post.
 
brg3466
Member Candidate
Member Candidate
Posts: 177
Joined: Sat Aug 01, 2015 7:29 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Wed Dec 06, 2023 4:37 am

Thank you for sharing ! I followed your tutorial and got it working on Ubuntu server.
 
lukmansincay
just joined
Posts: 1
Joined: Thu Jan 04, 2024 5:53 am

Re: [GUIDE] Grafana, Prometheus, and snmp_exporter

Thu Jan 04, 2024 8:24 am

Its awesome tools!
But i have a question and can not find it in the other forums,
if I want to monitor the latency from mikrotik to specific destination using grafana and prometheus, is there any tools regarding this?

by example, if I have mikrotik A and I want to monitor latency from Mikrotik A to Google DNS, and I want to graph the average / loss latency using prometheus and grafana
is this possible?

Who is online

Users browsing this forum: mrvelous01, vkp and 34 guests