Date: Tue, 25 Jan 2022 10:46:20 +0300 From: Victor Gamov <vit@otcnet.ru> To: questions@freebsd.org Subject: Re: snmp oid for memory usage, vmstat -i and others Message-ID: <5e9eb718-0472-fba1-0880-06f539e04790@otcnet.ru> In-Reply-To: <bf5d8bcb-45f7-6829-98f0-10b09e6f6048@aetern.org> References: <bd565507-019d-6fe9-6589-49413e5e1bb6@otcnet.ru> <0c8e1634-d4e2-2ecb-0af4-9f4eceab9124@aetern.org> <bf5d8bcb-45f7-6829-98f0-10b09e6f6048@aetern.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Yuri Thanks for your reply! So, I can find total memory via HOST-RESOURCES-MIB::hrMemorySize.0 But how to calculate used memory? I guess I need to find all HOST-RESOURCES-MIB::hrStorageType = HOST-RESOURCES-TYPES::hrStorageRam and then multiply corresponding hrStorageAllocationUnits * hrStorageSize and sum all of them. Is it correct? On 25.01.2022 08:32, Yuri wrote: > Yuri wrote: >> Victor Gamov wrote: >>> Hi All >>> >>> Some questions about bsnmpd. >>> >>> Is it possible to get memory usage via bsnmpd? When I tried to get >>> something like "snmpget hrStorageDescr.1 hrStorageAllocationUnits.1 >>> hrStorageSize.1 hrStorageUsed.1" then I've got this values: >>> >>> ===== >>> HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Real Memory Metrics >>> HOST-RESOURCES-MIB::hrStorageAllocationUnits.1 = INTEGER: 4096 Bytes >>> HOST-RESOURCES-MIB::hrStorageSize.1 = INTEGER: 391488 >>> HOST-RESOURCES-MIB::hrStorageUsed.1 = INTEGER: 391252 >>> ===== >>> >>> How I must process it to calculate actual memory usage for machine with >>> 4GB RAM and without swap? >>> >>> ===== >>> $ sysctl hw | egrep 'hw.(phys|user|real)' >>> hw.physmem: 4243894272 >>> hw.usermem: 3580182528 >>> hw.realmem: 4294967296 >>> ===== >> >> Values returned by bsnmpd look weird to me as well, so I looked into it >> a bit. Excerpt from the snmp_hostres (as a standalone test case): >> ---- >> #include <sys/types.h> >> #include <sys/sysctl.h> >> #include <sys/vmmeter.h> >> >> #include <vm/vm_param.h> >> >> #include <err.h> >> #include <stdio.h> >> >> static struct vmtotal mem_stats; >> >> int >> main(void) >> { >> int mib[2] = { CTL_VM, VM_TOTAL }; >> size_t len = sizeof(mem_stats); >> >> if (sysctl(mib, 2, &mem_stats, &len, NULL, 0) != 0) >> err(1, "sysctl"); >> >> printf("real=%lu\n", mem_stats.t_rm); >> >> return (0); >> } >> ---- >> output: >> real=31632 >> ---- >> >> Now the sysctl output: >> ---- >> $ sysctl vm.vmtotal >> vm.vmtotal: >> System wide totals computed every five seconds: (values in kilobytes) >> =============================================== >> Processes: (RUNQ: 1 Disk Wait: 0 Page Wait: 0 Sleep: 28) >> Virtual Memory: (Total: 547240K Active: 542480K) >> Real Memory: (Total: 126572K Active: 125600K) >> Shared Virtual Memory: (Total: 4612K Active: 0K) >> Shared Real Memory: (Total: 924K Active: 0K) >> Free Memory: 3608396K >> --- >> I can't map the output to anything on the system (16G RAM, 16G swap) >> except for the "Free Memory", it matches. >> >> 31632 ("real") * 4096 ("pagesize") matches the "Real Memory" in sysctl >> output. Though to get anything resembling 16G, "real" needs to be >> multiplied by 512 (K?). >> >> As a wild guess, it seems that the units used are wrong here, or I >> simply don't understand the meaning of these values. > > Looking at sys/vmmeter.h, my assumptions above are wrong: > > uint64_t t_rm; /* total real memory in use */ > > But that does not include the "wired" (and other) pages, so I'm not sure > about this metric usefulness. > > In any case, you have the following: > > HOST-RESOURCES-MIB::hrMemorySize.0 = INTEGER: 16734232 KBytes > -- CU, Victor Gamov
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5e9eb718-0472-fba1-0880-06f539e04790>