I would like to monitor the memory usage of my RPi3 running LE-9.2.4.
(My RPi3 is crashing very often and I want to find if memory is the reason)
For this I would like to obtain or calculate the used memory via snmp and graph it with mrtg.
Is it correct to use?:
.1.3.6.1.4.1.2021.4.5.0 - .1.3.6.1.4.1.2021.4.6.0
I'm a bit unsure because I saw someone using 'total' and 'available' from the 'free' command output e.g.:
Code
total_mem=$(free -k | grep Mem | awk '{print $2}')
avail_mem=$(free -k | grep Mem | awk '{print $7}')
memory_usage=$(awk "BEGIN {percent_used=($total_mem-$avail_mem)/($total_mem)*100; print percent_used}")
echo $memory_usage
54.0915
While my calculation would be comparable with (but than with snmp):
Code
total_mem=$(free -k | grep Mem | awk '{print $2}')
free_mem=$(free -k | grep Mem | awk '{print $4}')
memory_usage=$(awk "BEGIN {percent_used=($total_mem-$free_mem)/($total_mem)*100; print percent_used}")
echo $memory_usage
96.3987
e.g.
Code
total_mem=`snmpwalk -v 1 -c libreelec 192.168.178.22 -O qv .1.3.6.1.4.1.2021.4.5.0`
free_mem=`snmpwalk -v 1 -c libreelec 192.168.178.22 -O qv .1.3.6.1.4.1.2021.4.6.0`
used_mem=`expr $total_mem - $free_mem`
echo used memory = $total_mem - $free_mem = $used_mem
used memory = 765828 - 36260 = 729568
The free command gives the following output:
Code
# free -k
total used free shared buff/cache available
Mem: 765828 368088 31836 12864 365904 319296
Swap: 0 0 0
# free
total used free shared buff/cache available
Mem: 765828 337520 48720 12304 379588 350564
Swap: 0 0 0
# free -m
total used free shared buff/cache available
Mem: 747 329 33 12 385 342
Swap: 0 0 0
Display More
With snmp I obtain the following:
Code
snmpwalk -v 1 -c libreelec -m "/home/pi/.snmp/mibs/UCD-SNMP-MIB.txt" -Oaf 192.168.178.22 .1.3.6.1.4.1.2021.4
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memIndex.0 = INTEGER: 0
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memErrorName.0 = STRING: swap
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalSwap.0 = INTEGER: 0 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memAvailSwap.0 = INTEGER: 0 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalReal.0 = INTEGER: 765828 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memAvailReal.0 = INTEGER: 32736 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memTotalFree.0 = INTEGER: 32736 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memMinimumSwap.0 = INTEGER: 16000 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memShared.0 = INTEGER: 13132 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memBuffer.0 = INTEGER: 14844 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memCached.0 = INTEGER: 308492 kB
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memSwapError.0 = INTEGER: error(1)
.iso.org.dod.internet.private.enterprises.ucdavis.memory.memSwapErrorMsg.0 = STRING: Running out of swap space (0)
Display More
Code
snmpwalk -v 1 -c libreelec -m "/home/pi/.snmp/mibs/UCD-SNMP-MIB.txt" -On 192.168.178.22 .1.3.6.1.4.1.2021.4
.1.3.6.1.4.1.2021.4.1.0 = INTEGER: 0
.1.3.6.1.4.1.2021.4.2.0 = STRING: swap
.1.3.6.1.4.1.2021.4.3.0 = INTEGER: 0 kB
.1.3.6.1.4.1.2021.4.4.0 = INTEGER: 0 kB
.1.3.6.1.4.1.2021.4.5.0 = INTEGER: 765828 kB
.1.3.6.1.4.1.2021.4.6.0 = INTEGER: 28100 kB
.1.3.6.1.4.1.2021.4.11.0 = INTEGER: 28100 kB
.1.3.6.1.4.1.2021.4.12.0 = INTEGER: 16000 kB
.1.3.6.1.4.1.2021.4.13.0 = INTEGER: 12668 kB
.1.3.6.1.4.1.2021.4.14.0 = INTEGER: 6916 kB
.1.3.6.1.4.1.2021.4.15.0 = INTEGER: 318120 kB
.1.3.6.1.4.1.2021.4.100.0 = INTEGER: error(1)
.1.3.6.1.4.1.2021.4.101.0 = STRING: Running out of swap space (0)
Display More
Code
# cat /proc/meminfo
MemTotal: 765828 kB
MemFree: 33888 kB
MemAvailable: 323172 kB
Buffers: 9040 kB
Cached: 310884 kB
SwapCached: 0 kB
Active: 343016 kB
Inactive: 279112 kB
Active(anon): 309664 kB
Inactive(anon): 5416 kB
Active(file): 33352 kB
Inactive(file): 273696 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 23060 kB
Writeback: 0 kB
AnonPages: 302352 kB
Mapped: 32660 kB
Shmem: 12688 kB
Slab: 86596 kB
SReclaimable: 47648 kB
SUnreclaim: 38948 kB
KernelStack: 2216 kB
PageTables: 3296 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 382912 kB
Committed_AS: 1559040 kB
VmallocTotal: 1294336 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
Percpu: 656 kB
CmaTotal: 8192 kB
CmaFree: 6108 kB
Display More