When combined with grafana it can be a very powerful tool to visualize IT systems and routers statistics and to know about trends in a system over time.
I have created a container for Mikrotik RouterOS devices metric scrapping.
The sources are at:
https://github.com/elico/mikrotik-exporter-container
The exporter is based on the repository at:
https://github.com/nshttpd/mikrotik-exporter
An example of spinning a container:
Code: Select all
/interface/bridge/add name=dockers
/ip/address/add address=172.17.0.254/24 interface=dockers
/interface/veth/add name=veth5 address=172.17.0.5/24 gateway=172.17.0.254
/interface/bridge/port add bridge=dockers interface=veth5
/ip/firewall/filter/add chain=input protocol=tcp dst-port=8728 connection-state=new src-address=172.17.0.5 action=accept place-before=0
/container/config/set registry-url=https://registry-1.docker.io tmpdir=disk1/pull
/container/envs/add name=prom_exporter_envs key=TZ value="Asia/Jerusalem"
/container/envs/add name=prom_exporter_envs key=ROUTER_NAME value="RB4011"
/container/envs/add name=prom_exporter_envs key=ROUTER_ADDRESS value="172.17.0.254"
/container/envs/add name=prom_exporter_envs key=USER value="prometheus"
/container/envs/add name=prom_exporter_envs key=PASSWORD value="changeme"
/container/envs/add name=prom_exporter_envs key=PORT value="8728"
/container/envs/add name=prom_exporter_envs key=CONNTRACK_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=DHCP_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=DHCPL_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=FIRMWARE_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=HEALTH_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=ROUTES_METRICS value="1"
/container/envs/add name=prom_exporter_envs key=NETWATCH_METRICS value="1"
/container/add dns=172.17.0.254 remote-image=elicro/mikrotik-exporter:latest interface=veth5 root-dir=disk1/mt-exporter envlist=prom_exporter_envs start-on-boot=yes
Code: Select all
/user group add name=prometheus policy=api,read,winbox
/user add name=prometheus group=prometheus password=changeme
so in the case you will want to access/scrap it you would need to access the target:
172.17.0.5:9436
ie:
http://172.17.0.5:9436/metrics
The container is based on alpine linux to allow the option of debugging in shell if needed.
The exporter is written to handle two scenarios:
to export a single system or more then one system.
It can be a very powerfull tool if used properly.
The container contains a default config file at: /config/config.yaml
https://github.com/elico/mikrotik-expor ... onfig.yaml
If you wish to use your customized config.yaml file to export more then one system or for any other reason you can use a mount directory for that.
The mount directory inside the container is: /config
and it should contain two files:
/config/config.yaml
/config/custom
The file: /config/custom
is being used to instruct the container to spin with the plain configuration and to not transform the container default config.yaml which is really a single node template.
An example for multi RouterOS devices scrapping via a single config file can be seen here:
https://github.com/nshttpd/mikrotik-exp ... g.test.yml
By default all special metrics are disabled unless enabled using environment variable.
The start script with all the available variables can be seen at:
https://github.com/elico/mikrotik-expor ... r/start.sh
The exporter features can be seen at the sources config file at:
https://github.com/nshttpd/mikrotik-exp ... fig.go#L13
To enable a specific metric you need to set the variable with any value, ie not empty like:
Code: Select all
/container/envs/add name=prom_exporter_envs key=CONNTRACK_METRICS value="1"
So for example the feature name for wireless interfaces metrics is listed at:
https://github.com/nshttpd/mikrotik-exp ... fig.go#L28
and is: wlanif
So to enable the wireless interface metrics exporting you would need to define the next key value
Code: Select all
/container/envs/add name=prom_exporter_envs key=WLANIF_METRICS value="1"
Just pay attention that this and other Prometheus exporters do not support authentication and as long they are not firewalled with strict rules anyone can get these metrics, so be aware of what you are running.
I have not tried to run Prometheus on-top of a RouterOS device but I assume that it's possible as well.