[Nagiosplug-checkins] CVS: nagiosplug/plugins check_swap.c,1.30,1.31 common.h,1.12,1.13

Ton Voon tonvoon at users.sourceforge.net
Mon Aug 23 14:19:14 CEST 2004


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9795/plugins

Modified Files:
	check_swap.c common.h 
Log Message:
Using swapctl for Solaris, Tru64 and *BSD (Sean Finney)


Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** check_swap.c	19 Aug 2004 19:05:49 -0000	1.30
--- check_swap.c	23 Aug 2004 21:18:12 -0000	1.31
***************
*** 57,65 ****
  	char input_buffer[MAX_INPUT_BUFFER];
  	char *perf;
  #ifdef HAVE_PROC_MEMINFO
  	FILE *fp;
  #else
  # ifdef HAVE_SWAP
- 	int conv_factor;		/* Convert to MBs */
  	char *temp_buffer;
  	char *swap_command;
--- 57,65 ----
  	char input_buffer[MAX_INPUT_BUFFER];
  	char *perf;
+ 	int conv_factor = SWAP_CONVERSION;
  #ifdef HAVE_PROC_MEMINFO
  	FILE *fp;
  #else
  # ifdef HAVE_SWAP
  	char *temp_buffer;
  	char *swap_command;
***************
*** 67,77 ****
  # else
  #  ifdef HAVE_DECL_SWAPCTL
! 	int i=0, nswaps=0;
! 	swaptbl_t tbl;
  #  endif /* HAVE_DECL_SWAPCTL */
  # endif
  #endif
  	char str[32];
! 	char *status;
  
  	setlocale (LC_ALL, "");
--- 67,84 ----
  # else
  #  ifdef HAVE_DECL_SWAPCTL
! 	int i=0, nswaps=0, swapctl_res=0;
! #   ifdef CHECK_SWAP_SWAPCTL_SVR4
! 	swaptbl_t *tbl=NULL;
! 	swapent_t *ent=NULL;
! #   else
! #    ifdef CHECK_SWAP_SWAPCTL_BSD
! 	struct swapent *ent;
! #    endif /* CHECK_SWAP_SWAPCTL_BSD */
! #   endif /* CHECK_SWAP_SWAPCTL_SVR4 */
  #  endif /* HAVE_DECL_SWAPCTL */
  # endif
  #endif
  	char str[32];
! 	char *status, *tmp_status;
  
  	setlocale (LC_ALL, "");
***************
*** 80,83 ****
--- 87,91 ----
  
  	status = strdup ("");
+ 	tmp_status = strdup ("");
  	perf = strdup ("");
  
***************
*** 123,127 ****
  	asprintf(&swap_command, "%s", SWAP_COMMAND);
  	asprintf(&swap_format, "%s", SWAP_FORMAT);
- 	conv_factor = SWAP_CONVERSION;
  
  /* These override the command used if a summary (and thus ! allswaps) is required */
--- 131,134 ----
***************
*** 133,144 ****
  		conv_factor = 1;
  	}
- #  else
- #   ifdef sun
- 	if (!allswaps) {
- 		asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
- 		asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
- 		conv_factor = 2048;
- 	}
- #   endif
  #  endif
  
--- 140,143 ----
***************
*** 184,196 ****
  			printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap);
  	} else {
- #  else
- #   ifdef sun
- 	if (!allswaps) {
- 		sscanf (input_buffer, swap_format, &used_swap, &free_swap);
- 		used_swap = used_swap / 1024;
- 		free_swap = free_swap / 1024;
- 		total_swap = used_swap + free_swap;
- 	} else {
- #   endif
  #  endif
  		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
--- 183,186 ----
***************
*** 220,227 ****
  #  ifdef _AIX
  	}
- #  else
- #   ifdef sun
- 	}
- #   endif
  #  endif
  
--- 210,213 ----
***************
*** 237,265 ****
  		result = max_state (result, STATE_WARNING);
  # else
! #  ifdef HAVE_DECL_SWAPCTL
! 
! 	/* initialize swap table entries */
! 	memset(&tbl, 0, sizeof(swaptbl_t));
! 	tbl.swt_ent[0].ste_path=(char*)malloc(sizeof(char)*(MAXPATHLEN+1));
! 	memset(tbl.swt_ent[0].ste_path, 0, sizeof(char)*(MAXPATHLEN+1));
! 	tbl.swt_n=1;
  
  	/* get the number of active swap devices */
  	nswaps=swapctl(SC_GETNSWP, NULL);
  
  	/* and now, tally 'em up */
  	for(i=0;i<nswaps;i++){
! 		swapctl(SC_LIST, &tbl);
! 		/* on tru64, swap is stored in 8k pages.  i'd
! 		   use conv_factor or SWAP_CONVERSION, but they're
! 		   both buried under a bunch of ifdef's.  ideally
! 		   all functions could call getpagesize(2)...  */
! 		dsktotal = tbl.swt_ent[0].ste_pages / 128;
! 		dskfree = tbl.swt_ent[0].ste_free / 128;
! 		dskused = ( total_swap - free_swap );
  
  		if(allswaps && dsktotal > 0){
  			percent = 100 * (((double) dskused) / ((double) dsktotal));
  			result = max_state (result, check_swap (percent, dskfree));
  		}
  
--- 223,258 ----
  		result = max_state (result, STATE_WARNING);
  # else
! #  ifdef CHECK_SWAP_SWAPCTL_SVR4
  
  	/* get the number of active swap devices */
  	nswaps=swapctl(SC_GETNSWP, NULL);
  
+ 	/* initialize swap table + entries */
+ 	tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
+ 	memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
+ 	tbl->swt_n=nswaps;
+ 	for(i=0;i<nswaps;i++){
+ 		ent=&tbl->swt_ent[i];
+ 		ent->ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN);
+ 	}
+ 
  	/* and now, tally 'em up */
+ 	swapctl_res=swapctl(SC_LIST, tbl);
+ 	if(swapctl_res < 0){
+ 		perror("swapctl failed: ");
+ 		result = STATE_WARNING;
+ 	}
+ 
  	for(i=0;i<nswaps;i++){
! 		dsktotal = tbl->swt_ent[i].ste_pages / SWAP_CONVERSION;
! 		dskfree = tbl->swt_ent[i].ste_free /  SWAP_CONVERSION;
! 		dskused = ( dsktotal - dskfree );
  
  		if(allswaps && dsktotal > 0){
  			percent = 100 * (((double) dskused) / ((double) dsktotal));
  			result = max_state (result, check_swap (percent, dskfree));
+ 			if (verbose) {
+ 				asprintf (&status, "%s [%d (%d%%)]", status, (int)dskfree, 100 - percent);
+ 			}
  		}
  
***************
*** 270,276 ****
  
  	/* and clean up after ourselves */
! 	free(tbl.swt_ent[0].ste_path);
  
! #  endif /* HAVE_DECL_SWAPCTL */
  # endif /* HAVE_SWAP */
  #endif /* HAVE_PROC_MEMINFO */
--- 263,309 ----
  
  	/* and clean up after ourselves */
! 	for(i=0;i<nswaps;i++){
! 		free(tbl->swt_ent[i].ste_path);
! 	}
! 	free(tbl);
! #  else
! #   ifdef CHECK_SWAP_SWAPCTL_BSD
  
! 	/* get the number of active swap devices */
! 	nswaps=swapctl(SWAP_NSWAP, NULL, 0);
! 
! 	/* initialize swap table + entries */
! 	ent=(struct swapent*)malloc(sizeof(struct swapent)*nswaps);
! 
! 	/* and now, tally 'em up */
! 	swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
! 	if(swapctl_res < 0){
! 		perror("swapctl failed: ");
! 		result = STATE_WARNING;
! 	}
! 
! 	for(i=0;i<nswaps;i++){
! 		dsktotal = ent->se_nblks / conv_factor;
! 		dskused = ent->se_inuse / conv_factor;
! 		dskfree = ( dsktotal - dskused );
! 
! 		if(allswaps && dsktotal > 0){
! 			percent = 100 * (((double) dskused) / ((double) dsktotal));
! 			result = max_state (result, check_swap (percent, dskfree));
! 			if (verbose) {
! 				asprintf (&status, "%s [%d (%d%%)]", status, (int)dskfree, 100 - percent);
! 			}
! 		}
! 
! 		total_swap += dsktotal;
! 		free_swap += dskfree;
! 		used_swap += dskused;
! 	}
! 
! 	/* and clean up after ourselves */
! 	free(ent);
! 
! #   endif /* CHECK_SWAP_SWAPCTL_BSD */
! #  endif /* CHECK_SWAP_SWAPCTL_SVR4 */
  # endif /* HAVE_SWAP */
  #endif /* HAVE_PROC_MEMINFO */
***************
*** 278,283 ****
  	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
  	result = max_state (result, check_swap (percent_used, free_swap));
! 	asprintf (&status, _(" %d%% free (%llu MB out of %llu MB)%s"),
! 						(100 - percent_used), free_swap, total_swap, status);
  
  	asprintf (&perf, "%s", perfdata ("swap", (long) free_swap, "MB",
--- 311,318 ----
  	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
  	result = max_state (result, check_swap (percent_used, free_swap));
! 	/* broken into two steps because of funkiness with builtin asprintf */
! 	asprintf (&tmp_status, _(" %d%% free (%llu MB out of %llu MB)"),
! 						(100 - percent_used), free_swap, total_swap);
! 	asprintf (&status, "%s%s", tmp_status, status);
  
  	asprintf (&perf, "%s", perfdata ("swap", (long) free_swap, "MB",

Index: common.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/common.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** common.h	19 Aug 2004 19:05:49 -0000	1.12
--- common.h	23 Aug 2004 21:18:12 -0000	1.13
***************
*** 111,114 ****
--- 111,118 ----
  #endif
  
+ #ifndef SWAP_CONVERSION
+ # define SWAP_CONVERSION 1
+ #endif
+ 
  /*
   *





More information about the Commits mailing list