summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4615758)
raw | patch | inline | side by side (parent: 4615758)
author | Deyan Chepishev <dchepishev@superhosting.bg> | |
Fri, 28 Oct 2016 06:40:24 +0000 (09:40 +0300) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 28 Oct 2016 11:40:52 +0000 (13:40 +0200) |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/virt.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 821d0fff58746c9dccafcb871b634522b3b4319f..bbe7b18600b2cae7d3ce2341d31b5f6e50949e97 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# RefreshInterval 60
# Domain "name"
# BlockDevice "name:device"
-# BlockDeviceFormat dev
+# BlockDeviceFormat target
# BlockDeviceFormatBasename false
# InterfaceDevice "name:device"
# IgnoreSelected false
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 69e716be77ba6258368de6fb6411f22a94eb4d53..64be99e23a5742639e59f65b2450ee0b20927fba 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=item B<BlockDevice> I<name:dev>
-=item B<BlockDeviceFormat> B<source>|B<dev>
-
-=item B<BlockDeviceFormatBasename> B<false>|B<true>
+=item B<BlockDeviceFormat> B<source>|B<target>
=item B<InterfaceDevice> I<name:dev>
Ignore all I<hdb> devices on any domain, but other block devices (eg. I<hda>)
will be collected.
-If I<BlockDeviceFormat> is set to B<dev>, then the device names will be the ones
+If I<BlockDeviceFormat> is set to B<target>, then the device names will be the ones
in the I<target> node for the device in the XML definition of the domain. The
-default is B<dev>. This is the behavior before adding the option.
+default is B<target>. This is the behavior before adding the option.
If I<BlockDeviceFormat> is set to B<source>, then the device names will be the ones
in the I<source> node for the device in the XML definition of the domain.
setting
- BlockDeviceFormat dev
+ BlockDeviceFormat target
-will name the device in the graph as sda
+will name the device in the graph as C<sda>
setting
BlockDeviceFormat source
-will name the device in the graph as var_lib_libvirt_images_image1.qcow2
+will name the device in the graph as C<var_lib_libvirt_images_image1.qcow2>
These names will also be part of the RRD filename.
+=item B<BlockDeviceFormatBasename> B<false>|B<true>
+
I<BlockDeviceFormatBasename> - this option is honored if and only if
option I<BlockDeviceFormat> is set to B<source>. If set to B<true> then
only the last part of the path will be used for device name and naming the
Example:
-if the device path (source tag) is: /var/lib/libvirt/images/image1.qcow2
+if the device path (source tag) is: C</var/lib/libvirt/images/image1.qcow2>
setting:
BlockDeviceFormatBasename true
-will set the device name to: image1.qcow2
+will set the device name to: C<image1.qcow2>
=item B<HostnameFormat> B<name|uuid|hostname|...>
diff --git a/src/virt.c b/src/virt.c
index e32150af96cc9ad251df6fd9e21fee1573ca541f..416383f391dab103da71d513d8aaf460d3c91799 100644 (file)
--- a/src/virt.c
+++ b/src/virt.c
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libgen.h>
+#include <stdbool.h>
/* Plugin name */
#define PLUGIN_NAME "virt"
/* BlockDeviceFormat */
enum bd_field {
- dev,
+ target,
source
};
};
/* BlockDeviceFormatBasename */
-char *blockdevice_format_basename="false";
-static enum bd_field blockdevice_format = dev;
+_Bool blockdevice_format_basename = false;
+static enum bd_field blockdevice_format = target;
static enum if_field interface_format = if_name;
/* Time that we last refreshed. */
}
if (strcasecmp (key, "BlockDeviceFormat") == 0) {
- if (strcasecmp (value, "dev") == 0)
- blockdevice_format = dev;
+ if (strcasecmp (value, "target") == 0)
+ blockdevice_format = target;
else if (strcasecmp (value, "source") == 0)
blockdevice_format = source;
else {
}
if (strcasecmp (key, "BlockDeviceFormatBasename") == 0) {
if (strcasecmp (value, "true") == 0)
- blockdevice_format_basename = "true";
+ blockdevice_format_basename = true;
else if (strcasecmp (value, "false") == 0)
- blockdevice_format_basename = "false";
+ blockdevice_format_basename = false;
else {
ERROR (PLUGIN_NAME " plugin: unknown BlockDeviceFormatBasename: %s", value);
return -1;
&stats, sizeof stats) != 0)
continue;
- char *new_path=NULL;
- if( 0==strcasecmp("true", blockdevice_format_basename) && source==blockdevice_format){ //valid only if we use source (full path to the device)
- new_path=strdup(basename(block_devices[i].path));
- }else{
- new_path=strdup(block_devices[i].path);
+ char *type_instance = NULL;
+ if( blockdevice_format_basename && blockdevice_format == source ) //valid only if we use "source" (full path to the device)
+ {
+ type_instance = strdup(basename(block_devices[i].path));
+ }
+ else
+ {
+ type_instance = strdup(block_devices[i].path);
}
if ((stats.rd_req != -1) && (stats.wr_req != -1))
submit_derive2 ("disk_ops",
(derive_t) stats.rd_req, (derive_t) stats.wr_req,
- block_devices[i].dom, new_path);
+ block_devices[i].dom, type_instance);
if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1))
submit_derive2 ("disk_octets",
(derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes,
- block_devices[i].dom, new_path);
+ block_devices[i].dom, type_instance);
- free(new_path);
+ sfree(type_instance);
} /* for (nr_block_devices) */
/* Get interface stats for each domain. */
xpath_ctx = xmlXPathNewContext (xml_doc);
/* Block devices. */
- char * bd_xmlpath=NULL;
- if( source == blockdevice_format ){
- bd_xmlpath="/domain/devices/disk/source[@dev]";
- }else{
- if( dev == blockdevice_format ){
- bd_xmlpath="/domain/devices/disk/target[@dev]";
- }
+ char * bd_xmlpath = "/domain/devices/disk/target[@dev]"; //the default behavior
+ if( blockdevice_format == source )
+ {
+ bd_xmlpath = "/domain/devices/disk/source[@dev]";
}
- xpath_obj = xmlXPathEval
- ((xmlChar *) bd_xmlpath,
- xpath_ctx);
+ xpath_obj = xmlXPathEval ((xmlChar *) bd_xmlpath, xpath_ctx);
if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
xpath_obj->nodesetval == NULL)