I haven’t had this problem before so I’m asking for a bit of help. Here’s my script so far:
:local tx;
:local rx;
/interface monitor [/interface find name=“ether1”] once do={
:set tx $“tx-bits-per-second”;
:set rx $“rx-bits-per-second”
};
put “{\tTxRate: $tx,\r\n\tRxRate: $rx\r\n}”;
When I do “/system script run NetStatus”, I’m getting the following result:
name: ether1
rx-packets-per-second: 118
rx-bits-per-second: 557.3kbps
fp-rx-packets-per-second: 0
fp-rx-bits-per-second: 0bps
rx-drops-per-second: 0
rx-errors-per-second: 0
tx-packets-per-second: 89
tx-bits-per-second: 68.8kbps
fp-tx-packets-per-second: 0
fp-tx-bits-per-second: 0bps
tx-drops-per-second: 0
tx-errors-per-second: 0
{ TxRate: 68872,
RxRate: 557312
}
I’m getting output from the monitor I don’t want. How do I quiet that so I only get my formatted TxRate and RxRate?
Thx
try this
{
:global tx;
:global rx;
/interface monitor [/interface find name=“ether1”] once do={
:set tx $“tx-bits-per-second”;
:set rx $“rx-bits-per-second”
};
put “{\tTxRate: $tx,\r\n\tRxRate: $rx\r\n}”;
}and you can use $tx, $rx “global” by any another script, or by new terminal, just write :put $tx;
What you gave me gives me the exact same problem I was complaining about.
/system script run script1
name: ether1
rx-packets-per-second: 244
rx-bits-per-second: 232.1kbps
rx-drops-per-second: 0
rx-errors-per-second: 0
tx-packets-per-second: 32
tx-bits-per-second: 38.0kbps
tx-drops-per-second: 0
tx-errors-per-second: 0
{ TxRate: 38000,
RxRate: 232160
}
This script, once it’s done, will be run about once an hour from SSH by some custom monitoring software. I want a JSON object delivered to the monitoring software. What I’m getting is a bunch of extraneous text I don’t want. I suppose I could :put "/* “; before I run the monitor command and :put " */”; after I run the command and before I put my rates, but that seems like an ugly kludge.
I suppose I could do that, have a script with ugly output run once a minute and set the globals I need, and then grab the globals from the script that is called by SSH. That might be the only workable solution. Thanks for the idea.