Community discussions

MikroTik App
 
survtechke
just joined
Topic Author
Posts: 1
Joined: Sat Jul 29, 2017 12:04 pm

Saving Mikrotik Simple Queue Statistic PHP API

Sat Jul 29, 2017 12:12 pm

I want to save the statistics of the Mikrotik /simple queue using the PHP API. I have been able to pull the data but seems my implementation on the PHP side is a problem. The following is the code and the resulting array object.

Code: Select all

foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
// $lasArray = $queueEntry;
print_r($queueEntry);
}
Excerpt for Result since its returning for all users in the office, I have choosen just to display for one user. Take it that PEAR2\Net\RouterOS\Response Object is retuned for all users, i.e all in this case over 50 users. I would like to save this data to database but only the relevant ones like
[.id], [name], [target], [limit-at], [max-limit] and [bytes],
any assistance here would be highly regarded.

Code: Select all

PEAR2\Net\RouterOS\Response Object
(
[unrecognizedWords:protected] => Array
(
)

[_type:PEAR2\Net\RouterOS\Response:private] => !re
[attributes:protected] => Array
(
[.id] => *12
[name] => GikundaPhone
[target] => 192.168.1.108/32
[parent] => none
[packet-marks] =>
[priority] => 8/8
[queue] => default-small/default-small
[limit-at] => 128000/384000
[max-limit] => 384000/384000
[burst-limit] => 0/0
[burst-threshold] => 0/0
[burst-time] => 0s/0s
[bucket-size] => 0.1/0.1
[bytes] => 16515474/129310087
[total-bytes] => 0
[packets] => 127812/133712
[total-packets] => 0
[dropped] => 76/8667
[total-dropped] => 0
[rate] => 0/0
[total-rate] => 0
[packet-rate] => 0/0
[total-packet-rate] => 0
[queued-packets] => 0/0
[total-queued-packets] => 0
[queued-bytes] => 0/0
[total-queued-bytes] => 0
[invalid] => false
[dynamic] => false
[disabled] => false
)

[_tag:PEAR2\Net\RouterOS\Message:private] =>
)
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Saving Mikrotik Simple Queue Statistic PHP API

Sat Jul 29, 2017 7:03 pm

If the properties you want to save are already there, you can extract them with the getProperty() method, or __invoke(), i.e.
echo $queueEntry('name');
//same as
echo $queueEntry->getProperty('name'); 
Also, you can let the router give you only those properties, to minimize the input and be able to just loop through the properties, e.g.
foreach ($util->setMenu('/queue simple')->getAll(array('.proplist' => '.id,name,target,limit-at,max-limit,bytes')) as $queueEntry) {
print_r($queueEntry);
foreach ($queueEntry as $propName => $propValue) {
//form DB query here
}
} 
 
User avatar
manuzoli
Frequent Visitor
Frequent Visitor
Posts: 90
Joined: Mon Oct 03, 2016 6:47 pm

Re: Saving Mikrotik Simple Queue Statistic PHP API

Fri Oct 06, 2017 8:16 pm

I am working on quite the same. Maybe this will help you. Let me know what you think.

https://github.com/manuzoli/mikrostats

Who is online

Users browsing this forum: No registered users and 61 guests