Hi,
Given the recent (IRC) discussion around per-device metrics and the
importance of keeping PMIDs unchanged for metrics, I think it's best to
add support for block device backing chains now after all so that we
won't end up to a situation later where we've added per-device metrics
(one way or another) and find out that adding backing chain statistics
might cause some PMID turbulence.
The patch is pretty trivial, extra handling is warranted as otherwise
the total values would be completely meaningless (backingIndex) or even
misleading (name). Also minor cosmetic reordering of conf file handling.
Reorder the list of block metrics to match libvirt ordering.
---
qa/1041.out | 2 +-
src/pmdas/libvirt/connect | 21 ++++++++++++++-------
src/pmdas/libvirt/libvirt.conf | 3 ++-
src/pmdas/libvirt/pmdalibvirt.1 | 13 +++++++++----
src/pmdas/libvirt/pmdalibvirt.python | 35 +++++++++++++++++++++++++----------
5 files changed, 51 insertions(+), 23 deletions(-)
diff --git a/qa/1041.out b/qa/1041.out
index 325bd54..e041e28 100644
--- a/qa/1041.out
+++ b/qa/1041.out
@@ -15,7 +15,7 @@ Terminate PMDA if already installed ...
Updating the PMCD control file, and notifying PMCD ...
Starting pmcd ...
Starting pmlogger ...
-Check libvirt metrics have appeared ... 71 metrics and Y values
+Check libvirt metrics have appeared ... 72 metrics and Y values
=== verify metric values ===
diff --git a/src/pmdas/libvirt/connect b/src/pmdas/libvirt/connect
index 77f5c8c..1c1cd2d 100755
--- a/src/pmdas/libvirt/connect
+++ b/src/pmdas/libvirt/connect
@@ -28,28 +28,33 @@ from pcp.pmapi import pmContext as PCP
conffile = PCP.pmGetConfig('PCP_PMDAS_DIR')
conffile += '/libvirt/libvirt.conf'
-oldapi = False
user = 'root'
uri = 'qemu:///system'
+backing = False
+oldapi = False
config = ConfigParser.SafeConfigParser()
config.read(conffile)
if config.has_section('pmda'):
for opt in config.options('pmda'):
- if opt == 'oldapi':
- if config.get('pmda', opt) == 'True' or \
- config.get('pmda', opt) == '1':
- oldapi = True
- elif opt == 'user':
+ if opt == 'user':
user = config.get('pmda', opt)
elif opt == 'uri':
uri = config.get('pmda', opt)
+ elif opt == 'backing':
+ if config.get('pmda', opt) == 'True' or \
+ config.get('pmda', opt) == '1':
+ backing = True
+ elif opt == 'oldapi':
+ if config.get('pmda', opt) == 'True' or \
+ config.get('pmda', opt) == '1':
+ oldapi = True
else:
sys.stderr.write("Invalid directive '%s' in %s.\n" % (opt,
conffile))
sys.exit(1)
if len(sys.argv) > 1 and (sys.argv[1] == '-c' or sys.argv[1] == '--config'):
- sys.stdout.write("oldapi=%s\nuser=%s\nuri=%s\n" % (oldapi, user, uri))
+ sys.stdout.write("user=%s\nuri=%s\nbacking=%s\noldapi=%s" % (user, uri,
backing, oldapi))
sys.exit(0)
try:
@@ -68,6 +73,8 @@ except:
sys.stdout.write("Connection as %s to %s ok.\n" % (user, uri))
+sys.stdout.write("Block dev backing stats: %s.\n" % backing)
+
newapi = False
if 'domainListGetStats' in (dir(conn)):
newapi = True
diff --git a/src/pmdas/libvirt/libvirt.conf b/src/pmdas/libvirt/libvirt.conf
index 3862144..ca3a99e 100644
--- a/src/pmdas/libvirt/libvirt.conf
+++ b/src/pmdas/libvirt/libvirt.conf
@@ -3,6 +3,7 @@
#
[pmda]
-oldapi = False
user = root
uri = qemu:///system
+backing = True
+oldapi = False
diff --git a/src/pmdas/libvirt/pmdalibvirt.1 b/src/pmdas/libvirt/pmdalibvirt.1
index 60e33d2..06c0a11 100644
--- a/src/pmdas/libvirt/pmdalibvirt.1
+++ b/src/pmdas/libvirt/pmdalibvirt.1
@@ -29,14 +29,19 @@ See the libvirt documentation for detailed description of
each metric.
This file can contain in its \f3[pmda]\f1 section overriding values
for the following PMDA options:
.IP "\(bu" 4
-oldapi
-.IP "\(bu" 4
user
.IP "\(bu" 4
uri
+.IP "\(bu" 4
+backing
+.IP "\(bu" 4
+oldapi
+.PP
+By default, \f3root\f1, \f3qemu:///system\f1, \f3False\f1 and \f3False\f1
+are used as values, respectively.
.PP
-By default, \f3False\f1, \f3root\f1 and \f3qemu:///system\f1 are used,
-respectively.
+The backing setting can be used to expand block device information to
+cover backing chains with recent libvirt versions.
.PP
The old API setting can be used in environments where recent libvirt API
additions are not available (e.g., RHEL 6 / libvirt-0.10.2) to provide
diff --git a/src/pmdas/libvirt/pmdalibvirt.python
b/src/pmdas/libvirt/pmdalibvirt.python
index 66449db..1b9f1d8 100755
--- a/src/pmdas/libvirt/pmdalibvirt.python
+++ b/src/pmdas/libvirt/pmdalibvirt.python
@@ -48,9 +48,10 @@ class LibvirtPMDA(PMDA):
""" Constructor """
PMDA.__init__(self, name, domain)
- self.oldapi = False
self.user = DEFAULT_USER
self.uri = DEFAULT_URI
+ self.backing = False
+ self.oldapi = False
self.read_config()
self.set_user(self.user)
@@ -167,6 +168,9 @@ class LibvirtPMDA(PMDA):
# Name - empty - type - semantics - units - help
# See libvirt.git/src/libvirt-domain.c
[ 'domstats.block.count', None,
PM_TYPE_U32, PM_SEM_INSTANT, units_count, 'VM block devs, count'
],
+ [ 'domstats.block.all.name', None,
PM_TYPE_STRING, PM_SEM_INSTANT, units_none, 'VM block devs, all names'
],
+ [ 'domstats.block.all.backingIndex', None,
PM_TYPE_U32, PM_SEM_INSTANT, units_count, 'VM block devs, backing chain
imgs' ],
+ [ 'domstats.block.all.path', None,
PM_TYPE_STRING, PM_SEM_INSTANT, units_none, 'VM block devs, all paths'
],
[ 'domstats.block.all.rd.reqs', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_count, 'VM block devs, total rd reqs'
],
[ 'domstats.block.all.rd.bytes', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_bytes, 'VM block devs, total rd bytes'
],
[ 'domstats.block.all.rd.times', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_nsecs, 'VM block devs, total rd times'
],
@@ -175,11 +179,9 @@ class LibvirtPMDA(PMDA):
[ 'domstats.block.all.wr.times', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_nsecs, 'VM block devs, total wr times'
],
[ 'domstats.block.all.fl.reqs', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_count, 'VM block devs, total fl reqs'
],
[ 'domstats.block.all.fl.times', None,
PM_TYPE_U64, PM_SEM_COUNTER, units_nsecs, 'VM block devs, total fl times'
],
- [ 'domstats.block.all.name', None,
PM_TYPE_STRING, PM_SEM_INSTANT, units_none, 'VM block devs, all names'
],
[ 'domstats.block.all.allocation', None,
PM_TYPE_U64, PM_SEM_INSTANT, units_bytes, 'VM backing imgs, total
allocation' ],
[ 'domstats.block.all.capacity', None,
PM_TYPE_U64, PM_SEM_INSTANT, units_bytes, 'VM backing imgs, total capacity'
],
[ 'domstats.block.all.physical', None,
PM_TYPE_U64, PM_SEM_INSTANT, units_bytes, 'VM backing imgs, total physical'
],
- [ 'domstats.block.all.path', None,
PM_TYPE_STRING, PM_SEM_INSTANT, units_none, 'VM backing imgs, all paths'
],
]
self.vm_netstats_res = []
@@ -275,14 +277,18 @@ class LibvirtPMDA(PMDA):
config.read(conffile)
if config.has_section('pmda'):
for opt in config.options('pmda'):
- if opt == 'oldapi':
- if config.get('pmda', opt) == 'True' or \
- config.get('pmda', opt) == '1':
- self.oldapi = True
- elif opt == 'user':
+ if opt == 'user':
self.user = config.get('pmda', opt)
elif opt == 'uri':
self.uri = config.get('pmda', opt)
+ elif opt == 'backing':
+ if config.get('pmda', opt) == 'True' or \
+ config.get('pmda', opt) == '1':
+ self.backing = True
+ elif opt == 'oldapi':
+ if config.get('pmda', opt) == 'True' or \
+ config.get('pmda', opt) == '1':
+ self.oldapi = True
else:
self.err("Invalid directive '%s' in %s.\n" % (opt,
conffile))
sys.exit(1)
@@ -439,6 +445,8 @@ class LibvirtPMDA(PMDA):
self.vm_blockstats_res = []
if not self.oldapi:
stats = libvirt.VIR_DOMAIN_STATS_BLOCK
+ if self.backing:
+ flags |=
libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING
self.vm_blockstats_res =
self.conn.domainListGetStats(self.doms, stats, flags)
else:
for dom in self.doms:
@@ -671,9 +679,16 @@ class LibvirtPMDA(PMDA):
k = parts[0] + '.' + str(i) + '.' + parts[2]
if k in res[pos][1]:
if mtype == PM_TYPE_STRING:
- value = value + ' ' + res[pos][1][k]
+ if not self.backing:
+ value = value + ' ' + res[pos][1][k]
+ else:
+ if res[pos][1][k] not in value:
+ value = value + ' ' + res[pos][1][k]
else:
- value += res[pos][1][k]
+ if 'backingIndex' not in k:
+ value += res[pos][1][k]
+ else:
+ value += 1
if mtype == PM_TYPE_STRING and value.startswith(' '):
value = value[1:]
return [value, 1]
Thanks,
--
Marko Myllynen
|