def make_metrics_data_for_queues(queues_labels, mq_manager): """Returns string with all main metrics for all queues. Converts input dictionary with data to pushgateway formatted string.""" metrics_annotation = get_metric_annotation() prometheus_data_list = list(list() for i in range(len(metrics_annotation))) prometheus_data_list_result = list() for queue_name, queue_labels in queues_labels.items(): template_string = 'qmname="{0}", queuename="{1}", type="{2}"'.format( mq_manager, queue_name, queue_labels['type']) max_depth_metric = '{0}{{{1}}} {2}\n'.format( get_metric_name(metric_label='maxdepth'), template_string, int(queue_labels['maxdepth'])) cur_depth_metric = '{0}{{{1}}} {2}\n'.format( get_metric_name(metric_label='curdepth'), template_string, int(queue_labels['curdepth'])) prometheus_data_list[metrics_annotation['maxdepth'][1]].append( max_depth_metric) prometheus_data_list[metrics_annotation['curdepth'][1]].append( cur_depth_metric) for key in sorted(metrics_annotation.keys()): add_annotation(prometheus_data_list[metrics_annotation[key][1]], metrics_annotation[key][0]) prometheus_data_list_result.extend( prometheus_data_list[metrics_annotation[key][1]]) prometheus_data_str = ''.join(prometheus_data_list_result) return prometheus_data_str
def make_metrics_data_for_queues_monitor(queues_labels, mq_manager): """Returns string with all real-time monitoring metrics for all queues. Converts input dictionary with data to pushgateway formatted string.""" metrics_annotation = get_metric_annotation_monitor() prometheus_data_list = list(list() for i in range(len(metrics_annotation))) prometheus_data_list_result = list() for queue_name, queue_labels in queues_labels.items(): value_lput = ' '.join( [queue_labels['lputdate'], queue_labels['lputtime']]) metric_value_lput = time.mktime( datetime.datetime.strptime(value_lput, "%Y-%m-%d %H.%M.%S").timetuple()) value_lget = ' '.join( [queue_labels['lgetdate'], queue_labels['lgettime']]) metric_value_lget = time.mktime( datetime.datetime.strptime(value_lget, "%Y-%m-%d %H.%M.%S").timetuple()) template_string = 'qmname="{0}", queuename="{1}"'.format( mq_manager, queue_name) msgage_metric = '{0}{{{1}}} {2}\n'.format(get_metric_name('msgage'), template_string, int(queue_labels['msgage'])) lput_metric = '{0}{{{1}}} {2}\n'.format(get_metric_name('lput'), template_string, int(metric_value_lput)) lget_metric = '{0}{{{1}}} {2}\n'.format(get_metric_name('lget'), template_string, int(metric_value_lget)) metric_name_qtime_short = '{0}{{{1}, indicator="short_term"}} {2}\n'.format( get_metric_name('qtime'), template_string, int(queue_labels['qtime'].split(',')[0])) metric_name_qtime_long = '{0}{{{1}, indicator="long_term"}} {2}\n'.format( get_metric_name('qtime'), template_string, int(queue_labels['qtime'].split(',')[1].strip())) prometheus_data_list[metrics_annotation['msgage'][1]].append( msgage_metric) prometheus_data_list[metrics_annotation['lput'][1]].append(lput_metric) prometheus_data_list[metrics_annotation['lget'][1]].append(lget_metric) prometheus_data_list[metrics_annotation['qtime'][1]].extend( [metric_name_qtime_short, metric_name_qtime_long]) for key in sorted(metrics_annotation.keys()): add_annotation(prometheus_data_list[metrics_annotation[key][1]], metrics_annotation[key][0]) prometheus_data_list_result.extend( prometheus_data_list[metrics_annotation[key][1]]) prometheus_data_str = ''.join(prometheus_data_list_result) return prometheus_data_str
def get_mq_listeners_metrics(listeners, mq_manager): """Returns string with status listeners metrics which ready to push to pushgateway.""" metrics_annotation = get_metric_annotation() prometheus_data_list = list() for listener in listeners: listener_data = run_mq_command(task='get_lsstatus', mqm=mq_manager, listener=listener) listener_labels = run_mq_command(task='get_listener', mqm=mq_manager, listener=listener) listener_status = get_listener_status(listener_data=listener_data, listener_labels=listener_labels) metric_data = make_metric_for_mq_listener_status( mq_listener_status_data=listener_status, mqm=mq_manager) prometheus_data_list.append('{0}'.format(metric_data)) add_annotation(prometheus_data_list, metrics_annotation['status']) prometheus_data_str = ''.join(prometheus_data_list) return prometheus_data_str
def test_add_annotation(self): """Tests for `add_annotation` function.""" self.assertEqual(add_annotation(lis1=list(), annotation='test'), []) self.assertEqual(add_annotation(lis1=['test'], annotation='Good'), ['Good', 'test'])
def get_mq_channels_metrics(mq_channels, mq_manager): """Returns string with all metrics which ready to push to pushgateway.""" metrics_annotation = get_metric_annotation() prometheus_data_list = list(list() for i in range(len(metrics_annotation))) prometheus_data_list_result = list() for channels in mq_channels: for channel_data in mq_channels[channels]: metric_data_stat = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='status') prometheus_data_list[metrics_annotation['status'][1]].append( metric_data_stat) if not channel_data['STATUS']: continue else: metric_data_buffers_received = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='buffers_received') metric_data_buffers_sent = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='buffers_sent') metric_data_bytes_received = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='bytes_received') metric_data_bytes_sent = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='bytes_sent') metric_data_lmsg = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='lmsg') metric_data_msgs = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='msgs') metric_data_batches = make_metric_for_mq_channels_status( channel_data=channel_data, mqm=mq_manager, metric_type='batches') prometheus_data_list[metrics_annotation['buffers'][1]].extend( [metric_data_buffers_received, metric_data_buffers_sent]) prometheus_data_list[metrics_annotation['bytes'][1]].extend( [metric_data_bytes_received, metric_data_bytes_sent]) prometheus_data_list[metrics_annotation['lmsg'][1]].append( metric_data_lmsg) prometheus_data_list[metrics_annotation['msgs'][1]].append( metric_data_msgs) prometheus_data_list[metrics_annotation['batches'][1]].append( metric_data_batches) for key in sorted(metrics_annotation.keys()): add_annotation(prometheus_data_list[metrics_annotation[key][1]], metrics_annotation[key][0]) prometheus_data_list_result.extend( prometheus_data_list[metrics_annotation[key][1]]) prometheus_data_str = ''.join(prometheus_data_list_result) return prometheus_data_str