def QPSGraph(data_source, title, expressions, **kwargs): """Create a graph of QPS, broken up by response code. Data is drawn from Prometheus. :param title: Title of the graph. :param expressions: List of Prometheus expressions. Must be 5. :param kwargs: Passed on to Graph. """ if len(expressions) != 5 and len(expressions) != 7: raise ValueError('Expected 5 or 7 expressions, got {}: {}'.format( len(expressions), expressions)) legends = sorted(ALIAS_COLORS.keys()) exprs = zip(legends, expressions) return stacked(prometheus.PromGraph( data_source=data_source, title=title, expressions=exprs, aliasColors=ALIAS_COLORS, yAxes=[ G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.SHORT_FORMAT), ], **kwargs ))
def PromGraph(*args, **kwargs): """A graph of data from our Prometheus.""" kwargs_with_defaults = dict( tooltip=G.Tooltip(sort=G.SORT_DESC), nullPointMode=G.NULL_AS_NULL, ) kwargs_with_defaults.update(kwargs) return prometheus.PromGraph(data_source=PROMETHEUS, *args, **kwargs_with_defaults)
def StatusQPSGraph(data_source, title, expression, **kwargs): """Create a graph of QPS, coloured by status code. :param title: Title of the graph. :param expression: Format and PromQL expression; must sum by label which is http code like 404 or "success" and "error" :param kwargs: Passed on to Graph. """ return W.stacked( prometheus.PromGraph( data_source=data_source, title=title, expressions=[('{{status_code}}', 'sum by (status_code)(%s)' % (expression))], seriesOverrides=QPS_SERIES_OVERRIDES, legend=G.Legend(hideZero=True), yAxes=[ G.YAxis(format=G.OPS_FORMAT), G.YAxis(format=G.SHORT_FORMAT), ], **kwargs ) )