[Nagiosplug-checkins] CVS: nagiosplug/plugins check_swap.c,1.27,1.28

Karl DeBisschop kdebisschop at users.sourceforge.net
Fri Feb 27 21:04:01 CET 2004


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

Modified Files:
	check_swap.c 
Log Message:
update to work with Linux 2.6 /proc/meminfo format


Index: check_swap.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_swap.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -r1.27 -r1.28
*** check_swap.c	25 Feb 2004 08:12:56 -0000	1.27
--- check_swap.c	28 Feb 2004 04:54:32 -0000	1.28
***************
*** 53,57 ****
  	int percent_used, percent;
  	unsigned long long total_swap = 0, used_swap = 0, free_swap = 0;
! 	unsigned long long dsktotal, dskused, dskfree;
  	int result = STATE_OK;
  	char input_buffer[MAX_INPUT_BUFFER];
--- 53,57 ----
  	int percent_used, percent;
  	unsigned long long total_swap = 0, used_swap = 0, free_swap = 0;
! 	unsigned long long dsktotal, dskused, dskfree, tmp;
  	int result = STATE_OK;
  	char input_buffer[MAX_INPUT_BUFFER];
***************
*** 83,88 ****
  	fp = fopen (PROC_MEMINFO, "r");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
! 		if (sscanf (input_buffer, " %s %llu %llu %llu", str, &dsktotal, &dskused, &dskfree) == 4 &&
! 		    strstr (str, "Swap")) {
  			dsktotal = dsktotal / 1048576;
  			dskused = dskused / 1048576;
--- 83,87 ----
  	fp = fopen (PROC_MEMINFO, "r");
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
! 		if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %llu %llu %llu", &dsktotal, &dskused, &dskfree) == 3) {
  			dsktotal = dsktotal / 1048576;
  			dskused = dskused / 1048576;
***************
*** 98,103 ****
--- 97,114 ----
  			}
  		}
+ 		else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %llu %*[k]%*[B]", str, &tmp)) {
+ 			if (strcmp ("Total", str) == 0) {
+ 				dsktotal = tmp / 1024;
+ 			}
+ 			else if (strcmp ("Free", str) == 0) {
+ 				dskfree = tmp / 1024;
+ 			}
+ 		}
  	}
  	fclose(fp);
+ 	dskused = dsktotal - dskfree;
+ 	total_swap = dsktotal;
+ 	used_swap = dskused;
+ 	free_swap = dskfree;
  #else
  # ifdef HAVE_SWAP





More information about the Commits mailing list