From 11af74de386ba7c02d5d0e53f2500b5029a4537d Mon Sep 17 00:00:00 2001 From: mdavranche Date: Tue, 18 Aug 2020 15:37:38 -0400 Subject: check_swap: Handle cached swap diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 0ff0c77..ce3f1d7 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -133,7 +133,7 @@ main (int argc, char **argv) xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); } } - else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { + else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { if (verbose >= 3) { printf("Got %s with %f\n", str, tmp_mb); } @@ -142,7 +142,10 @@ main (int argc, char **argv) dsktotal_mb = tmp_mb / 1024; } else if (strcmp ("Free", str) == 0) { - dskfree_mb = tmp_mb / 1024; + dskfree_mb = dskfree_mb + tmp_mb / 1024; + } + else if (strcmp ("Cached", str) == 0) { + dskfree_mb = dskfree_mb + tmp_mb / 1024; } } } -- cgit v0.10-9-g596f From d496d6523bd0def281f001ddfb2a3f467bd9a4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 3 Jan 2022 14:07:54 +0100 Subject: Rename tmp variable to get even with master diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 2b8013b..bb854be 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -145,12 +145,12 @@ main (int argc, char **argv) xasprintf (&status, "%s [%lu (%d%%)]", status, dskfree_mb, 100 - percent); } } - + /* * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123" * This format exists at least on Debian Linux with a 5.* kernel */ - else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { + else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %f %*[k]%*[B]", str, &tmp_KB)) { if (verbose >= 3) { printf("Got %s with %lu\n", str, tmp_KB); } @@ -159,10 +159,10 @@ main (int argc, char **argv) dsktotal_mb = tmp_KB / 1024; } else if (strcmp ("Free", str) == 0) { - dskfree_mb = dskfree_mb + tmp_mb / 1024; + dskfree_mb = dskfree_mb + tmp_KB / 1024; } else if (strcmp ("Cached", str) == 0) { - dskfree_mb = dskfree_mb + tmp_mb / 1024; + dskfree_mb = dskfree_mb + tmp_KB / 1024; } } } -- cgit v0.10-9-g596f