Debian Codegraph @

agent/mibgroup/hardware/memory/memory_win.c

raw
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 <windows.h>
7
8
9 /*
10 * Load the latest memory usage statistics
11 */
12 int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
13
14 netsnmp_memory_info *mem;
15 MEMORYSTATUS stat;
16
17 /*
18 * Retrieve the memory information from the underlying O/S...
19 */
20 GlobalMemoryStatus(&stat);
21
22 /*
23 * ... and save this in a standard form.
24 */
25 mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 );
26 if (!mem) {
27 snmp_log_perror("No Physical Memory info entry");
28 } else {
29 if (!mem->descr)
30 mem->descr = strdup("Physical memory");
31 mem->units = 1024;
32 mem->size = stat.dwTotalPhys/1024;
33 mem->free = stat.dwAvailPhys/1024;
34 mem->other = -1;
35 }
36
37 mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 1 );
38 if (!mem) {
39 snmp_log_perror("No Virtual Memory info entry");
40 } else {
41 if (!mem->descr)
42 mem->descr = strdup("Virtual memory");
43 mem->units = 1024;
44 mem->size = stat.dwTotalVirtual/1024;
45 mem->free = stat.dwAvailVirtual/1024;
46 mem->other = -1;
47 }
48
49 mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 );
50 if (!mem) {
51 snmp_log_perror("No Swap info entry");
52 } else {
53 if (!mem->descr)
54 mem->descr = strdup("Swap space");
55 mem->units = 1024;
56 mem->size = stat.dwTotalPageFile/1024;
57 mem->free = stat.dwAvailPageFile/1024;
58 mem->other = -1;
59 }
60
61 return 0;
62 }
63