Skip to main content

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

Project description


ci-tests Test suite code coverage license pypi-downloads python-versions status pypi-version Supported Grafana versions

About

grafana-wtf - grep through all Grafana entities in the spirit of git-wtf, see also Introduction to GIT WTF.

Synopsis

Search Grafana (dashboards and datasources) for string “weatherbase”.

grafana-wtf find weatherbase

Display 50 most recent changes across all dashboards.

grafana-wtf log --number=50

Explore dashboards and datasources in more detail.

grafana-wtf explore dashboards
grafana-wtf explore datasources

Explore plugins.

grafana-wtf plugins list
grafana-wtf plugins status

Run with Docker:

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

# Access Grafana instance with authentication.
docker run --rm -it \
    --env GRAFANA_URL="https://grafana.example.org/grafana" \
    --env GRAFANA_TOKEN="eyJrIjoiWHg...dGJpZCI6MX0=" \
    ghcr.io/grafana-toolbox/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

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

Configuration

Grafana connection

To configure to which Grafana instance to connect to, and how to authenticate, use the --grafana-url and --grafana-token command line options.

Alternatively, before running grafana-wtf, you can define URL and access token of your Grafana instance by using environment variables:

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

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

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

Caching

grafana-wtf will cache HTTP responses for 60 minutes by default, in order to save resources, by not hitting the server each server. You can configure that setting by using the --cache-ttl option, or the CACHE_TTL environment variable.

When invoking the program with the --drop-cache option, it will drop its cache upfront.

Usage

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]}'

How to find dashboards using specific data sources?

# Display all dashboards which use a specific data source, filtered by data source name.
grafana-wtf explore dashboards --format=json | jq '.[] | select(.datasources | .[].name=="<datasource_name>")'

# Display all dashboards using data sources with a specific type. Here: InfluxDB.
grafana-wtf explore dashboards --format=json | jq '.[] | select(.datasources | .[].type=="influxdb")'

How to list all queries used in all dashboards?

grafana-wtf explore dashboards --data-details --queries-only --format=json | \
    jq '.[].details | values[] | .[] | .expr,.jql,.query,.rawSql | select( . != null and . != "" )'

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

Concurrency

Use the --concurrency option, for example --concurrency=5, to enable concurrent downloading per ThreadPoolExecutor.

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/grafana-toolbox/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.24.2.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

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

grafana_wtf-0.24.2-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file grafana_wtf-0.24.2.tar.gz.

File metadata

  • Download URL: grafana_wtf-0.24.2.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grafana_wtf-0.24.2.tar.gz
Algorithm Hash digest
SHA256 5228cbbb56cbcc4eb43b55b5989ef3d79903e66aaf9a71ba8821fcc941c73612
MD5 2450af813a0e95fdd180d89d07f81953
BLAKE2b-256 918255a9499d568dedfa8e0d005f08b8f4bdb3021260b4851fe1be8925d125e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafana_wtf-0.24.2.tar.gz:

Publisher: release-pypi.yml on grafana-toolbox/grafana-wtf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: grafana_wtf-0.24.2-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grafana_wtf-0.24.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d6f7e05fe54b38cf38a336f00db9eba2f46e4a76dce038b99219465c07e7601f
MD5 4a3237427ec633c76edd925c69e3c201
BLAKE2b-256 cde0bc6c072a6a246a2d7f5b5ea6dbb4c798b36b1cea91c4628c104bf05a6083

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafana_wtf-0.24.2-py3-none-any.whl:

Publisher: release-pypi.yml on grafana-toolbox/grafana-wtf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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