Community discussions

MikroTik App
 
codi639
just joined
Topic Author
Posts: 13
Joined: Mon Jan 15, 2024 1:41 pm
Location: France

Monitoring bandwidth by sending tx and rx bytes

Wed Feb 14, 2024 6:15 pm

Hello guys, it might be a little bit complicated to help me since I don't know the problem.
I've built a script which send the tx-bytes and rx-bytes for each interfaces to a remote php web server. The server then do some transformation/calculations on it to use them with Grafana for monitoring.
The script:
:local interfaces [/interface find];
:local interfaceName "LoopBr"  ;
:local routerIP [ip address get [find interface=$interfaceName] address];
:put ("Router IP: " . $routerIP);

:local tx;
:local rx;
#:put $interfaces;
:foreach interface in=$interfaces do={
    :local intName [/interface get $interface name];
    #:put ("Debug: " . $intName);
    :put ("Interface: " . $intName);

    :local softTx ([/interface get [find name=$intName] tx-byte]);
    :local softRx ([/interface get [find name=$intName] rx-byte]);

    #:set tx ($tx + $softTx);
    #:set rx ($rx + $softRx);

    :local data ("routerIP=" . $routerIP . "&intName=" . $intName . "&tx=" . $softTx . "&rx=" . $softRx);

    :local response [/tool fetch url="http://172.16.20.41/receiver_data.php" http-method=post http-data=$data as-value];
    :put ("sending data from interface: " . $intName);
    :put ($response->"data");
    :delay 1000ms;
    #:put $tx;
    #:put $rx;
};
when I run the script, because of the debug statement I've set, I can see that it is sending everything, for example:
Interface: ether1-10.144
sending data from interface: ether1-10.144

Interface: ether2-172.16.20
sending data from interface: ether2-172.16.20

Interface: ether3-ONT
sending data from interface: ether3-ONT

Interface: ether4-TR
sending data from interface: ether4-TR

Interface: ether5-TR
sending data from interface: ether5-TR

Interface: ether6-TR
sending data from interface: ether6-TR

Interface: ether7-TR
sending data from interface: ether7-TR
Thinking about the fact that it could be the server which could not send the different value to the database quickly enough, I add a delay (first it was at 4s). But whatever I'm doing I don't see every interface on my base, and always the same one's.
Such as:
| 10.211.0.11 | ether12-PiMGMT |
| 10.211.0.11 | LoopBr |
| 10.211.0.11 | TE-0002 |
| 10.211.0.11 | TE-0003 |
| 10.211.0.11 | TE-0004 |
| 10.211.0.11 | TE-0005 |
The problem might be from my web server, but since there's no error logs I can't see anything... I can provide some parts of the php code if needed.

Any idea is very welcome.
Last edited by codi639 on Thu Feb 15, 2024 4:39 pm, edited 1 time in total.
 
User avatar
patrikg
Member Candidate
Member Candidate
Posts: 262
Joined: Thu Feb 07, 2013 6:38 pm
Location: Stockholm, Sweden

Re: Sending tx and rx to a php server

Wed Feb 14, 2024 7:32 pm

Why go the script way of doing this ?
I think it should be lots easier to go to the snmp way to monitor the traffic.
 
codi639
just joined
Topic Author
Posts: 13
Joined: Mon Jan 15, 2024 1:41 pm
Location: France

Re: Sending tx and rx to a php server

Thu Feb 15, 2024 9:41 am

I'm using SNMP for everything else. But I haven't found a way to calculate correct bandwidth over the time I want, since InfluxDB queries are limited.
Last edited by codi639 on Thu Feb 15, 2024 4:46 pm, edited 1 time in total.
 
codi639
just joined
Topic Author
Posts: 13
Joined: Mon Jan 15, 2024 1:41 pm
Location: France

Re: Sending tx and rx to a php server  [SOLVED]

Thu Feb 15, 2024 10:44 am

The problem does not come from the router, I've been able to check the database entry logs and I can see my tx rx, but not in the base.
Just saying: tx an rx bytes are very large numbers, INT type for a database might not support it (it was my case)... You can instead choose BIGINT type for your column.
I'm closing this issue.

Who is online

Users browsing this forum: No registered users and 8 guests