Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add python3.8 (current on Ubuntu 20.04) to tox and CircleCI - decouple main github README from grafanalib docs RTD where we can use sphinx' "literalinclude" - fix flake linter issues - make examples run at all - test examples as part of general tests fixes: #55
- Loading branch information
Daniel Holbach
committed
Mar 23, 2020
1 parent
327b386
commit 1b07473
Showing
11 changed files
with
153 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
ignore = E501 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
=============================== | ||
Getting Started with 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: | ||
|
||
.. literalinclude:: example.dashboard.py | ||
:language: python | ||
|
||
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 | ||
<https://github.com/weaveworks/grafanalib/blob/master/grafanalib/weave.py>`_ | ||
for inspiration. | ||
|
||
You can read the entire grafanlib documentation on `readthedocs.io | ||
<https://grafanalib.readthedocs.io/en/latest/>`_. | ||
|
||
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, 3.5, 3.6 and 3.7. | ||
|
||
Developing | ||
========== | ||
If you're working on the project, and need to build from source, it's done as follows: | ||
|
||
.. code-block:: console | ||
$ virtualenv .env | ||
$ . ./.env/bin/activate | ||
$ pip install -e . | ||
Configuring Grafana Datasources | ||
=============================== | ||
|
||
This repo used to contain a program ``gfdatasource`` for configuring | ||
Grafana data sources, but it has been retired since Grafana now has a | ||
built-in way to do it. See https://grafana.com/docs/administration/provisioning/#datasources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'''Run examples.''' | ||
|
||
from contextlib import redirect_stdout | ||
import glob | ||
import io | ||
import os | ||
|
||
from grafanalib import _gen | ||
|
||
|
||
def test_examples(): | ||
'''Run examples in ./examples directory.''' | ||
|
||
examples_dir = os.path.join(os.path.dirname(__file__), 'examples') | ||
examples = glob.glob('{}/*.dashboard.py'.format(examples_dir)) | ||
assert len(examples) == 2 | ||
|
||
stdout = io.StringIO() | ||
for example in examples: | ||
with redirect_stdout(stdout): | ||
ret = _gen.generate_dashboard([example]) | ||
assert ret == 0 | ||
assert stdout.getvalue() != '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters