1
#include <net-snmp/net-snmp-config.h>
2
#include <net-snmp/net-snmp-includes.h>
3
#include <net-snmp/agent/net-snmp-agent-includes.h>
4
#include <net-snmp/agent/hardware/memory.h>
11
#include <sys/sysget.h>
15
#include <sys/sysmp.h>
19
* Load the latest memory usage statistics
21
int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
23
netsnmp_memory_info *mem;
24
struct rminfo meminfo; /* struct for getting memory info, see sys/sysmp.h */
26
off_t swaptotal, swapfree;
29
* Retrieve the memory information from the underlying O/S...
31
DEBUGMSGTL(("hardware/memory/memory_irix", "Start retrieving values from OS\n"));
32
pagesz = getpagesize();
33
DEBUGMSGTL(("hardware/memory/memory_irix", "Page size: %d\n", pagesz));
34
rminfosz = (int)sysmp(MP_SASZ, MPSA_RMINFO);
35
DEBUGMSGTL(("hardware/memory/memory_irix", "rminfo size: %d\n", rminfosz));
36
if (sysmp(MP_SAGET, MPSA_RMINFO, &meminfo, rminfosz) < 0) {
37
snmp_log(LOG_ERR, "memory_irix: sysmp failed!\n");
40
swapctl(SC_GETSWAPTOT, &swaptotal);
41
swapctl(SC_GETFREESWAP, &swapfree);
44
* ... and save this in a standard form.
46
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 );
48
snmp_log_perror("No Physical Memory info entry");
51
mem->descr = strdup("Physical memory");
53
mem->size = meminfo.physmem;
54
mem->free = meminfo.availrmem;
56
DEBUGMSGTL(("hardware/memory/memory_irix", "Physical memory: size %u, free %u\n", mem->size, mem->free));
59
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 1 );
61
snmp_log_perror("No Virtual Memory info entry");
64
mem->descr = strdup("Virtual memory");
65
mem->units = pagesz; /* swaptotal is in blocks, so adjust below */
66
mem->size = meminfo.physmem + (swaptotal*512/pagesz);
67
mem->free = meminfo.availsmem;
69
DEBUGMSGTL(("hardware/memory/memory_irix", "Virtual memory: size %u, free %u\n", mem->size, mem->free));
72
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 );
74
snmp_log_perror("No Swap info entry");
77
mem->descr = strdup("Swap space");
79
mem->size = swaptotal/2; /* blocks to KB */
80
mem->free = swapfree/2; /* blocks to KB */
82
DEBUGMSGTL(("hardware/memory/memory_irix", "Swap: size %u, free %u\n", mem->size, mem->free));