Have an installed, updated Ubuntu 18.04 or newer (preferably 22.04).
Prep for Prometheus install:
Code: Select all
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.