commit 839edfa1d69160678779e770374301acc489ed7f
Author: W. David Ashley <w.david.ashley(a)gmail.com>
Date: Thu Jul 9 10:51:07 2015 -0500
Domains chapter
- finished the performance section
- added examples 30-35
en-US/Guest_Domains.xml | 79 +++++++++++++++++++++++++++++++----
en-US/extras/Domains-Example-30.py | 2 +-
en-US/extras/Domains-Example-31.py | 26 ++++++++++++
en-US/extras/Domains-Example-32.py | 32 ++++++++++++++
en-US/extras/Domains-Example-33.py | 23 ++++++++++
en-US/extras/Domains-Example-34.py | 24 +++++++++++
en-US/extras/Domains-Example-35.py | 21 +++++++++
7 files changed, 197 insertions(+), 10 deletions(-)
---
diff --git a/en-US/Guest_Domains.xml b/en-US/Guest_Domains.xml
index 259dd3d..14f2e3f 100644
--- a/en-US/Guest_Domains.xml
+++ b/en-US/Guest_Domains.xml
@@ -883,11 +883,23 @@
block devices, and network interfaces.
</para>
- <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-Domain">
- <title>Domain Performance</title>
+ <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-Domain_Block">
+ <title>Domain Block Device Performance</title>
<para>
- TBD
+ Disk usage statistics are provided by the
+ <literal>blockStats</literal> method:
+ </para>
+ <example>
+ <title>Get the disk block I/O statistics</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-31.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
+ <para>
+ The returned tuple contains the number of read
+ (write) requests issued, and the actual number of bytes
+ transferred. A block device is specified by the image
+ file path or the device bus name set by the devices/disk/target[@dev]
+ element in the domain XML.
</para>
</section>
@@ -896,20 +908,69 @@
<title>vCPU Performance</title>
<para>
- TBD
+ To obtain the individual VCPU statistics:
+ </para>
+ <example>
+ <title>Get the individual CPU statistics</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-33.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
+ <para>
+ This way, each CPU reports its usage for the domain (in
+ nanoseconds). If a host has four CPUs, there will be
+ four entries in the cpu_stats array.
+ </para>
+ <para>
+ <literal>getCPUStats(True)</literal> aggregates the
statistics for all
+ CPUs on the host:
</para>
+ <example>
+ <title>Get the aggregate CPU statistics</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-34.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
</section>
- <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-IO_stats">
- <title>I/O Statistics</title>
+ <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-Memory">
+ <title>Memory Statistics</title>
- <para>
- TBD
- </para>
+ <para>
+ To obtain the amount of memory currently used by the domain you can use
the
+ <literal>memoryStats</literal> method.
+ </para>
+ <example>
+ <title>Get the memory statistics</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-35.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
+ <para>
+ To find the percentage of memory used by the domain invoke the
<literal>maxMemory</literal>
+ method an then perform the following calculation.
+ </para>
+ <programlisting language="Python">percentage =
dom.memoryStats().value() / dom.maxMemory()</programlisting>
</section>
+ <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-IO_stats">
+ <title>I/O Statistics</title>
+
+ <para>
+ To get the network statistics, you'll need the name
+ of the host interface that the domain is connected to
+ (usually vnetX). To find it, retrieve the domain XML
+ description (libvirt modifies it at the runtime). Then,
+ look for devices/interface/target[@dev] element(s):
+ </para>
+ <example>
+ <title>Get the network I/O statistics</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-32.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
+ <para>
+ The <literal>interfaceStats</literal> method returns the
number
+ of bytes (packets) received (transmitted), and the
+ number of reception/transmission errors.
+ </para>
+
+ </section>
+
</section>
<section
id="libvirt_application_development_guide_using_python-Guest_Domains-Device_Config">
diff --git a/en-US/extras/Domains-Example-30.py b/en-US/extras/Domains-Example-30.py
index 0af77cd..28c8c06 100644
--- a/en-US/extras/Domains-Example-30.py
+++ b/en-US/extras/Domains-Example-30.py
@@ -1,4 +1,4 @@
-# Example-29.py
+# Example-30.py
from __future__ import print_function
import sys
import libvirt
diff --git a/en-US/extras/Domains-Example-31.py b/en-US/extras/Domains-Example-31.py
new file mode 100644
index 0000000..96ac2e5
--- /dev/null
+++ b/en-US/extras/Domains-Example-31.py
@@ -0,0 +1,26 @@
+# Example-31.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+rd_req, rd_bytes, wr_req, wr_bytes, err =
dom.blockStats('/path/to/linux-0.2.img')
+print('Read requests issued: '+rd_req)
+print('Bytes read: '+rd_bytes)
+print('Write requests issued: '+wr_req)
+print('Bytes written: '+wr_bytes)
+print('Number of errors: '+err)
+
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-32.py b/en-US/extras/Domains-Example-32.py
new file mode 100644
index 0000000..a02abfd
--- /dev/null
+++ b/en-US/extras/Domains-Example-32.py
@@ -0,0 +1,32 @@
+# Example-32.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+tree = ElementTree.fromstring(dom.XMLDesc())
+iface = tree.find('devices/interface/target').get('dev')
+rx_bytes, rx_packets, rx_err, rx_drop, tx_bytes, tx_packets, tx_err,
+ tx_drop = dom.interfaceStats(iface)
+print('read bytes: '+rx_bytes)
+print('read packets: 'rx_packets)
+print('read errors: '+rx_err)
+print('read drops: '+rx_drop)
+print('write bytes: '+tx_bytes)
+print('write packets: 'rt_packets)
+print('write errors: '+tx_err)
+print('write drops: '+tx_drop)
+
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-33.py b/en-US/extras/Domains-Example-33.py
new file mode 100644
index 0000000..271cd7f
--- /dev/null
+++ b/en-US/extras/Domains-Example-33.py
@@ -0,0 +1,23 @@
+# Example-33.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+cpu_stats = dom.getCPUStats(False)
+for (i, cpu) in enumerate(cpu_stats):
+ print('CPU '+i+' Time: '+cpu['cpu_time'] / 1000000000.)
+
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-34.py b/en-US/extras/Domains-Example-34.py
new file mode 100644
index 0000000..2fa4315
--- /dev/null
+++ b/en-US/extras/Domains-Example-34.py
@@ -0,0 +1,24 @@
+# Example-34.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+stats = dom.getCPUStats(True)
+print('cpu_time: '+stats[0])
+print('system time: '+stats[1])
+print('user time: '+stats[2])
+
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-35.py b/en-US/extras/Domains-Example-35.py
new file mode 100644
index 0000000..5ad3e80
--- /dev/null
+++ b/en-US/extras/Domains-Example-35.py
@@ -0,0 +1,21 @@
+# Example-35.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+print('"memory used: '+dom.memoryStats().value()
+
+conn.close()
+exit(0)