Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing metrics agent bug for parsing and populating metrics objects for all subsystems #54

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions dss_metrics/nvmftarget_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def poll_statistics(self, metrics_data_buffer):

subsystem_num_to_nqn_map = {}
drive_num_to_drive_serial_map = {}
raw_data_queue = []

while True:
line = proc.stdout.readline().decode('utf-8')
Expand Down Expand Up @@ -103,28 +104,38 @@ def poll_statistics(self, metrics_data_buffer):
tags['cluster_id'] = self.cluster_id
tags['target_id'] = socket.gethostname()
tags['type'] = self.TYPE
if 'subsystem' in subsystem_num:
tags['subsystem_id'] = (
subsystem_num_to_nqn_map[subsystem_num]
)
else:
continue # skip if subsystem not mentioned

# TODO: return tuple with metric info instead of populating
"""
XOR operation
check if filter, then whitelist match should be True
if not filter, than whitelist match should be False
"""
if valid_value_flag and self.filter == whitelist_match:
metrics_data_buffer.append(
metrics.MetricInfo(full_key, metric_name, value,
tags, time.time())
)

# we are unsure what metrics have been processed so far, we need to store
# the raw data first and then populate metrics objects when we are sure
# we have processed the entire ustat output

data = {
"whitelist_match": whitelist_match,
"valid_value_flag": valid_value_flag,
"subsystem_num": subsystem_num,
"full_key": full_key,
"metric_name": metric_name,
"value": value,
"tags": tags,
"time": time.time()
}
raw_data_queue.append(data)

except Exception as error:
print(f'Failed to handle line {line}, Error: {str(error)}')
try:
proc.terminate()
for data in raw_data_queue:
if data['valid_value_flag'] and self.filter == data['whitelist_match']:
if 'subsystem' in data['subsystem_num'] and data['subsystem_num'] in subsystem_num_to_nqn_map:
data['tags']['subsystem_id'] = (
subsystem_num_to_nqn_map[data['subsystem_num']]
)
metrics_data_buffer.append(
metrics.MetricInfo(data['full_key'], data['metric_name'], data['value'],
data['tags'], data['time'])
)

except Exception:
print('ustat process termination exception ', exc_info=True)
proc.kill()