projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
src/collectd.h: Define GAUGE_FORMAT.
[collectd.git]
/
src
/
swap.c
diff --git
a/src/swap.c
b/src/swap.c
index
397969e
..
fb50cf3
100644
(file)
--- a/
src/swap.c
+++ b/
src/swap.c
@@
-1,6
+1,6
@@
/**
* collectd - src/swap.c
/**
* collectd - src/swap.c
- * Copyright (C) 2005-201
0
Florian octo Forster
+ * Copyright (C) 2005-201
2
Florian octo Forster
* Copyright (C) 2009 Stefan Völkel
* Copyright (C) 2009 Manuel Sanmartin
* Copyright (C) 2010 Aurélien Reynaud
* Copyright (C) 2009 Stefan Völkel
* Copyright (C) 2009 Manuel Sanmartin
* Copyright (C) 2010 Aurélien Reynaud
@@
-70,13
+70,16
@@
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#if KERNEL_LINUX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#if KERNEL_LINUX
-# define SWAP_HAVE_CONFIG 1
-/* No global variables */
+# define SWAP_HAVE_REPORT_BY_DEVICE 1
+static derive_t pagesize;
+static _Bool report_bytes = 0;
+static _Bool report_by_device = 0;
/* #endif KERNEL_LINUX */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
/* #endif KERNEL_LINUX */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
-# define SWAP_HAVE_
CONFIG
1
+# define SWAP_HAVE_
REPORT_BY_DEVICE
1
static derive_t pagesize;
static derive_t pagesize;
+static _Bool report_by_device = 0;
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
#elif defined(VM_SWAPUSAGE)
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
#elif defined(VM_SWAPUSAGE)
@@
-101,23
+104,37
@@
static perfstat_memory_total_t pmemory;
# error "No applicable input method."
#endif /* HAVE_LIBSTATGRAB */
# error "No applicable input method."
#endif /* HAVE_LIBSTATGRAB */
-#if SWAP_HAVE_CONFIG
static const char *config_keys[] =
{
static const char *config_keys[] =
{
+ "ReportBytes",
"ReportByDevice"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
"ReportByDevice"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-static _Bool report_by_device = 0;
-
static int swap_config (const char *key, const char *value) /* {{{ */
{
static int swap_config (const char *key, const char *value) /* {{{ */
{
- if (strcasecmp ("ReportBy
Device
", key) == 0)
+ if (strcasecmp ("ReportBy
tes
", key) == 0)
{
{
+#if KERNEL_LINUX
+ report_bytes = IS_TRUE (value) ? 1 : 0;
+#else
+ WARNING ("swap plugin: The \"ReportBytes\" option is only "
+ "valid under Linux. "
+ "The option is going to be ignored.");
+#endif
+ }
+ else if (strcasecmp ("ReportByDevice", key) == 0)
+ {
+#if SWAP_HAVE_REPORT_BY_DEVICE
if (IS_TRUE (value))
report_by_device = 1;
else
report_by_device = 0;
if (IS_TRUE (value))
report_by_device = 1;
else
report_by_device = 0;
+#else
+ WARNING ("swap plugin: The \"ReportByDevice\" option is not "
+ "supported on this platform. "
+ "The option is going to be ignored.");
+#endif /* SWAP_HAVE_REPORT_BY_DEVICE */
}
else
{
}
else
{
@@
-126,12
+143,11
@@
static int swap_config (const char *key, const char *value) /* {{{ */
return (0);
} /* }}} int swap_config */
return (0);
} /* }}} int swap_config */
-#endif /* SWAP_HAVE_CONFIG */
static int swap_init (void) /* {{{ */
{
#if KERNEL_LINUX
static int swap_init (void) /* {{{ */
{
#if KERNEL_LINUX
- /* No init stuff */
+ pagesize = (derive_t) sysconf (_SC_PAGESIZE);
/* #endif KERNEL_LINUX */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
/* #endif KERNEL_LINUX */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
@@
-144,6
+160,8
@@
static int swap_init (void) /* {{{ */
/* #endif defined(VM_SWAPUSAGE) */
#elif HAVE_LIBKVM_GETSWAPINFO
/* #endif defined(VM_SWAPUSAGE) */
#elif HAVE_LIBKVM_GETSWAPINFO
+ char errbuf[_POSIX2_LINE_MAX];
+
if (kvm_obj != NULL)
{
kvm_close (kvm_obj);
if (kvm_obj != NULL)
{
kvm_close (kvm_obj);
@@
-152,14
+170,11
@@
static int swap_init (void) /* {{{ */
kvm_pagesize = getpagesize ();
kvm_pagesize = getpagesize ();
- if ((kvm_obj = kvm_open (NULL, /* execfile */
- NULL, /* corefile */
- NULL, /* swapfile */
- O_RDONLY, /* flags */
- NULL)) /* errstr */
- == NULL)
+ kvm_obj = kvm_openfiles (NULL, "/dev/null", NULL, O_RDONLY, errbuf);
+
+ if (kvm_obj == NULL)
{
{
- ERROR ("swap plugin: kvm_open
failed."
);
+ ERROR ("swap plugin: kvm_open
files failed, %s", errbuf
);
return (-1);
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
return (-1);
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
@@
-205,7
+220,7
@@
static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
swap_submit (plugin_instance, "swap", type_instance, v);
} /* }}} void swap_submit_gauge */
swap_submit (plugin_instance, "swap", type_instance, v);
} /* }}} void swap_submit_gauge */
-#if KERNEL_LINUX
+#if KERNEL_LINUX
|| HAVE_PERFSTAT
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
const char *type_instance, derive_t value)
{
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
const char *type_instance, derive_t value)
{
@@
-214,7
+229,9
@@
static void swap_submit_derive (const char *plugin_instance, /* {{{ */
v.derive = value;
swap_submit (plugin_instance, "swap_io", type_instance, v);
} /* }}} void swap_submit_derive */
v.derive = value;
swap_submit (plugin_instance, "swap_io", type_instance, v);
} /* }}} void swap_submit_derive */
+#endif
+#if KERNEL_LINUX
static int swap_read_separate (void) /* {{{ */
{
FILE *fh;
static int swap_read_separate (void) /* {{{ */
{
FILE *fh;
@@
-321,7
+338,7
@@
static int swap_read_combined (void) /* {{{ */
fclose (fh);
fclose (fh);
- if (
have_data != 0x07
)
+ if (
(have_data & 0x03) != 0x03
)
return (ENOENT);
if (isnan (swap_total)
return (ENOENT);
if (isnan (swap_total)
@@
-333,7
+350,8
@@
static int swap_read_combined (void) /* {{{ */
swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
- swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+ if (have_data & 0x04)
+ swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
return (0);
} /* }}} int swap_read_combined */
return (0);
} /* }}} int swap_read_combined */
@@
-406,6
+424,12
@@
static int swap_read_io (void) /* {{{ */
if (have_data != 0x03)
return (ENOENT);
if (have_data != 0x03)
return (ENOENT);
+ if (report_bytes)
+ {
+ swap_in = swap_in * pagesize;
+ swap_out = swap_out * pagesize;
+ }
+
swap_submit_derive (NULL, "in", swap_in);
swap_submit_derive (NULL, "out", swap_out);
swap_submit_derive (NULL, "in", swap_in);
swap_submit_derive (NULL, "out", swap_out);
@@
-764,8
+788,12
@@
static int swap_read (void) /* {{{ */
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
+
swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
+ swap_submit_gauge (NULL, "reserved", (gauge_t) pmemory.pgsp_rsvd * pagesize);
+ swap_submit_derive (NULL, "in", (derive_t) pmemory.pgspins * pagesize);
+ swap_submit_derive (NULL, "out", (derive_t) pmemory.pgspouts * pagesize);
return (0);
} /* }}} int swap_read */
return (0);
} /* }}} int swap_read */
@@
-773,9
+801,8
@@
static int swap_read (void) /* {{{ */
void module_register (void)
{
void module_register (void)
{
-#if SWAP_HAVE_CONFIG
- plugin_register_config ("swap", swap_config, config_keys, config_keys_num);
-#endif
+ plugin_register_config ("swap", swap_config,
+ config_keys, config_keys_num);
plugin_register_init ("swap", swap_init);
plugin_register_read ("swap", swap_read);
} /* void module_register */
plugin_register_init ("swap", swap_init);
plugin_register_read ("swap", swap_read);
} /* void module_register */