4.8. WBEM operation statistics
New in pywbem 0.11 as experimental and finalized in 0.12.
Pywbem supports measuring the elapsed times of the WBEM operations that were performed in context of a connection, and maintaining a statistics over these times.
This capability is disabled by default and can be enabled in either of these ways:
When creating a
WBEMConnection
object, via itsstats_enabled
argument.After the
WBEMConnection
object has been created, by modifying itsstats_enabled
instance attribute.
The Statistics
class maintains statistics over the measured
elapsed times of the WBEM operations and is the interface for accessing the
statistics. The statistics of a WBEMConnection
object are
accessible via its statistics
instance
attribute.
The OperationStatistic
class is a helper class that contains
the actual measurement data for one operation name.
There will be one OperationStatistic
object each operation
name (see the table of WBEMConnection methods in the WBEM operations
section for the operation names).
The OperationStatistic
objects are under control of the
Statistics
class.
The statistics support maintains two kinds of times for each kind of WBEM operation:
Client times: The elapsed times for the WBEMConnection operation methods from call to return. This is measured in pywbem pretty close to the API the pywbem user is calling.
Server times: The elapsed times for processing the WBEM operations in the WBEM server from receiving the CIM-XML request message to sending back the CIM-XML response message. The server times are not measured by pywbem, but are taken from the WBEMServerResponseTime HTTP header field of a CIM-XML response, if present. See DSP0200 for a description of this header field.
The WBEMServerResponseTime HTTP header field is optionally implemented by WBEM servers. The following WBEM servers are known to implement this header field:
OpenPegasus
Because the interpretation of the calculated average and min/max server times becomes incorrect if only a subset of the operations return the server response time, the statistics counting for the server time is suspended if one or more operations do not return the server response time. Resetting the statistics via
reset()
clears this condition again.
The difference between client time and server time is the time spent in the pywbem client, plus the time spent on the network between client and server.
The statistics support also maintains the size of the HTTP body in the CIM-XML request and response messages, in Bytes.
These times and sizes are maintained as average, minimum and maximum values for each kind of operation in a connection.
Finally, the statistics support maintains the total count of operations and the count of operations that failed, for each kind of operation.
All data in the statistics applies to WBEM operations performed during periods of time where the statistics are enabled on a connection. Operations performed during periods of time where the statistics are disabled on a connection, are simply ignored in the statistics.
For the Iter methods of WBEMConnection (e.g.
IterEnumerateInstances()
), the WBEM operations
performed on behalf of them are subject of the statistics, but the Iter methods
themselves do not show up in the statistics.
The following example shows how statistics are enabled, and how statistics
values are accessed individually using the
get_op_statistic()
method:
conn = pywbem.WBEMConnection(..., stats_enabled=True)
# Perform some operations on this connection
insts_1 = conn.EnumerateInstances('CIM_Foo1', 'root/cimv2')
insts_2 = conn.EnumerateInstances('CIM_Foo2', 'root/cimv2')
insts_3 = conn.EnumerateInstances('CIM_Foo3', 'root/cimv2')
inst_paths_1 = conn.EnumerateInstanceNames('CIM_Foo1', 'root/cimv2')
# Access statistics values for EnumerateInstances
ei_stats = conn.statistics.get_op_statistic('EnumerateInstances')
ei_count = ei_stats.count
ei_avg_client_time = ei_stats.avg_time
ei_avg_server_time = ei_stats.avg_server_time
In the previous example, the values in ei_stats
are “live”, i.e. they
continue to be updated as operations are performed. If a snapshot is needed at
a certain point in time that remains unaffected by further operations, this can
be achieved using the snapshot()
method:
# Take snapshot and access statistics values for EnumerateInstances
stats_snapshot = dict(conn.statistics.snapshot())
ei_stats = stats_snapshot['EnumerateInstances']
ei_count = ei_stats.count
ei_avg_client_time = ei_stats.avg_time
ei_avg_server_time = ei_stats.avg_server_time
It is also possible to simply print the current statistics of a connection as a
formatted table, using the formatted()
method:
# Print statistics values for all operations
print(conn.statistics.formatted())
The output could look like this, if the WBEM server returns WBEM server response times:
Statistics (times in seconds, lengths in Bytes):
Count Excep ClientTime ServerTime RequestLen ReplyLen Operation
Cnt Avg Min Max Avg Min Max Avg Min Max Avg Min Max
3 0 0.234 0.100 0.401 0.204 0.080 0.361 1233 1000 1500 26667 20000 35000 EnumerateInstances
1 0 0.100 0.100 0.100 0.080 0.080 0.080 1200 1200 1200 22000 22000 22000 EnumerateInstanceNames