Getting performance statistics
You can extract various data metrics from the system by using code.
The following code snippet provides a reference for authenticating a user session, getting a list
of the statistics files, and downloading a statistics file for individual calculations. The example
code is also used in later sections to perform the actual calculations for various types of metrics
that can be pulled from the system.
Note: The following examples use Python programming language, and
the code and variables that are declared in previous examples.
import re
import xml.etree.ElementTree as ET
import requests
import json
import pprint
def get_token(url, username, password):
response = requests.post(
url + "/auth",
headers={"X-Auth-Username": username, "X-Auth-Password": password},
verify=False)
return response.json()['token']
def get_namespace(element):
m = re.match(r'\{.*\}', element.tag)
return m.group(0) if m else ''
def get_directory_listing(url, token):
response = requests.post(
url + "/lsdumps",
json={"prefix": "/dumps/iostats"},
headers={"X-Auth-Token": token},
verify=False)
if response.status_code != 200:
raise Exception("Invalid directory listing")
return response.json()
def get_file_contents(url, token, filename):
response = requests.post(
url + "/download",
json={"prefix": "/dumps/iostats", "filename": filename},
headers={"X-Auth-Token": token},
verify=False)
if response.status_code != 200:
raise Exception("File not found")
return response.content
def get_latest_stats(url, username, password):
token = get_token(url, username, password)
files = [row['filename'] for row in get_directory_listing(url, token)]
nm_files = [name for name in files if re.match("Nm_stats", name)]
nv_files = [name for name in files if re.match("Nv_stats", name)]
ng_files = [name for name in files if re.match("Ng_stats", name)]
nn_files = [name for name in files if re.match("Nn_stats", name)]
nd_files = [name for name in files if re.match("Nd_stats", name)]
nm_xml = ET.fromstring(get_file_contents(url, token, nm_files[0]))
nv_xml = ET.fromstring(get_file_contents(url, token, nv_files[0]))
ng_xml = ET.fromstring(get_file_contents(url, token, ng_files[0]))
nn_xml = ET.fromstring(get_file_contents(url, token, nn_files[0]))
nd_xml = ET.fromstring(get_file_contents(url, token, nd_files[0]))
xml = {
"Nm_stats": nm_xml,
"Nv_stats": nv_xml,
"Ng_stats": ng_xml,
"Nn_stats": nn_xml,
"Nd_stats": nd_xml
}
return xml
def populate_fields(xml, fields):
for item in fields.items():
item[1]['value'] = int(
xml[item[1]['filename']].
find(get_namespace(xml[item[1]['filename']]) + item[1]['element']).
attrib[item[1]['field']]
)
For details on different types of metrics, see the following sections: