Skip to main content

Grep through all Grafana entities in the spirit of git-wtf

Project description

https://github.com/panodata/grafana-wtf/workflows/Tests/badge.svg https://img.shields.io/pypi/pyversions/grafana-wtf.svg https://img.shields.io/pypi/status/grafana-wtf.svg https://img.shields.io/pypi/v/grafana-wtf.svg https://pepy.tech/badge/grafana-wtf/month https://img.shields.io/pypi/l/grafana-wtf.svg Supported Grafana versions

grafana-wtf

About

grafana-wtf - grep through all Grafana entities in the spirit of git-wtf.

Synopsis

Search Grafana API for string “weatherbase”.

grafana-wtf find weatherbase

Display 50 most recent changes across all dashboards.

grafana-wtf log --number=50

Run with Docker:

# Access Grafana instance on localhost, without authentication.
docker run --rm -it --env GRAFANA_URL="http://host.docker.internal:3000" ghcr.io/panodata/grafana-wtf grafana-wtf info

# Access Grafana instance with authentication.
docker run --rm -it --env GRAFANA_URL="https://daq.grafana.org/grafana" --env GRAFANA_TOKEN="eyJrIjoiWHg...dGJpZCI6MX0=" ghcr.io/panodata/grafana-wtf grafana-wtf info

Screenshots

grafana-wtf find

https://user-images.githubusercontent.com/453543/51694547-5c78fd80-2001-11e9-96ea-3fcc2e0fb016.png

grafana-wtf log

https://user-images.githubusercontent.com/453543/56455736-87ee5880-6362-11e9-8cd2-c356393d09c4.png

Setup

Install grafana-wtf

pip install grafana-wtf

Configure Grafana

Please take these steps to create an API key with your Grafana instance:

  • Go to https://daq.example.org/grafana/org/apikeys.

  • Choose “New API Key”.

    • Key name: grafana-wtf

    • Role: Admin

  • From the output curl -H "Authorization: Bearer eyJrIjoiWHg...dGJpZCI6MX0=" ..., please take note of the Bearer token. This is your Grafana API key.

Usage

Before running grafana-wtf, define URL and access token of your Grafana instance:

export GRAFANA_URL=https://daq.example.org/grafana/
export GRAFANA_TOKEN=eyJrIjoiWHg...dGJpZCI6MX0=

In order to ignore untrusted SSL certificates, append the ?verify=no query string to the GRAFANA_URL:

export GRAFANA_URL=https://daq.example.org/grafana/?verify=no

General information

# Display a bunch of meta information and statistics.
grafana-wtf info --format=yaml

# Display Grafana version.
grafana-wtf info --format=json | jq -r '.grafana.version'

Explore data sources

How to find unused data sources?

# Display all data sources and the dashboards using them, as well as unused data sources.
grafana-wtf explore datasources --format=yaml

# Display names of unused datasources as a flat list.
grafana-wtf explore datasources --format=json | jq -r '.unused[].datasource.name'

Explore dashboards

How to find dashboards which use non-existing data sources?

# Display some details of all dashboards, including names of missing data sources.
grafana-wtf explore dashboards --format=yaml

# Display only dashboards which have missing data sources, along with their names.
grafana-wtf explore dashboards --format=json | jq '.[] | select( .datasources_missing ) | .dashboard + {ds_missing: .datasources_missing[] | [.name]}'

Searching for strings

Find the string weatherbase throughout all dashboards and data sources:

grafana-wtf find weatherbase

Replacing strings

Replace all occurrences of ldi_v2 with ldi_v3 within dashboard with UID _JJ22OZZk:

grafana-wtf --select-dashboard=_JJ22OZZk replace ldi_v2 ldi_v3

In order to preview the changes, you should use the --dry-run option beforehand:

grafana-wtf --select-dashboard=_JJ22OZZk replace ldi_v2 ldi_v3 --dry-run

Display edit history

Watching out for recent editing activity on any dashboards?

# Display 50 most recent changes across all dashboards.
grafana-wtf log --number=50

Examples

For discovering more command line parameters and their arguments, please invoke grafana-wtf --help and have a look at grafana-wtf examples.

Development

git clone https://github.com/panodata/grafana-wtf
cd grafana-wtf

# Run all tests.
make test

# Run selected tests.
pytest --keepalive -vvv -k test_find_textual

Download files

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

Source Distribution

grafana-wtf-0.15.1.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

grafana_wtf-0.15.1-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file grafana-wtf-0.15.1.tar.gz.

File metadata

  • Download URL: grafana-wtf-0.15.1.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for grafana-wtf-0.15.1.tar.gz
Algorithm Hash digest
SHA256 e1bd86a17c4ad2df00681c28987548680a33e6d8004f28374feab2bb3b691a3d
MD5 26c1ad7255bb39cf23f03eb86e387d3d
BLAKE2b-256 0238b84b261c0021381a91d66edb35bc053bf8d6e0ecc11ec23c26cd818feb35

See more details on using hashes here.

Provenance

File details

Details for the file grafana_wtf-0.15.1-py3-none-any.whl.

File metadata

  • Download URL: grafana_wtf-0.15.1-py3-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for grafana_wtf-0.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0658e50d5de2b26817187040b9cbef8f60bff2bbb3beb286170e80ffce728926
MD5 05def1a05462df6ba1f7ceb66bcc9066
BLAKE2b-256 cdd525fc457ca034379c90bca263e433319d141998510d21f45d0b89a11d8c81

See more details on using hashes here.

Provenance

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