Warning
This exporter is under development, use with caution.
A Prometheus exporter for MikroTik RouterOS devices.
This exporter connects to MikroTik routers using the native API (via the go-routeros/routeros library) and exposes metrics for monitoring with Prometheus.
- Collects metrics for:
- System Resources (CPU, Memory, Storage, Uptime, Board Info) - Always Enabled
- System Health (Current and power consumption, fan speed and temperature) - Always Enabledx
- Interface Statistics (Traffic, Packets, Errors, Drops) - Always Enabled
- PPP and PPPoE interfaces are automatically excluded from interface statistics
- BGP Peer Status (State, Prefixes, Updates, Uptime) - Optional
- Active PPP Users (Count, User Info, Uptime) - Optional
- Exposes metrics via HTTP on
/metrics(default port 9483) - Target router and optional metric collection are specified via scrape configuration in Prometheus (using URL parameters)
- Exporter health metrics (
mikrotik_up,mikrotik_scrape_duration_seconds,mikrotik_last_scrape_error) - Always Enabled - Configurable listen address, metrics path, and scrape timeout via command-line flags
- Graceful shutdown handling
- Go 1.24+ required
- MikroTik RouterOS v6.48 or later (tested with both v6.x and v7.x API features)
- A dedicated read-only user on the MikroTik router for the exporter
-
RouterOS 7.x:
- Uses the newer API path (
/routing/bgp/peer/print) for BGP data collection - BGP peer uptime is available in the
uptimefield - Standard field names are used for BGP metrics and interface statistics
- Uses the newer API path (
-
RouterOS 6.x:
- Uses the older API path (
/ip/bgp/peer/print) for BGP data collection - In RouterOS 6.48, BGP peer uptime might be in the
established-forfield instead ofuptime - Field names for BGP metrics and interface statistics might be different in RouterOS 6.48
- The exporter tries multiple possible field names for each metric to find the correct one
- Multiple fallback methods for interface statistics collection:
- First tries
/interface/monitor-trafficwith all interfaces - If that fails, tries
/interface/print stats - If that fails, tries
/interface/ethernet/print stats - If that fails, tries to monitor each interface individually
- First tries
- Debug logging is available to identify which fields and methods are being used
- Uses the older API path (
The exporter automatically detects the RouterOS version and uses the appropriate API paths and field names for data collection. It also handles differences in field names and formats between RouterOS versions, making it compatible with both RouterOS 6.x and 7.x.
go build -o ros-exporter ./cmd/ros-exporter./ros-exporter [flags]Flags:
-web.listen-address: Address to listen on (default::9483).-web.telemetry-path: Path for metrics endpoint (default:/metrics).-scrape.timeout: Timeout for scraping a target router (default:10s).
To test base system go the exporter URL and add example target http://<exporter-address>:9483/metrics?target=<router-address>.
To test optional feature, add the parameter feature=true to URL parameter. In example of collect_wireless: http://<exporter-address>:9483/metrics?target=<router-address>&collect_wireless=true
Create a read-only user group and user on your MikroTik router:
/user group add name=prometheus policy=read,api
/user add name=prometheus group=prometheus password=YOUR_STRONG_PASSWORD address=EXPORTER_IP_ADDRESS
Additionally there might be also a need to update ip services to allow access to API from EXPORTER_IP_ADDRESS. Print current API service configuration and change it accordingly.
/ip services print
Important
Replace YOUR_STRONG_PASSWORD with a secure password and EXPORTER_IP_ADDRESS
with the IP address of the exporter itself.
Add the following job to your prometheus.yml:
scrape_configs:
- job_name: 'mikrotik'
scrape_interval: 1m
scrape_timeout: 50s # Should be slightly less than scrape_interval and greater than exporter's scrape.timeout
metrics_path: /metrics # Or your custom path if using -web.telemetry-path
static_configs:
- targets: ['192.168.88.1'] # Replace with your router IPs/hostnames
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9483 # Address of the ros-exporter itself
# Pass credentials via parameters. User defaults to 'prometheus' if omitted.
# Consider using Prometheus agent secrets management for production.
# - target_label: __param_user
# replacement: your_custom_user # Uncomment and set if not using default 'prometheus'
- target_label: __param_password
replacement: YOUR_STRONG_PASSWORD # Replace with the password set on the router
# Optionally specify the API port (defaults to 8728 if omitted)
# - target_label: __param_port
# replacement: 8729 # Example: Use non-standard port
# Optionally enable BGP and/or PPP metrics per target
# Add these blocks if you want to enable them for this job. Default is false.
# - target_label: __param_collect_bgp
# replacement: true
# - target_label: __param_collect_ppp
# replacement: trueExplanation:
targets: List your MikroTik router IPs/hostnames here.relabel_configs:- The first two rules take the router address from
targetsand set it as thetargetURL parameter (__param_target) for the exporter and also as theinstancelabel in Prometheus. - The third rule rewrites the scrape address (
__address__) to point to where yourros-exporteris running (e.g.,localhost:9483). - The
__param_userrule adds the username. If omitted, the exporter defaults toprometheus. - The
__param_passwordrule adds the password. Warning: Storing passwords directly inprometheus.ymlis insecure. Use appropriate secret management in production. - The optional
__param_portrule allows specifying a non-default API port (default is 8728). - The optional
__param_collect_bgpand__param_collect_ppprules enable collection of BGP and PPP metrics respectively (default isfalse).
- The first two rules take the router address from
Alternatively, using the params block (Prometheus v2.28+):
scrape_configs:
- job_name: 'mikrotik-params'
scrape_interval: 1m
scrape_timeout: 50s
metrics_path: /metrics # Or your custom path
params:
# user: ['your_custom_user'] # Optional: Defaults to 'prometheus' if omitted
password: ['YOUR_STRONG_PASSWORD'] # Required
# port: ['8729'] # Optional: Defaults to 8728 if omitted
collect_bgp: ['true'] # Optional: Enable BGP collection
collect_ppp: ['true'] # Optional: Enable PPP collection
static_configs:
- targets: ['192.168.88.1', '10.0.0.1'] # Router IPs/hostnames
relabel_configs:
- source_labels: [__address__]
target_label: __param_target # Set target parameter from address
- source_labels: [__param_target]
target_label: instance # Set instance label from target parameter
- target_label: __address__
replacement: localhost:9483 # Address of the ros-exporterNote
WIP
List the key metrics exposed:
mikrotik_upmikrotik_scrape_duration_secondsmikrotik_last_scrape_error- System metrics (e.g.,
mikrotik_system_cpu_load_percent,mikrotik_system_memory_usage_bytes) - Interface metrics (e.g.,
mikrotik_interface_receive_bytes_total) - BGP metrics (e.g.,
mikrotik_bgp_peer_state) - PPP metrics (e.g.,
mikrotik_ppp_active_users_count)
- Implement configuration via YAML/env vars
- Add better connection handling/pooling
- Debug mode
- Add unit/integration tests
- Add developer example how to implement metrics collection
- feature: transceivers signal and temperature
- feature: OSPF
- feature: wireless interfaces client count, tx and rx rate, ccq, noice floor and frequency
- fix: add Interface speed to mikrotik_interface_
- fix: add hostname as name to mikrotik_system_info labels