def get_sample(self, **kwargs): search_string = None search_type = None if 'search_string' in kwargs and 'search_type' in kwargs: search_string = kwargs['search_string'] search_type = kwargs['search_type'] meter_name = kwargs['meter_name'] unit_type = kwargs['unit_type'] if search_string is None or search_type is None: expr = metrics_helper.get_metrics_with_labels( meter_name, None, None) else: expr = metrics_helper.get_metrics_with_labels( meter_name, search_type, search_string) if 'function_type' in meter_name and 'function_time' in meter_name: expr = meter_name['function_type'] + "(" + expr + "[" + meter_name[ 'function_time'] + "]" + ")" if 'aggregation_op' in meter_name: expr = meter_name['aggregation_op'] + "(" + expr + ")" if 'aggregation_over_time' in meter_name and 'aggregation_over_time_value' in meter_name: expr = meter_name[ 'aggregation_over_time'] + "_over_time" + "(" + expr + "[" + meter_name[ 'aggregation_over_time_value'] + "]" + ")" if 'aggregation_paramop' in meter_name and 'aggregation_paramval' in meter_name: expr = meter_name['aggregation_paramop'] + "(" + meter_name[ 'aggregation_paramval'] + "," + "(" + expr + ")" + ")" if 'group_by' in meter_name: expr = expr + ' by ' + "(" + meter_name['group_by'] + ")" if 'not_group_by' in meter_name: expr = expr + ' without ' + "(" + meter_name['not_group_by'] + ")" log.info("Expression %s", expr) instance_value_list = prometheus_helper.get_metrics(expr, unit_type) kwargs['result_list'] = instance_value_list return kwargs
def get_sample(self, **kwargs): search_string = None search_type = None if 'search_string' in kwargs and 'search_type' in kwargs: search_string = kwargs['search_string'] search_type = kwargs['search_type'] meter_name = kwargs['meter_name'] unit_type = kwargs['unit_type'] if search_string is None or search_type is None: expr = metrics_helper.get_metrics_with_labels( json.loads(json.dumps(meter_name)), None, None) else: expr = metrics_helper.get_metrics_with_labels( json.loads(json.dumps(meter_name)), search_type, search_string) log.info("Expression %s", expr) instance_value_list = prometheus_helper.get_metrics(expr, unit_type) kwargs['result_list'] = instance_value_list return kwargs
def get_sample(self, **kwargs): search_string = None search_type = None if 'search_string' in kwargs and 'search_type' in kwargs: search_string = kwargs['search_string'] search_type = kwargs['search_type'] meter_name = kwargs['meter_name'] unit_type = kwargs['unit_type'] if search_string is None or search_type is None: expr = metrics_helper.get_metrics_with_labels(meter_name, None, None) else: expr = metrics_helper.get_metrics_with_labels(meter_name, search_type, search_string) if 'function_type' in meter_name and 'function_time' in meter_name: expr = meter_name['function_type']+"("+expr+"["+meter_name['function_time']+"]"+")" if 'aggregation_op' in meter_name: expr = meter_name['aggregation_op']+"("+expr+")" if 'aggregation_over_time' in meter_name and 'aggregation_over_time_value' in meter_name: expr = meter_name['aggregation_over_time']+"_over_time"+"("+expr+"["+meter_name['aggregation_over_time_value']+"]"+")" if 'aggregation_paramop' in meter_name and 'aggregation_paramval' in meter_name: expr = meter_name['aggregation_paramop']+"("+meter_name['aggregation_paramval']+","+"("+expr+")"+")" if 'group_by' in meter_name: expr = expr+' by '+"("+meter_name['group_by']+")" if 'not_group_by' in meter_name: expr = expr + ' without '+"("+meter_name['not_group_by']+")" log.info("Expression %s", expr) instance_value_list = prometheus_helper.get_metrics(expr, unit_type) kwargs['result_list'] = instance_value_list return kwargs
def create_json(name, unit_list, metrics_list, unit_type): """ Creates json for promdash :param name: Name of the dashboard :param unit_list: Name list of the units :param metrics_list: List of metrics :return: """ widgets_type = "graph" widgets_interpolation_method = "linear" widgets_resolution = 4 show_legend = "always" axes_orientation = "left" axes_renderer = "line" axes_scale = "linear" axes_format = "kmbt" base_file = os.path.join(os.path.dirname(template_data.__file__), "promdash.json") base_json = open(base_file).read() data = json.loads(base_json) data['name'] = name for i in unit_list: expressions_id = 0 expressions_server_id = 1 expressions_axis_id = 1 axes_id = 1 legend_id = 1 expressions = [] legendFormatStrings = [] axes = [] widget = {} widget["title"] = i widget["type"] = widgets_type widget["showLegend"] = show_legend widget["interpolationMethod"] = widgets_interpolation_method widget["resolution"] = widgets_resolution widget["endTime"] = None for j in metrics_list: expression = {} legendFormatString = {} axe = {} if axes_id < 3: if axes_id > 1: axe["orientation"] = "right" axe['yMin'] = "1" axe['yMax'] = "1000000000" axe["scale"] = "log" else: axe["orientation"] = axes_orientation axe["renderer"] = axes_renderer axe["scale"] = axes_scale axe["format"] = axes_format axe["id"] = axes_id axes.append(axe) expression["id"] = expressions_id expression["serverID"] = expressions_server_id if unit_type == 'docker': expression[ "expression"] = metrics_helper.get_metrics_with_labels( j, "name", i) elif unit_type == 'node': expression[ "expression"] = metrics_helper.get_metrics_with_labels( j, "instance", i) elif unit_type == 'jmx': expression[ "expression"] = metrics_helper.get_metrics_with_labels( j, "instance", i) expression["legendID"] = legend_id expression["axisID"] = 1 legendFormatString["id"] = legend_id legendFormatString["name"] = j['name'] axes_id += 1 expressions.append(expression) legendFormatStrings.append(legendFormatString) expressions_id += 1 expressions_axis_id += 1 legend_id += 1 widget["expressions"] = expressions widget["legendFormatStrings"] = legendFormatStrings widget["axes"] = axes data["dashboard_json"]["widgets"].append(widget) return json.dumps(data)