Exemplo n.º 1
0
def test_auto_id():
    """auto_panel_ids() provides IDs for all panels without IDs already set."""
    dashboard = G.Dashboard(
        title="Test dashboard",
        rows=[
            G.Row(panels=[
                G.Graph(
                    title="CPU Usage by Namespace (rate[5m])",
                    dataSource="My data source",
                    targets=[
                        G.Target(
                            expr='whatever',
                            legendFormat='{{namespace}}',
                            refId='A',
                        ),
                    ],
                    yAxes=G.YAxes(
                        G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds"),
                        G.YAxis(format=G.SHORT_FORMAT),
                    ),
                )
            ]),
        ],
    ).auto_panel_ids()
    assert dashboard.rows[0].panels[0].id == 1
Exemplo n.º 2
0
def test_auto_refids_preserves_provided_ids():
    """
    auto_ref_ids() provides refIds for all targets without refIds already
    set.
    """
    dashboard = G.Dashboard(
        title="Test dashboard",
        rows=[
            G.Row(panels=[
                G.Graph(
                    title="CPU Usage by Namespace (rate[5m])",
                    targets=[
                        G.Target(
                            expr='whatever #Q',
                            legendFormat='{{namespace}}',
                        ),
                        G.Target(
                            expr='hidden whatever',
                            legendFormat='{{namespace}}',
                            refId='Q',
                        ),
                        G.Target(expr='another target'),
                    ],
                ).auto_ref_ids()
            ]),
        ],
    )
    assert dashboard.rows[0].panels[0].targets[0].refId == 'A'
    assert dashboard.rows[0].panels[0].targets[1].refId == 'Q'
    assert dashboard.rows[0].panels[0].targets[2].refId == 'B'

    dashboard = G.Dashboard(
        title="Test dashboard",
        panels=[
            G.Graph(title="CPU Usage by Namespace (rate[5m])",
                    dataSource="My data source",
                    targets=[
                        G.Target(
                            expr='whatever #Q',
                            legendFormat='{{namespace}}',
                        ),
                        G.Target(
                            expr='hidden whatever',
                            legendFormat='{{namespace}}',
                            refId='Q',
                        ),
                        G.Target(expr='another target'),
                    ],
                    yAxes=G.YAxes(
                        G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds"),
                        G.YAxis(format=G.SHORT_FORMAT),
                    ),
                    gridPos=G.GridPos(h=1, w=24, x=0, y=8)).auto_ref_ids()
        ],
    ).auto_panel_ids()
    assert dashboard.panels[0].targets[0].refId == 'A'
    assert dashboard.panels[0].targets[1].refId == 'Q'
    assert dashboard.panels[0].targets[2].refId == 'B'
Exemplo n.º 3
0
def simple_graph(title, exprs, yAxes=None, legend=""):
    if not isinstance(exprs, (list, tuple)):
        exprs = [exprs]
    if legend != "" and len(exprs) != 1:
        raise ValueError("legend can be specified only for a 1-element exprs")
    return Graph(
        title=title,
        # One graph per row.
        targets=[g.Target(expr=expr, legendFormat=legend) for expr in exprs],
        yAxes=yAxes or g.YAxes(),
    )
def simple_graph(title, exprs, yAxes=None):
    if not isinstance(exprs, (list, tuple)):
        exprs = [exprs]
    return g.Graph(
        title=title,
        dataSource="$source",
        # One graph per row.
        span=g.TOTAL_SPAN,
        targets=[g.Target(expr=expr) for expr in exprs],
        yAxes=yAxes or g.YAxes(),
        tooltip=DECREASING_ORDER_TOOLTIP,
    )
Exemplo n.º 5
0
 def AddGraphPanel(self, title: Text, raw_sql: Text, y_axis_title: Text):
     self.AddPanel(
         core.Graph(
             title=title,
             targets=[
                 core.SqlTarget(
                     rawSql=raw_sql,
                     format=core.TABLE_TARGET_FORMAT,
                 ),
             ],
             yAxes=core.YAxes(core.YAxis(format=y_axis_title), ),
         ))
Exemplo n.º 6
0
def test_serialization_cloudwatch_metrics_target():
    """Serializing a graph doesn't explode."""
    graph = G.Graph(
        title="Lambda Duration",
        dataSource="Cloudwatch data source",
        targets=[
            C.CloudwatchMetricsTarget(),
        ],
        id=1,
        yAxes=G.YAxes(
            G.YAxis(format=G.SHORT_FORMAT, label="ms"),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
    )
    stream = StringIO()
    _gen.write_dashboard(graph, stream)
    assert stream.getvalue() != ''
Exemplo n.º 7
0
def test_serialization_humio_metrics_target():
    """Serializing a graph doesn't explode."""
    graph = G.Graph(
        title="Humio Logs",
        dataSource="Humio data source",
        targets=[
            H.HumioTarget(),
        ],
        id=1,
        yAxes=G.YAxes(
            G.YAxis(format=G.SHORT_FORMAT, label="ms"),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
    )
    stream = StringIO()
    _gen.write_dashboard(graph, stream)
    assert stream.getvalue() != ''
Exemplo n.º 8
0
def test_serialization():
    """Serializing a graph doesn't explode."""
    graph = G.Graph(
        title="CPU Usage by Namespace (rate[5m])",
        dataSource="My data source",
        targets=[
            G.Target(
                expr='namespace:container_cpu_usage_seconds_total:sum_rate',
                legendFormat='{{namespace}}',
                refId='A',
            ),
        ],
        id=1,
        yAxes=G.YAxes(
            G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
    )
    stream = StringIO()
    _gen.write_dashboard(graph, stream)
    assert stream.getvalue() != ''
Exemplo n.º 9
0
def test_serialization_zabbix_target():
    """Serializing a graph doesn't explode."""
    graph = G.Graph(
        title="CPU Usage",
        dataSource="Zabbix data source",
        targets=[
            Z.zabbixMetricTarget(group="Zabbix Group",
                                 host="Zabbix Host",
                                 application="CPU",
                                 item="/CPU (load)/",
                                 functions=[
                                     Z.ZabbixSetAliasFunction("View alias"),
                                 ]),
        ],
        id=1,
        yAxes=G.YAxes(
            G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
    )
    stream = StringIO()
    _gen.write_dashboard(graph, stream)
    assert stream.getvalue() != ''
Exemplo n.º 10
0
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.YAxes(
                                 G.YAxis(format=G.OPS_FORMAT),
                                 G.YAxis(format=G.SHORT_FORMAT),
                             ),
                             **kwargs))
Exemplo n.º 11
0
def test_serialization_opentsdb_target():
    """Serializing a graph doesn't explode."""
    graph = G.Graph(
        title="CPU Usage",
        dataSource="OpenTSDB data source",
        targets=[
            OpenTSDBTarget(metric='cpu',
                           alias='$tag_instance',
                           filters=[
                               OpenTSDBFilter(value='*',
                                              tag='instance',
                                              type='wildcard',
                                              groupBy=True),
                           ]),
        ],
        id=1,
        yAxes=G.YAxes(
            G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds / second"),
            G.YAxis(format=G.SHORT_FORMAT),
        ),
    )
    stream = StringIO()
    _gen.write_dashboard(graph, stream)
    assert stream.getvalue() != ''
Exemplo n.º 12
0
 def yaxis(self, **kw):
     self.yAxes = gf.YAxes(left=gf.YAxis(**kw))