Skip to main content

Library for building Grafana dashboards

Project description

==========
grafanalib
==========

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

Do you like `Grafana <http://grafana.org/>`_ 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:

.. code-block:: python

import itertools

from grafanalib.core import *


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',
),
],
yAxes=[
YAxis(format=OPS_FORMAT),
YAxis(format=SHORT_FORMAT),
],
alert=Alert(
name="Too many 500s on Nginx",
message="More than 5 QPS of 500s on Nginx for 5 minutes",
alertConditions=[
AlertCondition(
Target(
expr='sum(irate(nginx_http_requests_total{job="default/frontend",status=~"5.."}[1m]))',
legendFormat="5xx",
refId='A',
),
timeRange=TimeRange("5m", "now"),
evaluator=GreaterThan(5),
operator=OP_AND,
reducerType=RTYPE_SUM,
),
],
)
),
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',
),
],
yAxes=single_y_axis(format=SECONDS_FORMAT),
),
]),
],
).auto_panel_ids()

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 <grafanalib/weave.py>`_ 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:

.. code-block:: console

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

Installation
============

grafanalib is just a Python package, so:

.. code-block:: console

$ 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.

`gfdatasource`
==============

This module also provides a script and docker image which can configure grafana
with new sources, or enable app plugins.

The script answers the `--help` with full usage information, but basic
invocation looks like the this:

```
<gfdatasource> --grafana-url http://grafana. datasource --data-source-url http://datasource

<gfdatasource> --grafana-url http://grafana. app --id my-plugin
```


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.3.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grafanalib-0.3.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for grafanalib-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6fec693b3291dfa53480d45d4719a18c1beb55b4071e86629eecec76160f299f
MD5 e4b8c260266093d90cdbe86791d0e287
BLAKE2b-256 331a98f6a01f5b5f8888a00ff7d7d1b661ec618393496ffafc9900d7974f63f0

See more details on using hashes here.

File details

Details for the file grafanalib-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for grafanalib-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b76852ee452e86a2cb31e21e62a3e0d5a8030af9ec37c5f63042f4d5426424b5
MD5 613ede1afe2436ae87c61f93cf7e5908
BLAKE2b-256 f48d9b1b23f4fbc3a120b83cad4f68f811072b80f61ed3f00181dfb9c3bc69cf

See more details on using hashes here.

Supported by

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