summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a8411ca)
raw | patch | inline | side by side (parent: a8411ca)
author | Lorin Scraba <lorin@si-bemol.ro> | |
Tue, 19 Jan 2010 23:22:32 +0000 (15:22 -0800) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 20 Jan 2010 16:42:14 +0000 (17:42 +0100) |
It works on RedHat9 and 6 (don't ask). A more gracefull solution is
having a configuration option for choosing /proc/<foo> format I
suppose...
Hope it helps some sysadmins like me that are forced to maintained
anqituities in production.
Cheers
From 1da38c6d515f7fa4599b7b08e1284fb2ac9a504a Mon Sep 17 00:00:00 2001
From: Lorin Scraba <lorin@si-bemol.ro>
Date: Tue, 19 Jan 2010 15:16:29 -0800
Subject: [PATCH] swap plugin - swapin/out fix for older kernels - <2.6
Signed-off-by: Lorin Scraba <lorin@si-bemol.ro>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
having a configuration option for choosing /proc/<foo> format I
suppose...
Hope it helps some sysadmins like me that are forced to maintained
anqituities in production.
Cheers
From 1da38c6d515f7fa4599b7b08e1284fb2ac9a504a Mon Sep 17 00:00:00 2001
From: Lorin Scraba <lorin@si-bemol.ro>
Date: Tue, 19 Jan 2010 15:16:29 -0800
Subject: [PATCH] swap plugin - swapin/out fix for older kernels - <2.6
Signed-off-by: Lorin Scraba <lorin@si-bemol.ro>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/swap.c | patch | blob | history |
diff --git a/src/swap.c b/src/swap.c
index 7f41c9eae263d664bd6d05dbf0439b6ac486168f..63a5c89d24062745902dab9b7fadc0863ef15c01 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
char *fields[8];
int numfields;
+ unsigned int old_kernel=0;
+
derive_t swap_used = 0;
derive_t swap_cached = 0;
derive_t swap_free = 0;
if ((fh = fopen ("/proc/vmstat", "r")) == NULL)
{
- char errbuf[1024];
- WARNING ("swap: fopen: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
- }
-
- while (fgets (buffer, 1024, fh) != NULL)
- {
- derive_t *val = NULL;
-
- if (strncasecmp (buffer, "pswpin", 6) == 0)
- val = &swap_in;
- else if (strncasecmp (buffer, "pswpout", 7) == 0)
- val = &swap_out;
+ // /proc/vmstat does not exist in kernels <2.6
+ if ((fh = fopen ("/proc/stat", "r")) == NULL )
+ {
+ char errbuf[1024];
+ WARNING ("swap: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
else
- continue;
-
- numfields = strsplit (buffer, fields, 8);
-
- if (numfields < 2)
- continue;
-
- *val = (derive_t) atoll (fields[1]);
+ old_kernel = 1;
}
+ if ( old_kernel )
+ while (fgets (buffer, 1024, fh) != NULL)
+ {
+ if (strncasecmp (buffer, "page",4) == 0)
+ {
+ numfields = strsplit(buffer,fields,3);
+ if ( numfields < 3 )
+ continue;
+ swap_in = (derive_t) atoll(fields[1]);
+ swap_out = (derive_t) atoll(fields[2]);
+ }
+ }
+ else
+ while (fgets (buffer, 1024, fh) != NULL)
+ {
+ derive_t *val = NULL;
+ if (strncasecmp (buffer, "pswpin", 6) == 0)
+ val = &swap_in;
+ else if (strncasecmp (buffer, "pswpout", 7) == 0)
+ val = &swap_out;
+ else
+ continue;
+
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 2)
+ continue;
+
+ *val = (derive_t) atoll (fields[1]);
+ }
+
if (fclose (fh))
{
char errbuf[1024];