Utility Functions¶
This module contains utility functions for gathering CPU metrics
-
class
monitormetrics.utils.utils.
FileLock
(protected_file_path, timeout=None, delay=1, lock_file_contents=None)[source]¶ A file locking mechanism that has context-manager support so you can use it in a
with
statement. This should be relatively cross compatible as it doesn’t rely onmsvcrt
orfcntl
for the locking.-
acquire
(blocking=True)[source]¶ Acquire the lock, if possible. If the lock is in use, and blocking is False, return False. Otherwise, check again every self.delay seconds until it either gets the lock or exceeds timeout number of seconds, in which case it raises an exception.
-
-
class
monitormetrics.utils.utils.
PDF
(config)[source]¶ custom PDF class that inherits from the FPDF
This method defines footer of the pdf
-
monitormetrics.utils.utils.
check_perf_events
(perf_events)[source]¶ This function check if all perf groups are actually working. We will only probe the working counters during monitoring
-
monitormetrics.utils.utils.
dump_json
(content, filename)[source]¶ This function appends data to an existing json content. It creates a new file if no existing file found.
-
monitormetrics.utils.utils.
execute_cmd
(cmd_str, handle_exception=True)[source]¶ Accept command string and returns output.
- Parameters
- Returns
Output of the command. If command execution fails, returns ‘not_available’
- Return type
- Raises
subprocess.CalledProcessError – An error occurred in execution of command iff handle_exception is set to False
-
monitormetrics.utils.utils.
execute_cmd_pipe
(cmd_str)[source]¶ Accept command string and execute it using piping and returns process object.
-
monitormetrics.utils.utils.
find_procs_by_name
(name)[source]¶ Return a list of processes matching ‘name’
-
monitormetrics.utils.utils.
get_cpu_model_family
(cpu)[source]¶ ” This function gives CPU model and family ids from CPUID instruction
-
monitormetrics.utils.utils.
get_cpu_model_names_for_non_x86
()[source]¶ This function tries to extract the vendor, model and cpu architectures for non x86 machines like IBM POWER, ARM
- Returns
Name of the vendor model name/number of the processor micro architecture of the processor
- Return type
-
monitormetrics.utils.utils.
get_cpu_vendor
(cpu)[source]¶ This function gets the vendor name from CPUID instruction
-
monitormetrics.utils.utils.
get_cpu_vendor_model_family
()[source]¶ This function gets the name of CPU vendor, family and model parsed from CPUID instruction
- Returns
Name of the vendor, CPU family and model ID
- Return type
-
monitormetrics.utils.utils.
get_mem_bw_event
()[source]¶ This function returns the perf event to get memory bandwidth
- Returns
A string to get memory bandwidth for perf stat command
- Return type
-
monitormetrics.utils.utils.
get_perf_events
()[source]¶ This function checks the micro architecture type and returns available perf events. Raises an exception if micro architecture is not implemented
- Returns
Perf events with event name dict: Derived perf metrics from event counters
- Return type
- Raises
PerfEventsNotFoundError – An error occurred while looking for perf events
-
monitormetrics.utils.utils.
get_rapl_devices
()[source]¶ This function gets all the packages, core, uncore and dram device available within RAPL powercap interface
- Returns
A dict with package names and paths
- Return type
-
monitormetrics.utils.utils.
get_value
(input_dict, target)[source]¶ Find the value for a given target in dict
-
monitormetrics.utils.utils.
ibstat_ports
()[source]¶ This function returns Infiniband ports if present
- Returns
A dict with IB port names and numbers
- Return type
-
monitormetrics.utils.utils.
load_json
(filename)[source]¶ This function loads json file and return dict
-
monitormetrics.utils.utils.
merge_dicts
(exst_dict, new_dict)[source]¶ Merge two dicts. old_content is updated with data from new_content
-
monitormetrics.utils.utils.
proc_if_running
(procs)[source]¶ Check if all processes are running and returns a False if all of them are terminated