Skip to main content

Library for building Grafana dashboards

Project description

https://circleci.com/gh/weaveworks/grafanalib.svg?style=shield

Do you like Grafana but wish you could version your dashboard configuration? Do you find yourself repeating common patterns? If so, grafanalib is for you.

grafanalib lets you generate Grafana dashboards from simple Python scripts.

Writing dashboards

The following will configure a dashboard with a single row, with one QPS graph broken down by status code and another latency graph showing median and 99th percentile latency:

import itertools

from grafanalib.core import *


GRAPH_ID = itertools.count(1)


dashboard = Dashboard(
  title="Frontend Stats",
  rows=[
    Row(panels=[
      Graph(
        title="Frontend QPS",
        dataSource='My Prometheus',
        targets=[
          Target(
            expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"1.."}[1m]))',
            legendFormat="1xx",
            refId='A',
          ),
          Target(
            expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"2.."}[1m]))',
            legendFormat="2xx",
            refId='B',
          ),
          Target(
            expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"3.."}[1m]))',
            legendFormat="3xx",
            refId='C',
          ),
          Target(
            expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"4.."}[1m]))',
            legendFormat="4xx",
            refId='D',
          ),
          Target(
            expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
            legendFormat="5xx",
            refId='E',
          ),
        ],
        id=next(GRAPH_ID),
        yAxes=[
          YAxis(format=OPS_FORMAT),
          YAxis(format=SHORT_FORMAT),
        ],
      ),
      Graph(
        title="Frontend latency",
        dataSource='My Prometheus',
        targets=[
          Target(
            expr='histogram_quantile(0.5, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
            legendFormat="0.5 quantile",
            refId='A',
          ),
          Target(
            expr='histogram_quantile(0.99, sum(irate(nginx_http_request_duration_seconds_bucket{job="default/frontend"}[1m])) by (le))',
            legendFormat="0.99 quantile",
            refId='B',
          ),
        ],
        id=next(GRAPH_ID),
        yAxes=[
          YAxis(
            format=SECONDS_FORMAT,
          ),
          YAxis(
            format=SHORT_FORMAT,
            show=False,
          )
        ],
      ),
    ]),
  ],
)

There is a fair bit of repetition here, but once you figure out what works for your needs, you can factor that out. See our Weave-specific customizations for inspiration.

Generating dashboards

If you save the above as frontend.dashboard.py (the suffix must be .dashboard.py), you can then generate the JSON dashboard with:

$ generate-dashboard -o frontend.json frontend.dashboard.py

Installation

grafanalib is just a Python package, so:

$ pip install grafanalib

Support

This library is in its very early stages. We’ll probably make changes that break backwards compatibility, although we’ll try hard not to.

grafanalib works with Python 3.4 and 3.5.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grafanalib-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

grafanalib-0.1.2-py2-none-any.whl (10.5 kB view details)

Uploaded Python 2

File details

Details for the file grafanalib-0.1.2.tar.gz.

File metadata

  • Download URL: grafanalib-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for grafanalib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 38d88170712904365e48e01e97cfa81ced1f8163b5e481aa5df576e959d17e21
MD5 bbe86b7647cb93b2fb16fb90da6df495
BLAKE2b-256 2d88618cad77c7ca6e5c19aff2fe7c576c57c1e39a63e5504f9749401c5aeab7

See more details on using hashes here.

File details

Details for the file grafanalib-0.1.2-py2-none-any.whl.

File metadata

File hashes

Hashes for grafanalib-0.1.2-py2-none-any.whl
Algorithm Hash digest
SHA256 5e7e262f64d3415972214982560d75bdf09843fae15ed63fb358e3faffa6bfd6
MD5 48bff961057e8626363f23d4654c8ec1
BLAKE2b-256 ddbc0ab1d0b9fa7528ccfd366b1e7c777f56476a372de023490d4ac3307e2bb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page