[PHP] Realtime Traffic Graph on interfaces

Hello.

In our PHP application, I wanna show a live traffic graph of interfaces and so far here’s what I’ve come up with:
I run this query every second on the router:

/interface/monitor-traffic <pppoe-queue_name>

And I use JavaScript to render and update my graph every second:
Selection_1967.png
Now I have a concern with efficiency of this approach. There are a couple of issues that I’m aware of.

  • First of all, if the pppoe client is offline the interface is down and we can’t query the monitor traffic.
  • The API might take a long time to respond.
  • The high load on the router

So I was wondering, what are some better ways to handle this live graphs? I would appreciate any comment that would put me in the right direction.

Thank you very much in advance.

Depends on what you what to archive. How small you want your/accept your intervals to be.

You could look into using MQTT for this (push model).

Run a script on the MT device every which published the current up/down values to MQTT topic(s).

Then have your service subscribe to the topics on your MQTT broker.

And render the graph from the received MQTT messages.

https://help.mikrotik.com/docs/display/ROS/MQTT

https://en.wikipedia.org/wiki/MQTT

https://en.wikipedia.org/wiki/Comparison_of_MQTT_implementations