保存 Mikrotik 简单队列统计 PHP API
Saving Mikrotik Simple Queue Statistic PHP API
我想使用 PHP API 保存 Mikrotik /simple queue
的统计数据。我已经能够提取数据,但似乎我在 PHP 方面的实施存在问题。以下是代码和生成的数组对象。
foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
// $lasArray = $queueEntry;
print_r($queueEntry);
}
结果摘录自为办公室中的所有用户返回以来,我选择只为一个用户显示。假定 PEAR2\Net\RouterOS\Response Object
为所有用户重新调整,即在这种情况下所有超过 50 个用户。我想将这些数据保存到数据库中,但只有相关的数据,如 [.id], [name], [target], [limit-at], [max-limit] and [bytes]
,这里的任何帮助都将受到高度重视。
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] =>
)
找到并回答了我自己的问题。这就是我所做的。
foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
// $lasArray = $queueEntry;
print_r($queueEntry);
}
提供了很多不必要的信息,所以我发现 routeros_api.class.php
可以从 here and followed but modified information from here 下载。然后就用了
$address = 'IPV4_Address_of_router';
$user = 'username_of_router';
$pass = 'password_of_router';
require('routeros_api.class.php');
$API = new routeros_api();
$API->debug = false;
// router credentials and after including the routeros_api.cass.php
if ($API->connect($address, $user, $pass)) {
$results = $API->comm("/queue/simple/print");
foreach ($results as $row) {
$clientName = $row['name'];
$clientIP = $row['target'];
$clientMaxDown = $row['limit-at'];
$clientMaxUp = $row['max-limit'];
$clientDownloads = $row['bytes'];
}
}
唯一剩下的就是保存到数据库,这很简单。也许有一天有人会因此得到帮助。
我想使用 PHP API 保存 Mikrotik /simple queue
的统计数据。我已经能够提取数据,但似乎我在 PHP 方面的实施存在问题。以下是代码和生成的数组对象。
foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
// $lasArray = $queueEntry;
print_r($queueEntry);
}
结果摘录自为办公室中的所有用户返回以来,我选择只为一个用户显示。假定 PEAR2\Net\RouterOS\Response Object
为所有用户重新调整,即在这种情况下所有超过 50 个用户。我想将这些数据保存到数据库中,但只有相关的数据,如 [.id], [name], [target], [limit-at], [max-limit] and [bytes]
,这里的任何帮助都将受到高度重视。
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] =>
)
找到并回答了我自己的问题。这就是我所做的。
foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
// $lasArray = $queueEntry;
print_r($queueEntry);
}
提供了很多不必要的信息,所以我发现 routeros_api.class.php
可以从 here and followed but modified information from here 下载。然后就用了
$address = 'IPV4_Address_of_router';
$user = 'username_of_router';
$pass = 'password_of_router';
require('routeros_api.class.php');
$API = new routeros_api();
$API->debug = false;
// router credentials and after including the routeros_api.cass.php
if ($API->connect($address, $user, $pass)) {
$results = $API->comm("/queue/simple/print");
foreach ($results as $row) {
$clientName = $row['name'];
$clientIP = $row['target'];
$clientMaxDown = $row['limit-at'];
$clientMaxUp = $row['max-limit'];
$clientDownloads = $row['bytes'];
}
}
唯一剩下的就是保存到数据库,这很简单。也许有一天有人会因此得到帮助。