Getting tx-bits-per-second and rx-bits-per-second

can anyone help me or can explained what to do or what I am missing? ( complete beginner at the used API )

/interface monitor-traffic Hotspot-Bridge once do={:put ($"tx-bits-per-second")}

The code below does not work… while the code above works at winbox

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2/Autoload.php';

//$monitorRequest = new RouterOS\Request(
//        '/interface/monitor-traffic .proplist=rx-bits-per-second,tx-bits-per-second'
//);

$client = new RouterOS\Client('10.50.160.36', 'admin', 'webdev@2017');

$requests = new RouterOS\Request('/interface monitor-traffic Hotspot-Bridge');
$requests->setArgument('once');
$requests->setArgument('do', ' ($"tx-bits-per-second") ');
$result = $client->sendSync($requests)->current();
print_r($result);

?>

output :

PEAR2\Net\RouterOS\Response Object ( [unrecognizedWords:protected] => Array ( ) [_type:PEAR2\Net\RouterOS\Response:private] => !trap [attributes:protected] => Array ( [message] => no such command ) [_tag:PEAR2\Net\RouterOS\Message:private] => )

Unnamed arguments are not supported. You need to explicitly specify the name. Otherwise, you’re calling a command called “Hotspot-Bridge”, which does not exist.

In the case of monitor-traffic, the argument is called “interface”, so:

$requests = new RouterOS\Request('/interface monitor-traffic interface=Hotspot-Bridge');

I’m not entirely sure the “do” argument would work the way you expect it to, but certainly, you can inspect $result to get “tx-bits-per-second” and everything else.

Oh i c… thnxs a lot :smiley:, it worked!

$requests = new RouterOS\Request('/interface monitor-traffic interface=Hotspot-Bridge');
$requests->setArgument('once');
$result = $client->sendSync($requests)->current();
print_r($result('tx-bits-per-second'));

I changed my code to the code above, since the “do” did nothing… thanks again :smiley:

const { RouterOSAPI } = require(‘node-routeros’);

async function fetchDataFromRouterOS() {
try {
console.log(‘Connecting to MikroTik RouterOS API…’);
const conn = new RouterOSAPI({
host: ‘*****’,
user: ‘',
password: '
‘,
port: *****
});
await conn.connect();
console.log(‘Connected to MikroTik RouterOS API’);
console.log(‘Fetching traffic data…’);
const monitorTraffic = await conn.write(’/interface/monitor-traffic interface="<pppoe-
****>"’);
console.log(‘Traffic data:’, monitorTraffic);
const txBitsPerSecond = monitorTraffic[0][‘tx-bits-per-second’];
const rxBitsPerSecond = monitorTraffic[0][‘rx-bits-per-second’];
const txData = txBitsPerSecond.toString();
const rxData = rxBitsPerSecond.toString();
console.log(‘Closing connection…’);
await conn.close();
console.log(‘Connection closed’);
return { txData, rxData };
} catch (error) {
console.error(‘Error fetching data from MikroTik:’, error);
return null;
}
}
async function fetchData() {
const interfaceData = await fetchDataFromRouterOS();
console.log(‘Interface data:’, interfaceData);
}

fetchData();
sorry but i’m new in programming and i want to a specific pppoe interface using node and node-routeros but the command is not working. help !!!???