diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2004-08-19 19:05:49 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2004-08-19 19:05:49 +0000 |
commit | d5ae799b8792708cad68d57c966b562dc442dccd (patch) | |
tree | e2890c5c039f7572de2d9fae84cd67e0754ab5bc | |
parent | c25c672eb2d17f8f10b8e28389a2fd9c91a9b81b (diff) | |
download | monitoring-plugins-d5ae799b8792708cad68d57c966b562dc442dccd.tar.gz |
Patch for tru64 using swapctl calls (Sean Finney)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@890 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | configure.in | 19 | ||||
-rw-r--r-- | plugins/check_swap.c | 44 | ||||
-rw-r--r-- | plugins/common.h | 12 |
3 files changed, 73 insertions, 2 deletions
diff --git a/configure.in b/configure.in index e207d95b..3154af05 100644 --- a/configure.in +++ b/configure.in | |||
@@ -4,7 +4,7 @@ AC_PREREQ(2.50) | |||
4 | AC_INIT(nagios-plugins,1.4.0alpha2) | 4 | AC_INIT(nagios-plugins,1.4.0alpha2) |
5 | AC_CONFIG_SRCDIR(Helper.pm) | 5 | AC_CONFIG_SRCDIR(Helper.pm) |
6 | AM_INIT_AUTOMAKE | 6 | AM_INIT_AUTOMAKE |
7 | AC_CONFIG_HEADER(config.h) | 7 | AM_CONFIG_HEADER(config.h) |
8 | AC_CANONICAL_HOST | 8 | AC_CANONICAL_HOST |
9 | 9 | ||
10 | RELEASE=1 | 10 | RELEASE=1 |
@@ -1388,6 +1388,23 @@ fi | |||
1388 | dnl end if for PATH_TO_SWAPCTL | 1388 | dnl end if for PATH_TO_SWAPCTL |
1389 | fi | 1389 | fi |
1390 | 1390 | ||
1391 | dnl | ||
1392 | dnl test for swapctl system call, as found in tru64 and solaris | ||
1393 | dnl note: the way the ifdef logic in check_swap is right now, | ||
1394 | dnl this will only affect systems that don't pass one of the | ||
1395 | dnl earlier tests. | ||
1396 | dnl | ||
1397 | AC_CHECK_HEADERS([sys/swap.h sys/stat.h sys/param.h]) | ||
1398 | AC_CHECK_DECLS([swapctl],,,[ | ||
1399 | #include <sys/types.h> | ||
1400 | #include <sys/stat.h> | ||
1401 | #include <sys/swap.h> | ||
1402 | ]) | ||
1403 | dnl | ||
1404 | dnl end test for swapctl system call | ||
1405 | dnl | ||
1406 | |||
1407 | |||
1391 | if test "x$ac_cv_have_swap" != "x" | 1408 | if test "x$ac_cv_have_swap" != "x" |
1392 | then | 1409 | then |
1393 | AC_DEFINE(HAVE_SWAP,1,[Define if swap/swapinfo command is found]) | 1410 | AC_DEFINE(HAVE_SWAP,1,[Define if swap/swapinfo command is found]) |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 1155ed0e..f6bbd335 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -52,7 +52,7 @@ main (int argc, char **argv) | |||
52 | { | 52 | { |
53 | int percent_used, percent; | 53 | int percent_used, percent; |
54 | unsigned long long total_swap = 0, used_swap = 0, free_swap = 0; | 54 | unsigned long long total_swap = 0, used_swap = 0, free_swap = 0; |
55 | unsigned long long dsktotal, dskused, dskfree, tmp; | 55 | unsigned long long dsktotal = 0, dskused = 0, dskfree = 0, tmp = 0; |
56 | int result = STATE_OK; | 56 | int result = STATE_OK; |
57 | char input_buffer[MAX_INPUT_BUFFER]; | 57 | char input_buffer[MAX_INPUT_BUFFER]; |
58 | char *perf; | 58 | char *perf; |
@@ -64,6 +64,11 @@ main (int argc, char **argv) | |||
64 | char *temp_buffer; | 64 | char *temp_buffer; |
65 | char *swap_command; | 65 | char *swap_command; |
66 | char *swap_format; | 66 | char *swap_format; |
67 | # else | ||
68 | # ifdef HAVE_DECL_SWAPCTL | ||
69 | int i=0, nswaps=0; | ||
70 | swaptbl_t tbl; | ||
71 | # endif /* HAVE_DECL_SWAPCTL */ | ||
67 | # endif | 72 | # endif |
68 | #endif | 73 | #endif |
69 | char str[32]; | 74 | char str[32]; |
@@ -230,6 +235,43 @@ main (int argc, char **argv) | |||
230 | /* close the pipe */ | 235 | /* close the pipe */ |
231 | if (spclose (child_process)) | 236 | if (spclose (child_process)) |
232 | result = max_state (result, STATE_WARNING); | 237 | result = max_state (result, STATE_WARNING); |
238 | # else | ||
239 | # ifdef HAVE_DECL_SWAPCTL | ||
240 | |||
241 | /* initialize swap table entries */ | ||
242 | memset(&tbl, 0, sizeof(swaptbl_t)); | ||
243 | tbl.swt_ent[0].ste_path=(char*)malloc(sizeof(char)*(MAXPATHLEN+1)); | ||
244 | memset(tbl.swt_ent[0].ste_path, 0, sizeof(char)*(MAXPATHLEN+1)); | ||
245 | tbl.swt_n=1; | ||
246 | |||
247 | /* get the number of active swap devices */ | ||
248 | nswaps=swapctl(SC_GETNSWP, NULL); | ||
249 | |||
250 | /* and now, tally 'em up */ | ||
251 | for(i=0;i<nswaps;i++){ | ||
252 | swapctl(SC_LIST, &tbl); | ||
253 | /* on tru64, swap is stored in 8k pages. i'd | ||
254 | use conv_factor or SWAP_CONVERSION, but they're | ||
255 | both buried under a bunch of ifdef's. ideally | ||
256 | all functions could call getpagesize(2)... */ | ||
257 | dsktotal = tbl.swt_ent[0].ste_pages / 128; | ||
258 | dskfree = tbl.swt_ent[0].ste_free / 128; | ||
259 | dskused = ( total_swap - free_swap ); | ||
260 | |||
261 | if(allswaps && dsktotal > 0){ | ||
262 | percent = 100 * (((double) dskused) / ((double) dsktotal)); | ||
263 | result = max_state (result, check_swap (percent, dskfree)); | ||
264 | } | ||
265 | |||
266 | total_swap += dsktotal; | ||
267 | free_swap += dskfree; | ||
268 | used_swap += dskused; | ||
269 | } | ||
270 | |||
271 | /* and clean up after ourselves */ | ||
272 | free(tbl.swt_ent[0].ste_path); | ||
273 | |||
274 | # endif /* HAVE_DECL_SWAPCTL */ | ||
233 | # endif /* HAVE_SWAP */ | 275 | # endif /* HAVE_SWAP */ |
234 | #endif /* HAVE_PROC_MEMINFO */ | 276 | #endif /* HAVE_PROC_MEMINFO */ |
235 | 277 | ||
diff --git a/plugins/common.h b/plugins/common.h index 3e892522..d878271e 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -98,6 +98,18 @@ | |||
98 | #include <locale.h> | 98 | #include <locale.h> |
99 | #endif | 99 | #endif |
100 | 100 | ||
101 | #ifdef HAVE_DECL_SWAPCTL | ||
102 | # ifdef HAVE_SYS_SWAP_H | ||
103 | # include <sys/swap.h> | ||
104 | # endif | ||
105 | # ifdef HAVE_SYS_STAT_H | ||
106 | # include <sys/stat.h> | ||
107 | # endif | ||
108 | # ifdef HAVE_SYS_PARAM_H | ||
109 | # include <sys/param.h> | ||
110 | # endif | ||
111 | #endif | ||
112 | |||
101 | /* | 113 | /* |
102 | * | 114 | * |
103 | * Missing Functions | 115 | * Missing Functions |