1 #include <net-snmp/net-snmp-config.h>
15 #include <net-snmp/net-snmp-includes.h>
16 #include <net-snmp/agent/net-snmp-agent-includes.h>
17 #include <net-snmp/agent/auto_nlist.h>
18 #include "memory.h" /* the module-specific header */
19 #include "memory_hpux.h" /* the module-specific header */
21 #include <sys/pstat.h>
24 #define DEFAULTMINIMUMSWAP 16000 /* kilobytes */
27 static char errmsg[300];
29 static FindVarMethod var_extensible_mem;
30 static long getFreeSwap(void);
31 static long getTotalFree(void);
32 static long getTotalSwap(void);
35 unsigned long total_swap; /* in kilobytes */
36 unsigned long free_swap; /* in kilobytes */
40 memory_parse_config(const char *token, char *cptr)
42 minimumswap = atoi(cptr);
46 memory_free_config(void)
48 minimumswap = DEFAULTMINIMUMSWAP;
52 init_memory_hpux(void)
55 struct variable2 extensible_mem_variables[] = {
56 {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_mem, 1, {MIBINDEX}},
57 {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_mem, 1,
59 {MEMTOTALSWAP, ASN_INTEGER, RONLY, var_extensible_mem, 1,
61 {MEMAVAILSWAP, ASN_INTEGER, RONLY, var_extensible_mem, 1,
63 {MEMTOTALREAL, ASN_INTEGER, RONLY, var_extensible_mem, 1,
65 {MEMAVAILREAL, ASN_INTEGER, RONLY, var_extensible_mem, 1,
67 {MEMTOTALSWAPTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
69 {MEMUSEDSWAPTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
71 {MEMTOTALREALTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
73 {MEMUSEDREALTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
75 {MEMTOTALFREE, ASN_INTEGER, RONLY, var_extensible_mem, 1,
77 {MEMSWAPMINIMUM, ASN_INTEGER, RONLY, var_extensible_mem, 1,
79 {MEMSHARED, ASN_INTEGER, RONLY, var_extensible_mem, 1,
81 {MEMBUFFER, ASN_INTEGER, RONLY, var_extensible_mem, 1,
83 {MEMCACHED, ASN_INTEGER, RONLY, var_extensible_mem, 1,
85 {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_mem, 1,
87 {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_mem, 1, {ERRORMSG}}
91 * Define the OID pointer to the top of the mib tree that we're
92 * registering underneath
94 oid mem_variables_oid[] = { UCDAVIS_MIB, MEMMIBNUM };
97 * register ourselves with the agent to handle our mib tree
99 REGISTER_MIB("ucd-snmp/memory", extensible_mem_variables, variable2,
102 snmpd_register_config_handler("swap", memory_parse_config,
103 memory_free_config, "min-avail");
105 } /* end init_hpux */
108 get_swapinfo(struct swapinfo *swap)
111 struct pst_swapinfo pss;
114 while (pstat_getswap(&pss, sizeof(pss), (size_t) 1, i) != -1) {
115 if (pss.pss_idx == (unsigned) i) {
116 swap->total_swap += pss.pss_nblksenabled;
117 swap->free_swap += 4 * pss.pss_nfpgs; /* nfpgs is in 4-byte blocks - who knows why? */
122 } /* end get_swapinfo */
125 var_extensible_mem(struct variable *vp,
129 size_t * var_len, WriteMethod ** write_method)
132 struct swapinfo swap;
133 struct pst_static pst;
134 struct pst_dynamic psd;
135 static long long_ret;
138 * Initialize the return value to 0
144 if (header_generic(vp, name, length, exact, var_len, write_method))
150 return ((u_char *) (&long_ret));
151 case ERRORNAME: /* dummy name */
152 sprintf(errmsg, "swap");
153 *var_len = strlen(errmsg);
154 return ((u_char *) (errmsg));
157 long_ret = swap.total_swap;
158 return ((u_char *) (&long_ret));
161 long_ret = swap.free_swap;
162 return ((u_char *) (&long_ret));
164 long_ret = minimumswap;
165 return ((u_char *) (&long_ret));
168 * Retrieve the static memory statistics
170 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
171 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
174 long_ret = pst.page_size / 1024 * pst.physical_memory;
175 return ((u_char *) (&long_ret));
178 * Retrieve the static memory statistics
180 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
181 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
185 * Retrieve the dynamic memory statistics
187 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
188 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
191 long_ret = pst.page_size / 1024 * psd.psd_free;
192 return ((u_char *) (&long_ret));
193 case MEMTOTALSWAPTXT:
195 * Retrieve the static memory statistics
197 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
198 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
202 * Retrieve the dynamic memory statistics
204 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
205 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
208 long_ret = pst.page_size / 1024 * psd.psd_vmtxt;
209 return ((u_char *) (&long_ret));
212 * Retrieve the static memory statistics
214 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
215 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
219 * Retrieve the dynamic memory statistics
221 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
222 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
225 long_ret = pst.page_size / 1024 * (psd.psd_vmtxt - psd.psd_avmtxt);
226 return ((u_char *) (&long_ret));
227 case MEMTOTALREALTXT:
229 * Retrieve the static memory statistics
231 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
232 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
236 * Retrieve the dynamic memory statistics
238 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
239 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
242 long_ret = pst.page_size / 1024 * psd.psd_rmtxt;
243 return ((u_char *) (&long_ret));
246 * Retrieve the static memory statistics
248 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
249 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
253 * Retrieve the dynamic memory statistics
255 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
256 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
259 long_ret = pst.page_size / 1024 * (psd.psd_rmtxt - psd.psd_armtxt);
260 return ((u_char *) (&long_ret));
263 * Retrieve the static memory statistics
265 if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1) {
266 snmp_log(LOG_ERR, "memory_hpux: pstat_getstatic failed!\n");
270 * Retrieve the dynamic memory statistics
272 if (pstat_getdynamic(&psd, sizeof(psd), (size_t) 1, 0) == -1) {
273 snmp_log(LOG_ERR, "memory_hpux: pstat_getdynamic failed!\n");
277 long_ret = (pst.page_size / 1024 * psd.psd_free) + swap.free_swap;
278 return ((u_char *) (&long_ret));
281 long_ret = (swap.free_swap > minimumswap) ? 0 : 1;
282 return ((u_char *) (&long_ret));
285 if ((swap.free_swap > minimumswap) ? 0 : 1)
286 sprintf(errmsg, "Running out of swap space (%ld)", long_ret);
289 *var_len = strlen(errmsg);
290 return ((u_char *) (errmsg));