Date: Tue, 25 Jan 2022 08:32:19 +0300 From: Yuri <yuri@aetern.org> To: freebsd-questions@freebsd.org Subject: Re: snmp oid for memory usage, vmstat -i and others Message-ID: <bf5d8bcb-45f7-6829-98f0-10b09e6f6048@aetern.org> In-Reply-To: <0c8e1634-d4e2-2ecb-0af4-9f4eceab9124@aetern.org> References: <bd565507-019d-6fe9-6589-49413e5e1bb6@otcnet.ru> <0c8e1634-d4e2-2ecb-0af4-9f4eceab9124@aetern.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bf5d8bcb-45f7-6829-98f0-10b09e6f6048>