Community discussions

MikroTik App
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

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

Wed Mar 15, 2017 10:05 am

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] => )
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

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

Wed Mar 15, 2017 3:46 pm

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.
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

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

Thu Mar 16, 2017 2:27 am

Oh i c... thnxs a lot :D, 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 :D
 
Nathanael
just joined
Posts: 1
Joined: Mon Feb 19, 2024 4:39 pm

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

Mon Feb 19, 2024 4:52 pm

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 !!!???

Who is online

Users browsing this forum: No registered users and 7 guests