summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2003-02-18 03:46:15 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2003-02-18 03:46:15 (GMT)
commit773af31b84dda4732b1271ec87774479c384cf35 (patch)
tree7796a2946b3a8854e89a7da20477196a30e11324 /plugins
parent2d3e6c49ad8de1a9fb466b59c1b5b69405c39aa8 (diff)
downloadmonitoring-plugins-773af31b84dda4732b1271ec87774479c384cf35.tar.gz
support for Large swap sizes
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@334 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_swap.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 7046c75..5645779 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -43,16 +43,17 @@ void print_help (void);
43 43
44int warn_percent = 200; 44int warn_percent = 200;
45int crit_percent = 200; 45int crit_percent = 200;
46int warn_size = -1; 46long unsigned int warn_size = 0;
47int crit_size = -1; 47long unsigned int crit_size = 0;
48int verbose; 48int verbose;
49int allswaps; 49int allswaps;
50 50
51int 51int
52main (int argc, char **argv) 52main (int argc, char **argv)
53{ 53{
54 int total_swap = 0, used_swap = 0, free_swap = 0, percent_used; 54 int percent_used, percent;
55 int total, used, free, percent; 55 long unsigned int total_swap = 0, used_swap = 0, free_swap = 0;
56 long unsigned int total, used, free;
56 int result = STATE_OK; 57 int result = STATE_OK;
57 char input_buffer[MAX_INPUT_BUFFER]; 58 char input_buffer[MAX_INPUT_BUFFER];
58#ifdef HAVE_SWAP 59#ifdef HAVE_SWAP
@@ -71,28 +72,28 @@ main (int argc, char **argv)
71 fp = fopen (PROC_MEMINFO, "r"); 72 fp = fopen (PROC_MEMINFO, "r");
72 asprintf (&status, "%s", "Swap used:"); 73 asprintf (&status, "%s", "Swap used:");
73 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 74 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
74 if (sscanf (input_buffer, " %s %d %d %d", str, &total, &used, &free) == 4 && 75 if (sscanf (input_buffer, " %s %lu %lu %lu", str, &total, &used, &free) == 4 &&
75 strstr (str, "Swap")) { 76 strstr (str, "Swap")) {
76 total_swap += total; 77 total_swap += total;
77 used_swap += used; 78 used_swap += used;
78 free_swap += free; 79 free_swap += free;
79 if (allswaps) { 80 if (allswaps) {
80 percent = 100 * (((float) used) / ((float) total)); 81 percent = 100 * (((double) used) / ((double) total));
81 if (percent >= crit_percent || free <= crit_size) 82 if (percent >= crit_percent || free <= crit_size)
82 result = max_state (STATE_CRITICAL, result); 83 result = max_state (STATE_CRITICAL, result);
83 else if (percent >= warn_percent || free <= warn_size) 84 else if (percent >= warn_percent || free <= warn_size)
84 result = max_state (STATE_WARNING, result); 85 result = max_state (STATE_WARNING, result);
85 if (verbose) 86 if (verbose)
86 asprintf (&status, "%s [%d/%d]", status, used, total); 87 asprintf (&status, "%s [%lu/%lu]", status, used, total);
87 } 88 }
88 } 89 }
89 } 90 }
90 percent_used = 100 * (((float) used_swap) / ((float) total_swap)); 91 percent_used = 100 * (((double) used_swap) / ((double) total_swap));
91 if (percent_used >= crit_percent || free_swap <= crit_size) 92 if (percent_used >= crit_percent || free_swap <= crit_size)
92 result = max_state (STATE_CRITICAL, result); 93 result = max_state (STATE_CRITICAL, result);
93 else if (percent_used >= warn_percent || free_swap <= warn_size) 94 else if (percent_used >= warn_percent || free_swap <= warn_size)
94 result = max_state (STATE_WARNING, result); 95 result = max_state (STATE_WARNING, result);
95 asprintf (&status, "%s %2d%% (%d out of %d)", status, percent_used, 96 asprintf (&status, "%s %2d%% (%lu out of %lu)", status, percent_used,
96 used_swap, total_swap); 97 used_swap, total_swap);
97 fclose (fp); 98 fclose (fp);
98#else 99#else
@@ -131,22 +132,22 @@ main (int argc, char **argv)
131 used_swap += used; 132 used_swap += used;
132 free_swap += free; 133 free_swap += free;
133 if (allswaps) { 134 if (allswaps) {
134 percent = 100 * (((float) used) / ((float) total)); 135 percent = 100 * (((double) used) / ((double) total));
135 if (percent >= crit_percent || free <= crit_size) 136 if (percent >= crit_percent || free <= crit_size)
136 result = max_state (STATE_CRITICAL, result); 137 result = max_state (STATE_CRITICAL, result);
137 else if (percent >= warn_percent || free <= warn_size) 138 else if (percent >= warn_percent || free <= warn_size)
138 result = max_state (STATE_WARNING, result); 139 result = max_state (STATE_WARNING, result);
139 if (verbose) 140 if (verbose)
140 asprintf (&status, "%s [%d/%d]", status, used, total); 141 asprintf (&status, "%s [%lu/%lu]", status, used, total);
141 } 142 }
142 } 143 }
143 percent_used = 100 * ((float) used_swap) / ((float) total_swap); 144 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
144 asprintf (&status, "%s %2d%% (%d out of %d)",
145 status, percent_used, used_swap, total_swap);
146 if (percent_used >= crit_percent || free_swap <= crit_size) 145 if (percent_used >= crit_percent || free_swap <= crit_size)
147 result = max_state (STATE_CRITICAL, result); 146 result = max_state (STATE_CRITICAL, result);
148 else if (percent_used >= warn_percent || free_swap <= warn_size) 147 else if (percent_used >= warn_percent || free_swap <= warn_size)
149 result = max_state (STATE_WARNING, result); 148 result = max_state (STATE_WARNING, result);
149 asprintf (&status, "%s %2d%% (%lu out of %lu)",
150 status, percent_used, used_swap, total_swap);
150 151
151 /* If we get anything on STDERR, at least set warning */ 152 /* If we get anything on STDERR, at least set warning */
152 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) 153 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
@@ -231,7 +232,7 @@ process_arguments (int argc, char **argv)
231 } 232 }
232 else if (strstr (optarg, ",") && 233 else if (strstr (optarg, ",") &&
233 strstr (optarg, "%") && 234 strstr (optarg, "%") &&
234 sscanf (optarg, "%d,%d%%", &warn_size, &warn_percent) == 2) { 235 sscanf (optarg, "%lu,%d%%", &warn_size, &warn_percent) == 2) {
235 break; 236 break;
236 } 237 }
237 else if (strstr (optarg, "%") && 238 else if (strstr (optarg, "%") &&
@@ -249,7 +250,7 @@ process_arguments (int argc, char **argv)
249 } 250 }
250 else if (strstr (optarg, ",") && 251 else if (strstr (optarg, ",") &&
251 strstr (optarg, "%") && 252 strstr (optarg, "%") &&
252 sscanf (optarg, "%d,%d%%", &crit_size, &crit_percent) == 2) { 253 sscanf (optarg, "%lu,%d%%", &crit_size, &crit_percent) == 2) {
253 break; 254 break;
254 } 255 }
255 else if (strstr (optarg, "%") && 256 else if (strstr (optarg, "%") &&