Network bandwidth monitoring - CHR router os

Hi,
I’d like to know if it is possible to have a bandwidth management like Unifi .
I’m using a routerOs by mikrotik.

Welcome @gianry to the Grafana Community Forum.

Yes, Grafana can monitor bandwidth usage from your MikroTik router, similar to Unifi, by collecting network traffic data. I would suggest creating instances of Prometheus or InfluxDB+Telegraf if you have not done so already.

Here’s a rough outline of how you can achieve this using Telegraf, InfluxDB, and Grafana. Here’s how:

Step 1: Enable SNMP on MikroTik

  1. Log into your MikroTik router and enable SNMP:
/snmp set enabled=yes
  1. You can also specify a community (e.g., “public”):
/snmp community add name=public addresses=0.0.0.0/0

Step 2: Install and Configure Telegraf

Telegraf will collect SNMP data from MikroTik and send it to InfluxDB.

  1. Install Telegraf on your monitoring system.
  2. Edit the Telegraf configuration file (telegraf.conf):
[[inputs.snmp]]
  agents = ["udp://192.168.88.1:161"]  # Replace with your router's IP
  community = "public"
  version = 2
  timeout = "5s"
  retries = 3

[[inputs.snmp.field]]
  name = "interface_in_octets"
  oid = "IF-MIB::ifInOctets.1"
[[inputs.snmp.field]]
  name = "interface_out_octets"
  oid = "IF-MIB::ifOutOctets.1"
  1. Restart Telegraf:
systemctl restart telegraf

Step 3: Store Data in InfluxDB

  1. Ensure you have InfluxDB installed and running.
  2. Telegraf will automatically send SNMP data to InfluxDB.

Step 4: Visualize Data in Grafana

  1. Add InfluxDB as a data source in Grafana.
  2. Create a new dashboard and use the following Flux query to visualize bandwidth:
from(bucket: "telegraf")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "snmp")
  |> filter(fn: (r) => r._field == "interface_in_octets" or r._field == "interface_out_octets")
  1. Use time-based transformations to calculate bandwidth usage (convert octets to Mbps).

This setup will allow you to monitor bandwidth usage in real time with historical data, much like Unifi.

1 Like

@grant2
I’ve very happy to use Grafana and I appreciate your help.
now I’ve a mini pc with debian and CasaOs. I’ve installed Grafana and prometheus but I didn’t found a solution . I think I’ll go to use Telegraf and influxDB.

By the way … do you know the way to collect data for the traffic identification ? like in the unifi dashboard I’ve mentioned up ?

thanks a lot

Have you configured Prometheus to scrape your network traffic? Can you share your prom config?

Other options

where is the prom config ?

At this point I’ve found this

root@casaos:/home/casaos# systemctl restart telegraf
Job for telegraf.service failed because the control process exited with error code.
See "systemctl status telegraf.service" and "journalctl -xe" for details.

root@casaos:/home/casaos# systemctl status telegraf.service
● telegraf.service - Telegraf
     Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2025-02-09 12:37:20 EST; 17s ago
       Docs: https://github.com/influxdata/telegraf
    Process: 288712 ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-director>
   Main PID: 288712 (code=exited, status=1/FAILURE)
        CPU: 248ms

Feb 09 12:37:20 casaos systemd[1]: telegraf.service: Failed with result 'exit-code'.
Feb 09 12:37:20 casaos systemd[1]: Failed to start Telegraf.
Feb 09 12:37:20 casaos systemd[1]: telegraf.service: Scheduled restart job, restart counter is at 5.
Feb 09 12:37:20 casaos systemd[1]: Stopped Telegraf.
Feb 09 12:37:20 casaos systemd[1]: telegraf.service: Start request repeated too quickly.
Feb 09 12:37:20 casaos systemd[1]: telegraf.service: Failed with result 'exit-code'.
Feb 09 12:37:20 casaos systemd[1]: Failed to start Telegraf.
...skipping...

For now maybe you can try out telegram as recommended by @grant2

ok but as you can see telegraf doesn’t start

Did you follow the docs?

Can you share how you configured telegraf

I’ve installed using Install from the InfluxData repository

and I received this error

systemctl restart telegraf

Job for telegraf.service failed because the control process exited with error code.

See "systemctl status telegraf.service" and "journalctl -xe" for details.

@grant2

is it necessary to change this too?

  ## Token for authentication.
  token = "$INFLUX_TOKEN"

Best to read doc

Ok,
I read but I asked something else. Is it necessary to change the telegraf conf at the point as on my previous screenshot ?

this is the debug result … I 've followed the instructions wrote yesterday:

Feb 10 16:19:16 CasaOS systemd[1]: telegraf.service: Scheduled restart job, restart counter is at 5.
Feb 10 16:19:16 CasaOS systemd[1]: Stopped Telegraf.
Feb 10 16:19:16 CasaOS systemd[1]: telegraf.service: Start request repeated too quickly.
Feb 10 16:19:16 CasaOS systemd[1]: telegraf.service: Failed with result 'exit-code'.
Feb 10 16:19:16 CasaOS systemd[1]: Failed to start Telegraf.
root@CasaOS:/home/casaos# telegraf --config telegraf.conf --test
2025-02-10T21:20:15Z I! Loading config: telegraf.conf
2025-02-10T21:20:15Z E! loading config file telegraf.conf failed: open telegraf.conf: no such file or directory
root@CasaOS:/home/casaos# telegraf --config /etc/telegraf/telegraf.conf --test
2025-02-10T21:20:56Z I! Loading config: /etc/telegraf/telegraf.conf
2025-02-10T21:20:56Z I! Starting Telegraf 1.33.1 brought to you by InfluxData the makers of InfluxDB
2025-02-10T21:20:56Z I! Available plugins: 236 inputs, 9 aggregators, 33 processors, 26 parsers, 63 outputs, 6 secret-stores
2025-02-10T21:20:56Z I! Loaded inputs: snmp
2025-02-10T21:20:56Z I! Loaded aggregators:
2025-02-10T21:20:56Z I! Loaded processors:
2025-02-10T21:20:56Z I! Loaded secretstores:
2025-02-10T21:20:56Z W! Outputs are not used in testing mode!
2025-02-10T21:20:56Z I! Tags enabled: host=CasaOS
2025-02-10T21:20:56Z W! [agent] The default value of 'skip_processors_after_aggregators' will change to 'true' with Telegraf v1.40.0! If you need the current default behavior, please explicitly set the option to 'false'!
2025-02-10T21:20:56Z E! [telegraf] Error running agent: could not initialize input inputs.snmp: initializing table interface: translating: exec: "snmptranslate": executable file not found in $PATH

after a long night studying I realized that something missing - I had to snmp MIB plugin.
Now I’ve another issue . this is what I see in Grafana

what are we looking at here?

Grafana dashboard . I followed the instructions as in the first reply of this topic.
I’m not educated for such thing of tools. I asked how to replicate a Unifi dashboard and in other forum someone wrote to use Grafana.