Пример #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

    dashboard = G.Dashboard(
        title="Test dashboard",
        panels=[
            G.RowPanel(gridPos=G.GridPos(h=1, w=24, x=0, y=8)),
            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),
                    ),
                    gridPos=G.GridPos(h=1, w=24, x=0, y=8))
        ],
    ).auto_panel_ids()
    assert dashboard.panels[0].id == 1
Пример #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'
Пример #3
0
 def AddPanel(self, panel: core.Panel):
     panel.gridPos = core.GridPos(
         h=8,
         w=12,
         # First bit of panel length.  Alternates between 0 & 1.
         x=bin(len(self.panels))[-1] * 12,
         y=(len(self.panels) // 2) * 8,
     )
     self.panels.append(panel)
Пример #4
0
def dummy_grid_pos() -> G.GridPos:
    return G.GridPos(h=1, w=2, x=3, y=4)
import grafanalib.core as G

dashboard = G.Dashboard(
    title='Test dashboard',
    panels=[
        G.Graph(title='CPU Usage by Namespace',
                dataSource='metricbeat',
                targets=[
                    G.Target(
                        expr='whatever',
                        legendFormat='{{namespace}}',
                        refId='A',
                    ),
                ],
                yAxes=[
                    G.YAxis(format=G.SHORT_FORMAT, label='CPU seconds'),
                    G.YAxis(format=G.SHORT_FORMAT),
                ],
                gridPos=G.GridPos(h=8, w=12, x=0, y=0))
    ],
).auto_panel_ids()