• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language Makefile
  • License
    MIT License
  • Created over 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Monitor your Mikrotik router with Prometheus and Grafana

Monitor your Mikrotik router with Prometheus and Grafana

Use Grafana & Prometheus to monitor Mikrotik devices. This projects serves as a ready to use blueprint for monitoring based on Docker. It is designed and tested to be run on Raspberry Pis.

Features

  • System Health Monitoring
    • disk usage
    • CPU load
    • memory usage
    • public IP address (IPv4 & IPv6)
    • system uptime
    • temperature
    • voltage monitoring
  • Interface Monitoring
    • traffic (bit/s)
    • traffic (packets/s)
    • per interface graphs
  • Latency Monitoring
    • customizable ICMP and/or UDP pings
    • packet loss
  • DHCP Monitoring
    • active leases
    • MAC addresses, host names, addresses
  • Network Monitoring
    • routes
    • interfaces errors
    • interface states
    • PoE states
  • Firewall Monitoring
    • rules traffic
    • logged rules traffic
    • Ipv4 & IPv6
    • bandwidth
    • active users
  • Wireless Monitoring
    • noise floor
    • TxCCQ
    • client devices
    • number of clients
    • traffic
    • signal strength
    • signal to noise ratio
  • Netwatch
  • CAPsMAN Monitoring
    • remote CAPS
    • registrations
    • clients
    • frequencies
    • signal strength
    • traffic

Setup

  • Router running RouterOS 7.x.x
  • Raspberry Pi 4 with 2 gb RAM (other PIs may also work, but I wanted ARM 64 bit)
  • before opening a new issue, please take a look at the FAQ

Demo pictures

General system stats

Show more images

Network Latency Netwatch Firewall WiFi Interfaces

Installation

Mikrotik Router

At first you need to prepare your router.

Create a group on the device that has API and read-only access:

/user group add name=prometheus policy=api,read,winbox,test

Create a user that is part of the group:

/user add name=prometheus group=prometheus password=TOP_SECRET

Prepare Raspi

You need Ubuntu Server for ARM 64 bit in order to use this setup. You may also use Raspian, but then you are limited to 32bit ARM executables. This would mean, that you need to compile the mikrotik-exporter by hand, because there are no pre built 32-bit Docker images.

You need to execute the following steps on the target machine itself (e.g. Raspberry Pi).

Install Python and pip:

sudo apt install python3-dev python3 python3-pip -y

Install Docker + Docker-compose (reboot required)

curl -sSL https://get.docker.com | sh
sudo usermod -aG docker ubuntu
sudo pip3 install docker-compose
sudo systemctl enable docker
sudo reboot
Optional: Build the Docker Image for mktxp

It might be necessary to build the Docker Image for: https://github.com/akpw/mktxp. This is especially the case, if your architecture is not:

  • linux/amd64
  • linux/arm/v7
  • linux/arm64
# Get the mktxp repository
git clone https://github.com/akpw/mktxp.git

# Go into the newly downloaded repo
cd mktxp

# Build the docker image
docker build . -t leonmorten/mktxp:latest

Now get this repo and install all services:

# Clone this repo
git clone https://github.com/M0r13n/mikrotik_monitoring.git


# Go into the cloned directory
cd mikrotik_monitoring

# Let docker-compose do it's job
docker-compose up -d

You may need to adjust the following configuration files and add your own credentials for your router:

  • mktxp/mktxp.conf

Done. You should now be able to open the Grafana dashboard on Port 3000 of your Raspberry Pi.

Latency Monitoring

This projects uses the Prometheus Blackbox exporter to measure network latency. By default three targets are configured:

  • 1.1.1.1 (Cloudflare)
  • 8.8.8.8 (Google)
  • 9.9.9.9 (IBM)

You may adjust blackbox/blackbox.yml according to your needs.

Multiple Nodes

It is possible to monitor multiple (Mikrotik) devices. Just change add as many devices to mktxp/mktxp.conf as you want.

HTTPS

It is also possible to access the Grafana Dashboard over HTTPS. Depending on your security requirements and/or threat model it might be a good idea to enable HTTPS.

Generate a self signed certificate for your domain:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./nginx/nginx-selfsigned.key -out ./nginx/nginx-selfsigned.crt

Replace the content of ./nginx/nginx.conf with:

server {
  listen 80;
	listen [::]:80;
	server_name _;
	return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  include ssl/self-signed.conf;

  location / {
   proxy_set_header Host $http_host; 
   proxy_pass http://grafana:3000/;
  }
}

AppArmor

Under ./docker-armor you can find an AppArmor profile for this stack. To use it, do the following:

cp ./docker-armor /etc/apparmor.d/docker-armor
apparmor_parser -r -W /etc/apparmor.d/docker-armor
docker-compose -f docker-compose-armored.yml  up -d

Resources

FAQ

Why are my graphs empty?

It might happen that the Grafana dashboard loads, but the graphs remain empty. If the dashboard loads, but no data is shown, this may be caused by any of the following reasons:

  • invalid credentials for the monitored RouterOS device
    • verify with: /user/print detail
  • invalid host and port for the monitored RouterOS device
    • check that the IP or host name of the monitored device is correct
  • API service disabled on the RouterOS device
    • verify with /ip/service/print detail

What distinguishes this project from other similar projects?

This project is only a personal hobby. It do it mainly to learn something and to improve my skills. Therefore, the project does not compete with other projects. Nor do I aim for completeness or perfection. The goal of this project is to develop a monitoring solution for multiple RouterOS devices simultaneously that is resource-efficient and scalable.

Why you don't use the SNMP for monitoring?

Firstly SNMP based monitoring is painfully slow. In my experience SNMP walks are slow and CPU heavy. And I am not alone with this. In my experience the API is much faster and produces less stress on the CPU of the monitored device.

Secondly I never really got used to the way that SNMP metrics and queries are structured. I find them very hard to read.

In addition, the API offers a lot of flexibility. Any command can be executed on RouterOS via the API. Thus it is possible to collect complex metrics.

I get a PermissionError when running docker-compose up

When bind-mounting a directory from the host into a container, files and directories maintain the permissions they have on the host. These can not be changed by Docker. Typically, a bind-mounted directory has permissions like these: rwxrwxr-x. This means that the container can read from the bind-mounted directory. But it can not write or modify the mounted files.

This mostly works fine. But the Prometheus exporter mktxp has a specialty: It may update it's configuration if some keys are missing from the configuration file. Imagine, that the key ipv6_firewall is missing from the mktxp.conf. In this case mktxp will add ipv6_firewall=false to the configuration file instead of failing. This is a helpful feature, but can cause the container to crash, if the user inside the container lacks write permissions.

In order to resolve this issue, make sure that all keys that mktxp currently supports are listed in your mktxp.conf file.

More Repositories

1

pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
Python
153
star
2

socket-chess

A chess game based on Spring using Websockets
Java
5
star
3

battleships

A simple battleship game implemented in less than 500 lines of Python.
Python
5
star
4

chess

A chess model written in Python
Python
4
star
5

shelly

A simple shell written in C. Supports Chains, Pipes and Redirects.
C
4
star
6

Smartphoniker-shop

[WIP] Work in Progress
Python
3
star
7

mktvis

A straightforward Python module to export and visualize open connections from any Mikrotik RouterOS device.
Python
3
star
8

terminal

A web based terminal that executes commands inside a docker container.
JavaScript
2
star
9

price_picker

A landing page / price overview for repairshops.
Python
2
star
10

py-vigil-reporter

Vigil Reporter module for Python 3.
Python
2
star
11

cs50_final

A Jpeg to ASCII Converter as my final project for CS50.
Python
1
star
12

related

Nested Object Models in Python with dictionary, YAML, and JSON transformation support
Python
1
star
13

python-gitlab-reporter

A custom exception handler that can be used to (re)open issues on Gitlab for projects written in Python.
Python
1
star
14

kiosk

A simple kiosk site that we use to show some information to customers.
JavaScript
1
star
15

ascii_converter

Convert a image to ASCII-Art.
Python
1
star
16

py-raider-reporter

Raider Reporter module for Python 3.
Python
1
star
17

homie

Super simple single static site that gives you an overview of all of your services.
Python
1
star
18

CSV2VCF

Python Script for converting .csv contact files to .vcf.
Python
1
star
19

ideen

Python
1
star
20

mac-os-alt-gr

US International Keyboard Layout with Alt/Option as dead key
1
star