"/system resources" do miss "find", bug?

I am trying to get memory usage from the my MikrtoTik 750Gv3 without using SNMP.

To get other information like snapshot information I do use this line:

foreach logline in=[/ip accounting snapshot find] do={:log info message="$[/ip accounting snapshot print as-value from=$logline]"}

find command is the clue here. It will split the output so it sends each line as a separate line.
But for
/system resources the find is missing.
You have the usual print, but not find

/system resource>

.. -- go up to system
cpu --
export -- Print or save an export script that can be used to restore configuration
get -- Gets value of item's property
irq -- Interrupt Request usage information
monitor -- Monitor CPU and memory usage
pci -- List of all PCI devices
print -- Print values of item properties
usb -- List of all USB devices

If I go to cpu, find is there:

/system resource cpu>

.. -- go up to resource
find -- Find items by value
get -- Gets value of item's property
print -- Print values of item properties

Any tips on how to get the /system resources out as line by line?

Why does this work:

log info message=[/ip firewall nat print dynamic as-value]

but not this?

log info message=[/system resource print dynamic as-value]

Hi,

  1. Don’t use “print as-value” if you don’t need it. Learn how to use find and get.
  2. Your example doesn’t work, because there is no “dynamic” entry in system resources. Without “dynamic” it should work:
log info message=[/system resource print as-value]
  1. Please, look at this:
log info message=[/system resource get free-memory]

And generally - when you do /system resource get - you’ll see the values you can just obtain. Then you can do it in smart way, for example:

:local freemem [/system resource get free-memory];
:local totmem [/system resource get total-memory];
:log info message="Free memory: $freemem bytes out of $totmem bytes";

Or maybe:

:local freemem ([/system resource get free-memory]/1000000);
:local totmem ([/system resource get total-memory]/1000000);
:log info message="Free memory: $freemem MB out of $totmem MB";

Thanks allot.
I do see I have lot to learn about scripting :slight_smile:

Here is what I use now:

:local freemem ([/system resource get free-memory]/1000000);
:local totmem ([/system resource get total-memory]/1000000);
:local freehddspace ([/system resource get free-hdd-space]/1000000);
:local totalhddspace ([/system resource get total-hdd-space]/1000000);
:local cpuload ([/system resource get cpu-load]);
:local up ([/system resource get uptime]);
:log info message="free-memory=$freemem MB total_memory=$totmem MB free-hdd-space=$freehddspace MB total-hdd-space=$totalhddspace MB cpu_load=$cpuload uptime=$up";