Giter Site home page Giter Site logo

mikrotik_monitoring's Introduction

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 apt 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.

mikrotik_monitoring's People

Contributors

m0r13n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mikrotik_monitoring's Issues

Wireless interface

Hi, i just tried to lunch monitoring for my home system, and in wireless monitoring i am missing W60G interface.. in Mikrotik it's showing in wireless interfaces.. and configuration is very similar for regular wifi.. so maybe its possible quick add for that?

mikrotik_exporter:9436

prometheus/prometheus.yml

I see this host being asked for in DNS, but I don't see anything listening in any of the containers.. should it be?

but I do see 49090

docker exec -it mikrotik-mktxp netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 127.0.0.11:42195        0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:49090           0.0.0.0:*               LISTEN      
tcp        0      0 172.18.0.3:49090        172.18.0.5:43912        TIME_WAIT   
tcp        0      0 172.18.0.3:52014        192.168.88.1:8728       ESTABLISHED 
tcp        0      0 172.18.0.3:49090        172.18.0.5:35862        TIME_WAIT   
tcp        0      0 172.18.0.3:49090        172.18.0.5:37194        TIME_WAIT   
tcp        0      0 172.18.0.3:49090        172.18.0.5:58176        TIME_WAIT   
udp        0      0 127.0.0.11:51610        0.0.0.0:*                           
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node Path

(hope this makes sense..)

Thank you in advance.

Grafana exits prematurely

Grafana exists with code 1:

grafana                      | Error: โœ— 
grafana                      | <html><head>
grafana                      | <meta http-equiv="content-type" content="text/html;charset=utf-8">
grafana                      | <title>403 Forbidden</title>
grafana                      | </head>
grafana                      | <body text=#000000 bgcolor=#ffffff>
grafana                      | <h1>Error: Forbidden</h1>
grafana                      | <h2>Your client does not have permission to get URL <code>/api/plugins/repo/flant-statusmap-panel</code> from this server.</h2>
grafana                      | <h2></h2>
grafana                      | </body></html>
grafana                      |  (Grafana v9.3.2 linux-arm64)

If running Grafana without plug-in it start without any problems.
Any ideas what can be the cause? Unfortunately run out of any further ideas...

some principal question about this project

Hi Leon,
I am currently browsing the internet for a good visualisation to monitor my MTs (10x units) and came across your site (among others).
May I ask a few questions about why you started your own project as there is a similar project and so on?

  1. have you considered using: https://github.com/IgorKha/Grafana-Mikrotik?
    (I know that https://grafana.com/grafana/dashboards/?search=mikrotik does not show that much useful)
  2. for what purpose do you use the REST API as it would require opening the Firewall if the Raspi is not in the same VLAN as the MTs (my case)
  3. why you don't use the official SNMP exporter https://github.com/prometheus/snmp_exporter?
  4. Have you ever used The Dude as I start with as that is familiar for the MT vendors?
    Going your way is the cherry on the cream :).
  5. Have you tried to implement the syslog as well, see https://grafana.com/blog/2021/03/23/how-i-fell-in-love-with-logs-thanks-to-grafana-loki?
  6. (going via Zabbix, I cannot find the website anymore but https://twitter.com/alexanderzobnin/status/841631679064227840?lang=en and https://github.com/alexanderzobnin/grafana-zabbix)

thank you
stefan

Connections

It would be nice to show the number of connections over time

Not pulling any data

Hello,

I have a MikroTik CCR2216 (new flagship) and followed your tutorial to a perfect "T".

I have an outside VPS with a static IP pointed to the router IP (I can login over Winbox with the account on a netbook with 5G) so I know that is correct (the hostname, and user/password).

UFW is disabled on my Ubuntu install running just your docker clone.

Only changes I made to your config was:

enabled = True
hostname

username
password

Nothing else was changed but I just do not receive any data on your dashboard. Any help would be appreciated! The FAQ didn't help in this instance.

CCR2216 is on 7.6

Multiple Nodes

How can I add multiple node in config file? I added one but not wokring

Request features.

There are no Queues features and also no maxmimum, minimum and avarage bandwidth and traffic consumtion, it will great if you add it.

Thank you.

Internet Latency and Internet Bandwidth graphs question

Hi,
I've got it running, thanks. However I can't find anything about Internet Latency settings. It is taking measures from something but I can't figure it what IP it is being used and if it is possible to change it?

Very similar question regarding the Internet Bandwidth graph it looks like it is constantly measure it but I can't see this in my Mikrotik traffic. How this works?

Option to disable speedtest

I noticed every 7 minutes that a good amount of traffic was outbound to 184.182.243.193:8080 coming from the monitoring container. Upon resolving, this was to an Ookla server (no idea if this is hosted by Ookla themselves, but returns a Cox owned IP), so I'm guessing this is the speedtest to show bandwidth in the grafana dashboard. Would be nice to be able to turn this off as it may impact online gaming and really not useful info (have no idea the geographic location of this address). For now I can just block this address outbound, though.

Multiple node

how to add multiple nodes? will this feature be available in the future?

Latency

By default added 3 ips to check those ips latency, but I need more ip to add and check latency. How can I add?

Adding additional Nodes

Hi

I am trying to add a additional 3 routers to the config file.

Do I just add the additional router addresses below the IP address field.

Or do I need to copy the entire config and paste that below the original one with the different IP address of the other router?

I have currently tried both and no data is showing when i do so?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.