A brief introduction:
MikroTik (officially SIA "Mikrotīkls") is a Latvian network equipment manufacturer. The company develops and sells wired and wireless network routers, network switches, access points, as well as operating systems and auxiliary software. The company was founded in 1996 with the focus of selling equipment in emerging markets.
Prometheus is an open-source monitoring system used for event monitoring and alerting. It records real-time metrics in a time series database built using a HTTP pull model, with flexible queries and real-time alerting.
Grafana is a multi-platform open source analytics and interactive visualization software available since 2014. It provides charts, graphs, and alerts for the web when connected to supported data sources. It is expandable through a plug-in system.
What you need:
1, Mikrotik routers (x86/CHR are also supported).
2, Local virtual machine or a remote vps running linux(recommend Debian 9/10).
3, SSH client and a little knowledge about linux command.
Let’s begin:
1, Log in mikrotik in winbox or from ssh client.
Create a user on the device that has API and read-only access.
/user group add name=prometheus policy=api,read,winbox
Create the user to access the API via.
/user add name=prometheus group=prometheus password=#changeme#
2, Log in your linux server
ssh root@ip -p 22(or you assigned)
sudo apt update
sudo apt upgrade
Install grafana
sudo apt -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates
sudo apt-get install -y gnupg2 curl software-properties-common
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt-get update
sudo apt-get -y install grafana
You should be able to access to grafana by http://your-server-ip:3000.
Install Prometheus
Create a group for prometheus
sudo groupadd --system prometheus
Create a user for prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Create a directory
sudo mkdir /var/lib/prometheus
For sub-directories
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
sudo apt update
Install curl and wget if the system is very clean
sudo apt -y install wget curl
Download 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/
Add prometheus to systemd to make it start with system boot
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
Change directories 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
sudo chown -R prometheus:prometheus /var/lib/prometheus/
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
You should be able to access to prometheus http://your-server-ip:9090.