| 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> |
| 5 |
|
| 6 |
#include <unistd.h> |
| 7 |
#include <sys/protosw.h> |
| 8 |
#include <libperfstat.h> |
| 9 |
#include <sys/stat.h> |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
* Load the latest memory usage statistics |
| 14 |
*/ |
| 15 |
int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) { |
| 16 |
|
| 17 |
netsnmp_memory_info *mem; |
| 18 |
perfstat_memory_total_t pstat_mem; |
| 19 |
long pagesize; |
| 20 |
|
| 21 |
/* |
| 22 |
* Retrieve the memory information from the underlying O/S... |
| 23 |
*/ |
| 24 |
if (perfstat_memory_total((perfstat_id_t *)NULL, &pstat_mem, |
| 25 |
sizeof(perfstat_memory_total_t), 1) < 1) { |
| 26 |
snmp_log(LOG_ERR, "memory_aix: perfstat_memory_total failed!\n"); |
| 27 |
return -1; |
| 28 |
} |
| 29 |
pagesize = getpagesize(); |
| 30 |
|
| 31 |
/* |
| 32 |
* ... and save this in a standard form. |
| 33 |
*/ |
| 34 |
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 ); |
| 35 |
if (!mem) { |
| 36 |
snmp_log_perror("No Physical Memory info entry"); |
| 37 |
} else { |
| 38 |
if (!mem->descr) |
| 39 |
mem->descr = strdup("Physical memory"); |
| 40 |
mem->units = pagesize; /* or 4096 */ |
| 41 |
mem->size = pstat_mem.real_total; |
| 42 |
mem->free = pstat_mem.real_free; |
| 43 |
} |
| 44 |
|
| 45 |
/* ??? Duplicates Physical Memory statistics? */ |
| 46 |
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_USERMEM, 1 ); |
| 47 |
if (!mem) { |
| 48 |
snmp_log_perror("No (user) Memory info entry"); |
| 49 |
} else { |
| 50 |
if (!mem->descr) |
| 51 |
mem->descr = strdup("Real memory"); |
| 52 |
mem->units = pagesize; /* or 4096 */ |
| 53 |
mem->size = pstat_mem.real_total; /* ? less system memory ? */ |
| 54 |
mem->free = pstat_mem.real_free; |
| 55 |
} |
| 56 |
|
| 57 |
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 1 ); |
| 58 |
if (!mem) { |
| 59 |
snmp_log_perror("No Virtual Memory info entry"); |
| 60 |
} else { |
| 61 |
if (!mem->descr) |
| 62 |
mem->descr = strdup("Virtual memory"); |
| 63 |
mem->units = pagesize; /* or 4096 */ |
| 64 |
mem->size = pstat_mem.virt_total; |
| 65 |
mem->free = pstat_mem.real_free + pstat_mem.pgsp_free; |
| 66 |
} |
| 67 |
|
| 68 |
mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 ); |
| 69 |
if (!mem) { |
| 70 |
snmp_log_perror("No Swap info entry"); |
| 71 |
} else { |
| 72 |
if (!mem->descr) |
| 73 |
mem->descr = strdup("Swap space"); |
| 74 |
mem->units = pagesize; /* or 4096 */ |
| 75 |
mem->size = pstat_mem.pgsp_total; |
| 76 |
mem->free = pstat_mem.pgsp_free; |
| 77 |
mem->other = pstat_mem.pgsp_rsvd; |
| 78 |
} |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |