def test_row_show_title():
    row = G.Row().to_json_data()
    assert row['title'] == 'New row'
    assert not row['showTitle']

    row = G.Row(title='My title').to_json_data()
    assert row['title'] == 'My title'
    assert row['showTitle']

    row = G.Row(title='My title', showTitle=False).to_json_data()
    assert row['title'] == 'My title'
    assert not row['showTitle']
    def run(self):
        templateList = [
            G.Template(default="",
                       dataSource="default",
                       name="serverid",
                       label="ServerID",
                       query="label_values(serverid)")
        ]

        dashboard = G.Dashboard(title=self.options.title,
                                templating=G.Templating(list=templateList))

        # Simple table processing - could be enhanced to use GridPos etc.
        for metric in metrics:
            if 'section' in metric:
                dashboard.rows.append(
                    G.Row(title=metric['section'], showTitle=True))
                continue
            if 'row' in metric:
                dashboard.rows.append(G.Row(title='', showTitle=False))
                continue
            graph = G.Graph(title=metric['title'],
                            dataSource='default',
                            maxDataPoints=1000,
                            legend=G.Legend(show=True,
                                            alignAsTable=True,
                                            min=True,
                                            max=True,
                                            avg=True,
                                            current=True,
                                            total=True,
                                            sort='max',
                                            sortDesc=True),
                            yAxes=G.single_y_axis())
            ref_id = 'A'
            for texp in metric['expr']:
                graph.targets.append(G.Target(expr=texp, refId=ref_id))
                ref_id = chr(ord(ref_id) + 1)
            dashboard.rows[-1].panels.append(graph)

        # Auto-number panels - returns new dashboard
        dashboard = dashboard.auto_panel_ids()

        s = io.StringIO()
        write_dashboard(dashboard, s)
        print("""{
        "dashboard": %s
        }
        """ % s.getvalue())
Exemple #3
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'
Exemple #4
0
def test_auto_refids():
    """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])",
                    dataSource="My data source",
                    targets=[
                        G.Target(
                            expr='whatever #Q',
                            legendFormat='{{namespace}}',
                        ),
                        G.Target(
                            expr='hidden whatever',
                            legendFormat='{{namespace}}',
                            refId='Q',
                            hide=True
                        ),
                        G.Target(
                            expr='another target'
                        ),
                    ],
                    yAxes=[
                        G.YAxis(format=G.SHORT_FORMAT, label="CPU seconds"),
                        G.YAxis(format=G.SHORT_FORMAT),
                    ],
                ).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'
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.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
Exemple #6
0
def Row(
    panels, height=None, title='Dashboard Row', showTitle=False
):
    assert isinstance(height, (type(None), int))
    return core.Row(
        panels=panels, height=height, title=title, showTitle=showTitle,
        titleSize='h6', editable=False,
    )
Exemple #7
0
def REDRow(namespace, graphName, job, rule_root="job:", metric_root="request", extra_conditions="", collapse=False):
    return G.Row(
        title='%s QPS & Latency' % (graphName, ),
        collapse=collapse,
        panels=[
            QPSGraph(namespace, graphName, job, metric_root, extra_conditions),
            LatencyGraph(namespace, graphName, job, rule_root, metric_root, extra_conditions),
        ]
    )
Exemple #8
0
def _row(title):
    return core.Row(panels=[
        core.Graph(title=title,
                   dataSource='prometheus',
                   targets=[
                       core.Target(
                           expr=title,
                           legendFormat='{{namespace}}',
                       ),
                   ],
                   yAxes=[
                       core.YAxis(format=core.NO_FORMAT),
                       core.YAxis(format=core.SHORT_FORMAT),
                   ])
    ])
Exemple #9
0
def test_auto_refids():
    """
    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="metric %d" % i)
                             for i in range(53)],
                ).auto_ref_ids()
            ]),
        ],
    )
    assert dashboard.rows[0].panels[0].targets[0].refId == 'A'
    assert dashboard.rows[0].panels[0].targets[25].refId == 'Z'
    assert dashboard.rows[0].panels[0].targets[26].refId == 'AA'
    assert dashboard.rows[0].panels[0].targets[51].refId == 'AZ'
    assert dashboard.rows[0].panels[0].targets[52].refId == 'BA'
def dashboard():
    PROMETHEUS = "prometheus"
    return G.Dashboard(
        title="S4",
        rows=[
            G.Row(panels=[
                G.Graph(
                    title="Signups",
                    dataSource=PROMETHEUS,
                    xAxis=X_TIME,
                    yAxes=[
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                    ],
                    targets=[
                        G.Target(
                            expr='wormhole_signup_started{pod=~"s4-signup.*"}',
                            legendFormat="Wormhole Signups Started",
                            refId="A",
                        ),
                        G.Target(
                            expr='wormhole_signup_success{pod=~"s4-signup.*"}',
                            legendFormat="Wormhole Signups Completed",
                            refId="B",
                        ),
                        G.Target(
                            expr='wormhole_signup_failure{pod=~"s4-signup.*"}',
                            legendFormat="Wormhole Signups Failed",
                            refId="C",
                        ),
                    ],
                ),
                G.Graph(
                    title="Usage",
                    dataSource=PROMETHEUS,

                    # Stack the connection graphs on each other, revealing
                    # both a total and a distribution across different grid
                    # router instances.
                    stack=True,
                    tooltip=G.Tooltip(
                        valueType=G.INDIVIDUAL,
                    ),

                    xAxis=X_TIME,
                    yAxes=[
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                    ],
                    targets=[
                        G.Target(
                            expr="grid_router_connections",
                            legendFormat="Tahoe-LAFS Connections",
                            refId="D",
                        ),
                    ],
                ),
            ]),
            G.Row(
                title="Cluster",
                panels=[
                    cpu_usage(PROMETHEUS, ["1m", "5m", "10m"]),
                    memory_usage(PROMETHEUS),
                    network_usage(PROMETHEUS),
                    filesystem_usage(PROMETHEUS),
                ],
            ),
            G.Row(panels=[
                G.SingleStat(
                    title='Current Customer Deployments',
                    dataSource='prometheus',
                    valueName='current',
                    sparkline=G.SparkLine(show=True),
                    targets=[
                        G.Target(
                            expr='s4_deployment_gauge',
                            refId="E",
                        ),
                    ],
                ),
                G.SingleStat(
                    title='Unhandled Errors',
                    dataSource='prometheus',
                    valueName='current',
                    sparkline=G.SparkLine(show=True),
                    targets=[
                        G.Target(
                            expr='s4_unhandled_error_counter',
                            refId="F",
                        ),
                    ],
                ),
            ]),
        ],
    ).auto_panel_ids()
Exemple #11
0
        yAxes=g.single_y_axis(format=g.SHORT_FORMAT, logBase=10),
    ),
]

# The final dashboard must be named 'dashboard' so that grafanalib will find it.
dashboard = g.Dashboard(
    title="Master dashboard",
    time=g.Time("now-30d", "now"),
    templating=g.Templating(list=[
        # Make it possible to use $source as a source.
        g.Template(name="source", type="datasource", query="prometheus")
    ]),
    rows=[
        g.Row(
            title="Clusterloader",
            height=DEFAULT_PANEL_HEIGHT,
            panels=CLUSTERLOADER_PANELS,
        ),
        g.Row(
            title="Overall cluster health",
            height=DEFAULT_PANEL_HEIGHT,
            panels=HEALTH_PANELS,
        ),
        g.Row(title="etcd", height=DEFAULT_PANEL_HEIGHT, panels=ETCD_PANELS),
        g.Row(title="kube-apiserver",
              height=DEFAULT_PANEL_HEIGHT,
              panels=APISERVER_PANELS),
        g.Row(
            title="kube-controller-manager",
            height=DEFAULT_PANEL_HEIGHT,
            panels=[
Exemple #12
0
    "3xx": BLUE,
    "4xx": ORANGE,
    "5xx": RED,
    "success": GREEN,
    "error": RED,
}

dashboard = G.Dashboard(
    title='UCDAPI',
    rows=[
        G.Row(panels=[
            G.SingleStat(
                title='Pods Up',
                dataSource='prometheus',
                valueName='current',
                sparkline=G.SparkLine(show=True),
                targets=[
                    G.Target(
                        expr='count by(service) (up{service="ucdapi"} == 1)', )
                ]),
        ]),
        G.Row(panels=[
            G.Graph(
                title='HTTP RPS',
                dataSource='prometheus',
                targets=[
                    G.Target(
                        expr=
                        'service_status:http_request_duration_seconds_count:irate{service="ucdapi",status_code=~"1.."}',
                        legendFormat='1xx',
                        refId='A'),
    def run(self):
        templateList = []
        if self.options.use_sdp:
            templateList.append(
                G.Template(default="1",
                           dataSource="default",
                           name="sdpinst",
                           label="SDPInstance",
                           query="label_values(sdpinst)"))
        if self.options.customer:
            templateList.append(
                G.Template(default="1",
                           dataSource="default",
                           name="customer",
                           label="Customer",
                           query="label_values(customer)"))
        templateList.append(
            G.Template(default="",
                       dataSource="default",
                       name="serverid",
                       label="ServerID",
                       query="label_values(serverid)"))

        dashboard = G.Dashboard(title=self.options.title,
                                templating=G.Templating(list=templateList))

        for metric in metrics:
            if 'section' in metric:
                dashboard.rows.append(
                    G.Row(title=metric['section'], showTitle=True))
                continue
            if 'row' in metric:
                dashboard.rows.append(G.Row(title='', showTitle=False))
                continue
            if 'type' in metric and metric['type'] == 'gauge':
                pass
                # text = G.Text(title=metric['title'],
                #                 dataSource='default')
                # dashboard.rows[-1].panels.append(G.Text)
            else:
                yAxis = G.single_y_axis(format="short")
                if 'yformat' in metric:
                    yAxis = G.single_y_axis(format=metric['yformat'])
                graph = G.Graph(title=metric['title'],
                                dataSource='default',
                                maxDataPoints=1000,
                                legend=G.Legend(show=True,
                                                alignAsTable=True,
                                                min=True,
                                                max=True,
                                                avg=True,
                                                current=True,
                                                total=True,
                                                sort='max',
                                                sortDesc=True),
                                yAxes=yAxis)
                refId = 'A'
                for targ in metric['target']:
                    texp = targ['expr']
                    legend = "instance {{instance}}, serverid {{serverid}}"
                    if 'legend' in targ:
                        legend += ' %s' % targ['legend']
                    # Remove SDP
                    if not self.options.use_sdp:
                        texp = texp.replace('sdpinst="$sdpinst",', '')
                    if self.options.customer:
                        texp = texp.replace('{', '{customer="$customer",')
                    graph.targets.append(
                        G.Target(expr=texp, legendFormat=legend, refId=refId))
                    refId = chr(ord(refId) + 1)
                dashboard.rows[-1].panels.append(graph)

        # Auto-number panels - returns new dashboard
        dashboard = dashboard.auto_panel_ids()

        s = io.StringIO()
        write_dashboard(dashboard, s)
        print("""{
        "dashboard": %s
        }
        """ % s.getvalue())
 G.Row(
     title="Retrieval Stats",
     collapse=True,
     panels=[
         common.PromGraph(
             title="Retrieval sent batches",
             expressions=[
                 ('{{url}}',
                  'sum(rate(prometheus_remote_storage_sent_batch_duration_seconds_count[1m])) by (url)'
                  ),
             ],
         ),
         common.PromGraph(
             title="Retrieval batch latency",
             expressions=[
                 ('{{url}} 99th',
                  'histogram_quantile(0.99, sum(rate(prometheus_remote_storage_sent_batch_duration_seconds_bucket[2m])) by (url, le)) * 1e3'
                  ),
                 ('{{url}} 50th',
                  'histogram_quantile(0.50, sum(rate(prometheus_remote_storage_sent_batch_duration_seconds_bucket[2m])) by (url, le)) * 1e3'
                  ),
                 ('{{url}} mean',
                  '(sum(rate(prometheus_remote_storage_sent_batch_duration_seconds_sum[2m])) by (url) /  sum(rate(prometheus_remote_storage_sent_batch_duration_seconds_count[2m])) by (url)) * 1e3'
                  ),
             ],
             yAxes=common.LATENCY_AXES,
         ),
         common.PromGraph(
             title="Retrieval sent samples",
             expressions=[
                 ('{{url}} success',
                  'sum(rate(prometheus_remote_storage_succeeded_samples_total[1m])) by (url)'
                  ),
                 ('{{url}} dropped',
                  'sum(rate(prometheus_remote_storage_dropped_samples_total[1m])) by (url)'
                  ),
                 ('{{url}} retried',
                  'sum(rate(prometheus_remote_storage_retried_samples_total[1m])) by (url)'
                  ),
                 ('{{url}} failure',
                  'sum(rate(prometheus_remote_storage_failed_samples_total[1m])) by (url)'
                  ),
             ],
         ),
         common.PromGraph(
             title="Queue",
             expressions=[
                 ('{{url}}: queue length',
                  'sum(prometheus_remote_storage_pending_samples) by (url)'
                  ),
                 ('{{url}}: lag',
                  'max(time()-prometheus_remote_storage_queue_highest_sent_timestamp_seconds) by (url)'
                  ),
                 ('{{url}}: shards',
                  'max(prometheus_remote_storage_shards) by (url)'),
             ],
         ),
     ],
 ),
Exemple #15
0
 G.Row(title="Service status",
       panels=[
           G.SingleStat(
               editable=True,
               colorBackground=True,
               colorValue=False,
               colors=[G.ORANGE, G.GREEN, G.RED],
               dataSource="Prometheus",
               gauge=G.Gauge(
                   maxValue=100,
                   minValue=0,
                   show=False,
                   thresholdLabels=False,
                   thresholdMarkers=True,
               ),
               title=app["name"],
               targets=[
                   G.Target(
                       expr='up{{instance="{hostname}:{port}"}}'.format(
                           hostname=app["hostname"], port=app["port"]),
                       intervalFactor=2,
                       legendFormat="",
                       step=4,
                   )
               ],
               span=2,
               thresholds="0.1",
               transparent=True,
               valueMaps=[
                   G.ValueMap(op="=", text="N/A", value="null"),
                   G.ValueMap(op="=", text="Down", value="0"),
                   G.ValueMap(op="=", text="Up", value="1"),
               ],
               sparkline=G.SparkLine(
                   fillColor=G.RGBA(31, 118, 109, 0.18),
                   full=False,
                   lineColor=G.RGB(31, 120, 193),
                   show=False,
               ),
               rangeMaps=[G.RangeMap(start=None, text="N/A", end=None)],
               valueName="current",
           ) for app in APPS
       ])
Exemple #16
0
import common

dashboard = common.Dashboard(
    uid='chunks',
    title="Cortex > Chunks",
    rows=[
        G.Row(
            panels=[
                common.PromGraph(
                    title="Number of chunks (in memory, in ingesters)",
                    expressions=[
                        ('', 'sum(cortex_ingester_memory_chunks{job="cortex/ingester"})'),
                    ],
                ),
                common.PromGraph(
                    title="Chunks per series",
                    expressions=[
                        (
                            '',
                            'sum(cortex_ingester_memory_chunks{job="cortex/ingester"}) / sum(cortex_ingester_memory_series{job="cortex/ingester"})'
                        ),
                    ],
                ),
            ]
        ),
        G.Row(
            panels=[
                common.PromGraph(
                    title="Chunk Size Bytes (on flush)",
                    expressions=[
                        (
Exemple #17
0
 G.Row(
     title="Configs",
     collapse=True,
     panels=[
         common.PromGraph(
             title="Known Configurations",
             expressions=[
                 ("Configurations",
                  'max(cortex_configs{job="cortex/ruler"})'),
                 ("{{status}}",
                  'max by(status)(cortex_alertmanager_configs{job="cortex/alertmanager"})'
                  ),
             ],
         ),
         common.QPSGraph('cortex_configs', 'Configs', 'cortex/ruler'),
         common.PromGraph(
             title="Configs Latency",
             expressions=[
                 ("99th centile",
                  'histogram_quantile(0.99, sum(rate(cortex_configs_request_duration_seconds_bucket{job="cortex/ruler"}[2m])) by (le)) * 1e3'
                  ),
                 ("50th centile",
                  'histogram_quantile(0.50, sum(rate(cortex_configs_request_duration_seconds_bucket{job="cortex/ruler"}[2m])) by (le)) * 1e3'
                  ),
                 ("Mean",
                  'sum(rate(cortex_configs_request_duration_seconds_sum{job="cortex/ruler"}[2m])) / sum(rate(cortex_configs_request_duration_seconds_count{job="cortex/ruler"}[2m])) * 1e3'
                  ),
             ],
             yAxes=common.LATENCY_AXES,
         ),
     ]),
 uid='am',
 title="Cortex > Alertmanager",
 rows=[
     G.Row(
         title='Operations',
         panels=[
             common.PromGraph(
                 title="Alerts",
                 expressions=[
                     ("{{instance}} {{status}}",
                      'sum by (instance, status)(rate(alertmanager_alerts_received_total{job="cortex/alertmanager"}[2m]))'
                      ),
                     ("{{instance}} invalid",
                      'sum by (instance, status)(rate(alertmanager_alerts_invalid_total{job="cortex/alertmanager"}[2m]))'
                      ),
                 ],
                 yAxes=common.OPS_AXIS,
             ),
             common.PromGraph(
                 title="Notifications",
                 expressions=[
                     ("{{integration}}",
                      'sum by (integration)(rate(alertmanager_notifications_total{job="cortex/alertmanager"}[2m]))'
                      ),
                 ],
                 yAxes=common.OPS_AXIS,
             ),
         ]),
     G.Row(
         title='Alertmanager fetching configs',
         collapse=True,
def dashboard():
    PROMETHEUS = "prometheus"
    return G.Dashboard(
        title="S4",
        rows=[
            G.Row(panels=[
                G.Graph(
                    title="Signups",
                    dataSource=PROMETHEUS,
                    xAxis=X_TIME,
                    yAxes=[
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                    ],
                    targets=[
                        G.Target(
                            # Filter down to just the signup pod since that's
                            # the only one where this metric value is
                            # meaningful.  Some other pods report a 0 value
                            # for this metric because they happen to import
                            # the Python code that defines the object
                            # representing it.
                            #
                            # Also, sum over the selected series to account
                            # for pod replacement.
                            expr='sum(wormhole_signup_started{pod=~"s4-signup.*"})',
                            legendFormat="Wormhole Signups Started",
                            refId="A",
                        ),
                        G.Target(
                            expr='sum(wormhole_signup_success{pod=~"s4-signup.*"})',
                            legendFormat="Wormhole Signups Completed",
                            refId="B",
                        ),
                        G.Target(
                            expr='sum(wormhole_signup_failure{pod=~"s4-signup.*"})',
                            legendFormat="Wormhole Signups Failed",
                            refId="C",
                        ),
                    ],
                ),
                G.Graph(
                    title="Usage",
                    dataSource=PROMETHEUS,

                    # Stack the connection graphs on each other, revealing
                    # both a total and a distribution across different grid
                    # router instances.
                    stack=True,
                    tooltip=G.Tooltip(
                        valueType=G.INDIVIDUAL,
                    ),

                    xAxis=X_TIME,
                    yAxes=[
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                        G.YAxis(
                            format="none",
                            label="Count",
                        ),
                    ],
                    targets=[
                        G.Target(
                            expr="grid_router_connections",
                            legendFormat="Tahoe-LAFS Connections",
                            refId="D",
                        ),
                    ],
                ),
                last_convergence(PROMETHEUS),
            ]),
            G.Row(
                title="Cluster",
                panels=[
                    cpu_usage(PROMETHEUS, ["1m", "5m", "10m"]),
                    memory_usage(PROMETHEUS),
                    network_usage(PROMETHEUS),
                    filesystem_usage(PROMETHEUS),
                ],
            ),
            G.Row(
                title="Cluster2",
                panels=[
                    process_open_fds(PROMETHEUS),
                ],
            ),
            G.Row(panels=[
                tahoe_lafs_transfer_rate(PROMETHEUS),
                s4_customer_deployments(PROMETHEUS),
                unhandled_errors(PROMETHEUS),
            ]),
        ],
    ).auto_panel_ids()
Exemple #20
0
 common.REDRow('cortex', 'Querier read', 'cortex/querier'),
 G.Row(
     title="Ingester",
     panels=[
         common.PromGraph(
             title="Ingester read QPS",
             expressions=[
                 ('{{route}}: {{status_code}}',
                  'sum(rate(cortex_request_duration_seconds_count{job="cortex/ingester", route!="/cortex.Ingester/Push"}[1m])) by (route, status_code)'
                  ),
             ],
             yAxes=common.OPS_AXIS,
         ),
         common.PromGraph(
             title="Ingester read latency",
             expressions=[
                 ('{{route}}: 99th centile',
                  'job_route:cortex_request_duration_seconds:99quantile{job="cortex/ingester", route!="/cortex.Ingester/Push"} * 1e3'
                  ),
                 ('{{route}}: 50th centile',
                  'job_route:cortex_request_duration_seconds:50quantile{job="cortex/ingester", route!="/cortex.Ingester/Push"} * 1e3'
                  ),
                 ('{{route}}: Mean',
                  'sum(rate(cortex_request_duration_seconds_sum{job="cortex/ingester", route!="/cortex.Ingester/Push"}[2m])) by (route) * 1e3 / sum(rate(cortex_request_duration_seconds_count{job="cortex/ingester", route!="/cortex.Ingester/Push"}[2m])) by (route)'
                  ),
             ],
             yAxes=common.LATENCY_AXES,
         ),
     ],
 ),
 G.Row(
Exemple #21
0
def make(prefix, title):
    def target(expr, **kw):
        return G.Target(expr=expr.format(prefix), **kw)

    return G.Dashboard(
        title=title,
        rows=[
            G.Row(panels=[
                G.SingleStat(
                    title='Pods up (web)',
                    dataSource='prometheus',
                    valueName='current',
                    sparkline=G.SparkLine(show=True),
                    targets=[
                        target(
                            expr=
                            'count by(service) (up{{service="{}-isaacranks-web"}} == 1)'
                        )
                    ]),
                G.SingleStat(
                    title='Pods up (rebuild)',
                    dataSource='prometheus',
                    valueName='current',
                    sparkline=G.SparkLine(show=True),
                    targets=[
                        target(
                            expr=
                            'count by(service) (up{{service="{}-isaacranks-rebuild"}} == 1)'
                        )
                    ]),
            ]),
            G.Row(panels=[
                G.Graph(
                    title='HTTP RPS',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"1.."}}',
                            legendFormat='1xx',
                            refId='A'),
                        target(
                            expr=
                            'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"2.."}}',
                            legendFormat='2xx',
                            refId='B'),
                        target(
                            expr=
                            'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"3.."}}',
                            legendFormat='3xx',
                            refId='C'),
                        target(
                            expr=
                            'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"4.."}}',
                            legendFormat='4xx',
                            refId='D'),
                        target(
                            expr=
                            'service_status:http_request_duration_seconds_count:irate{{service="{}-isaacranks-web",status_code=~"5.."}}',
                            legendFormat='5xx',
                            refId='E'),
                    ],
                    aliasColors=ALIAS_COLORS,
                    yAxes=[
                        G.YAxis(format=G.OPS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ],
                    nullPointMode=G.NULL_AS_ZERO,
                    stack=True,
                    lineWidth=0,
                    fill=10,
                    tooltip=G.Tooltip(valueType=G.INDIVIDUAL)),
                G.Graph(
                    title='HTTP latency',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service:http_request_duration_seconds:50p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.5q',
                            refId='A'),
                        target(
                            expr=
                            'service:http_request_duration_seconds:90p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.9q',
                            refId='B'),
                        target(
                            expr=
                            'service:http_request_duration_seconds:99p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.99q',
                            refId='C'),
                    ],
                    aliasColors=ALIAS_COLORS,
                    yAxes=[
                        G.YAxis(format=G.MILLISECONDS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ]),
            ]),
            G.Row(panels=[
                G.Graph(
                    title='Ballots',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service_version:isaacranks_ballot_generation_seconds_count:irate{{service="{}-isaacranks-web"}}',
                            legendFormat='{{version}}',
                            refId='A')
                    ],
                    yAxes=[
                        G.YAxis(format=G.OPS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False),
                    ],
                    nullPointMode=G.NULL_AS_ZERO,
                    stack=True,
                    lineWidth=0,
                    fill=10,
                    tooltip=G.Tooltip(valueType=G.INDIVIDUAL)),
                G.Graph(
                    title='Ballot latency',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service:isaacranks_ballot_generation_seconds:50p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.5q',
                            refId='A'),
                        target(
                            expr=
                            'service:isaacranks_ballot_generation_seconds:90p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.9q',
                            refId='B'),
                        target(
                            expr=
                            'service:isaacranks_ballot_generation_seconds:99p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.99q',
                            refId='C'),
                    ],
                    yAxes=[
                        G.YAxis(format=G.MILLISECONDS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ]),
            ]),
            G.Row(panels=[
                G.Graph(
                    title='Votes',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service_version:isaacranks_vote_casting_seconds_count:irate{{service="{}-isaacranks-web"}}',
                            legendFormat='{{version}}',
                            refId='A')
                    ],
                    yAxes=[
                        G.YAxis(format=G.OPS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ],
                    nullPointMode=G.NULL_AS_ZERO,
                    stack=True,
                    lineWidth=0,
                    fill=10,
                    tooltip=G.Tooltip(valueType=G.INDIVIDUAL)),
                G.Graph(
                    title='Vote latency',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'service:isaacranks_vote_casting_seconds:50p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.5q',
                            refId='A'),
                        target(
                            expr=
                            'service:isaacranks_vote_casting_seconds:90p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.9q',
                            refId='B'),
                        target(
                            expr=
                            'service:isaacranks_vote_casting_seconds:99p{{service="{}-isaacranks-web"}} * 1000',
                            legendFormat='0.99q',
                            refId='C'),
                    ],
                    yAxes=[
                        G.YAxis(format=G.MILLISECONDS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ]),
            ]),
            G.Row(panels=[
                G.Graph(
                    title='Time since last rebuild',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'time() - (isaacranks_last_rebuild_timestamp{{service="{}-isaacranks-rebuild"}} != 0)',
                            legendFormat='Age')
                    ],
                    legend=G.Legend(current=True),
                    yAxes=[
                        G.YAxis(format=G.SECONDS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ]),
                G.Graph(
                    title='Rebuild duration',
                    dataSource='prometheus',
                    targets=[
                        target(
                            expr=
                            'isaacranks_last_rebuild_duration_seconds{{service="{}-isaacranks-rebuild"}} != 0',
                            legendFormat='Duration')
                    ],
                    legend=G.Legend(current=True),
                    yAxes=[
                        G.YAxis(format=G.SECONDS_FORMAT),
                        G.YAxis(format=G.SHORT_FORMAT, show=False)
                    ]),
            ])
        ]).auto_panel_ids()
import common

dashboard = common.Dashboard(
    uid='cortex-blocks',
    title="Cortex > Blocks",
    rows=[
        G.Row(
            title="Data",
            panels=[
                common.PromGraph(
                    title="Number of series in memory, in ingesters",
                    expressions=[
                        ('',
                         'sum(cortex_ingester_memory_series{job="cortex/ingester"})'
                         ),
                    ],
                ),
                common.PromGraph(
                    title="Head chunks",
                    expressions=[
                        ('{{instance}}', 'cortex_ingester_tsdb_head_chunks'),
                    ],
                ),
            ]),
        G.Row(
            title="Resources",
            panels=[
                common.PromGraph(
                    title="Memory Usage",
                    expressions=[
                        ('{{pod}}',