diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-10 10:37:19 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-10 10:37:19 +0100 |
| commit | 9679551b20acdc8306a11e6c7d9dbc4f15e90967 (patch) | |
| tree | 2d8a340dd0df04284bc4d3dcb6e27cb4a7461de7 /plugins/check_swap.d | |
| parent | 77c0913f7577d20fbb8a8ead522199cd079ea122 (diff) | |
| download | monitoring-plugins-9679551b20acdc8306a11e6c7d9dbc4f15e90967.tar.gz | |
check_swap: stricter error handling
Diffstat (limited to 'plugins/check_swap.d')
| -rw-r--r-- | plugins/check_swap.d/swap.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c index 17c4f73b..6c94b33a 100644 --- a/plugins/check_swap.d/swap.c +++ b/plugins/check_swap.d/swap.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include "./check_swap.d/check_swap.h" | 1 | #include "./check_swap.d/check_swap.h" |
| 2 | #include "../popen.h" | 2 | #include "../popen.h" |
| 3 | #include "../utils.h" | 3 | #include "../utils.h" |
| 4 | #include "common.h" | ||
| 4 | 5 | ||
| 5 | extern int verbose; | 6 | extern int verbose; |
| 6 | 7 | ||
| @@ -66,7 +67,7 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { | |||
| 66 | meminfo_file_ptr = fopen(proc_meminfo, "r"); | 67 | meminfo_file_ptr = fopen(proc_meminfo, "r"); |
| 67 | 68 | ||
| 68 | swap_result result = {0}; | 69 | swap_result result = {0}; |
| 69 | result.statusCode = STATE_OK; | 70 | result.errorcode = STATE_UNKNOWN; |
| 70 | 71 | ||
| 71 | uint64_t swap_total = 0; | 72 | uint64_t swap_total = 0; |
| 72 | uint64_t swap_used = 0; | 73 | uint64_t swap_used = 0; |
| @@ -91,6 +92,9 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { | |||
| 91 | result.metrics.used += swap_used; | 92 | result.metrics.used += swap_used; |
| 92 | result.metrics.free += swap_free; | 93 | result.metrics.free += swap_free; |
| 93 | 94 | ||
| 95 | // Set error | ||
| 96 | result.errorcode = STATE_OK; | ||
| 97 | |||
| 94 | /* | 98 | /* |
| 95 | * The following sscanf call looks for lines looking like: | 99 | * The following sscanf call looks for lines looking like: |
| 96 | * "SwapTotal: 123" and "SwapFree: 123" This format exists at least | 100 | * "SwapTotal: 123" and "SwapFree: 123" This format exists at least |
| @@ -113,6 +117,8 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) { | |||
| 113 | } else if (strcmp("Cached", str) == 0) { | 117 | } else if (strcmp("Cached", str) == 0) { |
| 114 | swap_free = swap_free + tmp_KB * 1024; | 118 | swap_free = swap_free + tmp_KB * 1024; |
| 115 | } | 119 | } |
| 120 | |||
| 121 | result.errorcode = STATE_OK; | ||
| 116 | } | 122 | } |
| 117 | } | 123 | } |
| 118 | 124 | ||
