summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 3bbea77b..3a799c32 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -59,14 +59,15 @@ main (int argc, char **argv)
59 long unsigned int dsktotal, dskused, dskfree; 59 long unsigned int dsktotal, dskused, dskfree;
60 int result = STATE_OK; 60 int result = STATE_OK;
61 char input_buffer[MAX_INPUT_BUFFER]; 61 char input_buffer[MAX_INPUT_BUFFER];
62#ifdef HAVE_SWAP 62#ifdef HAVE_PROC_MEMINFO
63 FILE *fp;
64#else
65# ifdef HAVE_SWAP
63 int conv_factor; /* Convert to MBs */ 66 int conv_factor; /* Convert to MBs */
64 char *temp_buffer; 67 char *temp_buffer;
65 char *swap_command; 68 char *swap_command;
66 char *swap_format; 69 char *swap_format;
67#endif 70# endif
68#ifdef HAVE_PROC_MEMINFO
69 FILE *fp;
70#endif 71#endif
71 char str[32]; 72 char str[32];
72 char *status; 73 char *status;
@@ -88,8 +89,20 @@ main (int argc, char **argv)
88 dsktotal = dsktotal / 1048576; 89 dsktotal = dsktotal / 1048576;
89 dskused = dskused / 1048576; 90 dskused = dskused / 1048576;
90 dskfree = dskfree / 1048576; 91 dskfree = dskfree / 1048576;
91#endif 92 total_swap += dsktotal;
92#ifdef HAVE_SWAP 93 used_swap += dskused;
94 free_swap += dskfree;
95 if (allswaps) {
96 percent = 100 * (((double) dskused) / ((double) dsktotal));
97 result = max_state (result, check_swap (percent, dskfree));
98 if (verbose)
99 asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
100 }
101 }
102 }
103 fclose(fp);
104#else
105# ifdef HAVE_SWAP
93 if (!allswaps && sun) { 106 if (!allswaps && sun) {
94 asprintf(&swap_command, "%s", "/usr/sbin/swap -s"); 107 asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
95 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s"); 108 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
@@ -103,7 +116,7 @@ main (int argc, char **argv)
103 if (verbose >= 2) 116 if (verbose >= 2)
104 printf (_("Command: %s\n"), swap_command); 117 printf (_("Command: %s\n"), swap_command);
105 if (verbose >= 3) 118 if (verbose >= 3)
106 printf ("_(Format: %s\n"), swap_format); 119 printf (_("Format: %s\n"), swap_format);
107 120
108 child_process = spopen (swap_command); 121 child_process = spopen (swap_command);
109 if (child_process == NULL) { 122 if (child_process == NULL) {
@@ -146,7 +159,6 @@ main (int argc, char **argv)
146 printf (_("total=%d, free=%d\n"), dsktotal, dskfree); 159 printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
147 160
148 dskused = dsktotal - dskfree; 161 dskused = dsktotal - dskfree;
149#endif
150 total_swap += dsktotal; 162 total_swap += dsktotal;
151 used_swap += dskused; 163 used_swap += dskused;
152 free_swap += dskfree; 164 free_swap += dskfree;
@@ -158,15 +170,6 @@ main (int argc, char **argv)
158 } 170 }
159 } 171 }
160 } 172 }
161 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
162 result = max_state (result, check_swap (percent_used, free_swap));
163 asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
164 (100 - percent_used), free_swap, total_swap, status);
165
166#ifdef HAVE_PROC_MEMINFO
167 fclose(fp);
168#endif
169#ifdef HAVE_SWAP
170 /* If we get anything on STDERR, at least set warning */ 173 /* If we get anything on STDERR, at least set warning */
171 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) 174 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
172 result = max_state (result, STATE_WARNING); 175 result = max_state (result, STATE_WARNING);
@@ -177,8 +180,14 @@ main (int argc, char **argv)
177 /* close the pipe */ 180 /* close the pipe */
178 if (spclose (child_process)) 181 if (spclose (child_process))
179 result = max_state (result, STATE_WARNING); 182 result = max_state (result, STATE_WARNING);
183# endif
180#endif 184#endif
181 185
186 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
187 result = max_state (result, check_swap (percent_used, free_swap));
188 asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
189 (100 - percent_used), free_swap, total_swap, status);
190
182 die (result, "SWAP %s:%s\n", state_text (result), status); 191 die (result, "SWAP %s:%s\n", state_text (result), status);
183 return STATE_UNKNOWN; 192 return STATE_UNKNOWN;
184} 193}