Giter Site home page Giter Site logo

forkkit / grafanalib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weaveworks/grafanalib

0.0 2.0 0.0 316 KB

Python library for building Grafana dashboards

License: Apache License 2.0

Python 59.11% Makefile 2.31% Shell 24.68% Go 5.00% HCL 7.84% Dockerfile 1.06%

grafanalib's Introduction

grafanalib

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:

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 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 2.7, 3.4, 3.5, and 3.6.

Developing

If you're working on the project, and need to build from source, it's done as follows:

$ virtualenv .env
$ . ./.env/bin/activate
$ pip install -e .

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 this:

$ <gfdatasource> --grafana-url http://grafana. datasource --data-source-url http://datasource
$ <gfdatasource> --grafana-url http://grafana. app --id my-plugin

Getting Help

If you have any questions about, feedback for or problems with grafanalib:

Your feedback is always welcome!

grafanalib's People

Contributors

aknuds1 avatar astronaut1712 avatar atopuzov avatar bboreham avatar beanzhou avatar butlerx avatar christine-gong avatar dholbach avatar dmajere avatar fho avatar filippog avatar foot avatar gaell avatar ivan avatar jml avatar jpellizzari avatar kevingessner avatar lalinsky avatar leth avatar lexfrei avatar marccarre avatar mikebryant avatar paulbellamy avatar rade avatar rndstr avatar teran avatar tharvik avatar tomwilkie avatar vthriller avatar xxr3376 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.