grafana-wtf


Namegrafana-wtf JSON
Version 0.19.1 PyPI version JSON
download
home_pagehttps://github.com/panodata/grafana-wtf
SummaryGrep through all Grafana entities in the spirit of git-wtf
upload_time2024-04-20 19:55:48
maintainerNone
docs_urlNone
authorAndreas Motl
requires_pythonNone
licenseAGPL 3, EUPL 1.2
keywords grafana search index
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ###########
grafana-wtf
###########

|

.. start-badges

|ci-tests| |ci-coverage| |license| |pypi-downloads|
|python-versions| |status| |pypi-version| |grafana-versions|

.. |ci-tests| image:: https://github.com/panodata/grafana-wtf/actions/workflows/tests.yml/badge.svg
    :target: https://github.com/panodata/grafana-wtf/actions/workflows/tests.yml

.. |ci-coverage| image:: https://codecov.io/gh/panodata/grafana-wtf/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/panodata/grafana-wtf
    :alt: Test suite code coverage

.. |python-versions| image:: https://img.shields.io/pypi/pyversions/grafana-wtf.svg
    :target: https://pypi.org/project/grafana-wtf/

.. |status| image:: https://img.shields.io/pypi/status/grafana-wtf.svg
    :target: https://pypi.org/project/grafana-wtf/

.. |pypi-version| image:: https://img.shields.io/pypi/v/grafana-wtf.svg
    :target: https://pypi.org/project/grafana-wtf/

.. |pypi-downloads| image:: https://static.pepy.tech/badge/grafana-wtf/month
    :target: https://pypi.org/project/grafana-wtf/

.. |license| image:: https://img.shields.io/pypi/l/grafana-wtf.svg
    :target: https://github.com/panodata/grafana-wtf/blob/main/LICENSE

.. |grafana-versions| image:: https://img.shields.io/badge/Grafana-6.x%20--%2010.x-blue.svg
    :target: https://github.com/grafana/grafana
    :alt: Supported Grafana versions

.. end-badges


*****
About
*****
grafana-wtf - grep through all Grafana entities in the spirit of `git-wtf`_.

.. _git-wtf: http://thrawn01.org/posts/2014/03/03/git-wtf/

.. attention::

    This program can put significant load on your Grafana instance
    and the underlying database machinery. Handle with care!


********
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/panodata/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/panodata/grafana-wtf grafana-wtf info


***********
Screenshots
***********

``grafana-wtf find``
====================
.. image:: https://user-images.githubusercontent.com/453543/51694547-5c78fd80-2001-11e9-96ea-3fcc2e0fb016.png

``grafana-wtf log``
===================
.. image:: 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.


*************
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 | .[].type=="<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



********
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


.. _grafana-wtf examples: https://github.com/panodata/grafana-wtf/blob/master/doc/examples.rst

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/panodata/grafana-wtf",
    "name": "grafana-wtf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "grafana search index",
    "author": "Andreas Motl",
    "author_email": "andreas@hiveeyes.org",
    "download_url": "https://files.pythonhosted.org/packages/32/c7/b09b7ce6246fb497574a88b6ddb81c96416c5320da41b4314eefc07f051d/grafana_wtf-0.19.1.tar.gz",
    "platform": null,
    "description": "###########\ngrafana-wtf\n###########\n\n|\n\n.. start-badges\n\n|ci-tests| |ci-coverage| |license| |pypi-downloads|\n|python-versions| |status| |pypi-version| |grafana-versions|\n\n.. |ci-tests| image:: https://github.com/panodata/grafana-wtf/actions/workflows/tests.yml/badge.svg\n    :target: https://github.com/panodata/grafana-wtf/actions/workflows/tests.yml\n\n.. |ci-coverage| image:: https://codecov.io/gh/panodata/grafana-wtf/branch/main/graph/badge.svg\n    :target: https://codecov.io/gh/panodata/grafana-wtf\n    :alt: Test suite code coverage\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/grafana-wtf.svg\n    :target: https://pypi.org/project/grafana-wtf/\n\n.. |status| image:: https://img.shields.io/pypi/status/grafana-wtf.svg\n    :target: https://pypi.org/project/grafana-wtf/\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/grafana-wtf.svg\n    :target: https://pypi.org/project/grafana-wtf/\n\n.. |pypi-downloads| image:: https://static.pepy.tech/badge/grafana-wtf/month\n    :target: https://pypi.org/project/grafana-wtf/\n\n.. |license| image:: https://img.shields.io/pypi/l/grafana-wtf.svg\n    :target: https://github.com/panodata/grafana-wtf/blob/main/LICENSE\n\n.. |grafana-versions| image:: https://img.shields.io/badge/Grafana-6.x%20--%2010.x-blue.svg\n    :target: https://github.com/grafana/grafana\n    :alt: Supported Grafana versions\n\n.. end-badges\n\n\n*****\nAbout\n*****\ngrafana-wtf - grep through all Grafana entities in the spirit of `git-wtf`_.\n\n.. _git-wtf: http://thrawn01.org/posts/2014/03/03/git-wtf/\n\n.. attention::\n\n    This program can put significant load on your Grafana instance\n    and the underlying database machinery. Handle with care!\n\n\n********\nSynopsis\n********\n\nSearch Grafana (dashboards and datasources) for string \"weatherbase\".\n::\n\n    grafana-wtf find weatherbase\n\nDisplay 50 most recent changes across all dashboards.\n::\n\n    grafana-wtf log --number=50\n\nExplore dashboards and datasources in more detail.\n::\n\n    grafana-wtf explore dashboards\n    grafana-wtf explore datasources\n\nExplore plugins.\n::\n\n    grafana-wtf plugins list\n    grafana-wtf plugins status\n\nRun with Docker::\n\n    # Access Grafana instance on localhost, without authentication.\n    docker run --rm -it \\\n        --env GRAFANA_URL=\"http://host.docker.internal:3000\" \\\n        ghcr.io/panodata/grafana-wtf grafana-wtf info\n\n    # Access Grafana instance with authentication.\n    docker run --rm -it \\\n        --env GRAFANA_URL=\"https://grafana.example.org/grafana\" \\\n        --env GRAFANA_TOKEN=\"eyJrIjoiWHg...dGJpZCI6MX0=\" \\\n        ghcr.io/panodata/grafana-wtf grafana-wtf info\n\n\n***********\nScreenshots\n***********\n\n``grafana-wtf find``\n====================\n.. image:: https://user-images.githubusercontent.com/453543/51694547-5c78fd80-2001-11e9-96ea-3fcc2e0fb016.png\n\n``grafana-wtf log``\n===================\n.. image:: https://user-images.githubusercontent.com/453543/56455736-87ee5880-6362-11e9-8cd2-c356393d09c4.png\n\n\n*****\nSetup\n*****\n\nInstall ``grafana-wtf``\n=======================\n::\n\n    pip install grafana-wtf\n\n\nConfigure Grafana\n=================\nPlease take these steps to create an API key with your Grafana instance:\n\n- Go to ``https://daq.example.org/grafana/org/apikeys``.\n\n- Choose \"New API Key\".\n\n  - Key name: grafana-wtf\n  - Role: Admin\n\n- From the output ``curl -H \"Authorization: Bearer eyJrIjoiWHg...dGJpZCI6MX0=\" ...``,\n  please take note of the Bearer token. This is your Grafana API key.\n\n\n*************\nConfiguration\n*************\n\nGrafana connection\n==================\n\nTo configure to which Grafana instance to connect to, and how to authenticate, use\nthe ``--grafana-url`` and ``--grafana-token`` command line options.\n\nAlternatively, before running ``grafana-wtf``, you can define URL and access token\nof your Grafana instance by using environment variables::\n\n    export GRAFANA_URL=https://daq.example.org/grafana/\n    export GRAFANA_TOKEN=eyJrIjoiWHg...dGJpZCI6MX0=\n\nIn order to accept untrusted SSL certificates, append the ``?verify=no`` query string\nto the ``GRAFANA_URL``::\n\n    export GRAFANA_URL=https://daq.example.org/grafana/?verify=no\n\nCaching\n=======\n\n``grafana-wtf`` will cache HTTP responses for 60 minutes by default, in order to save\nresources, by not hitting the server each server. You can configure that setting by using\nthe ``--cache-ttl`` option, or the ``CACHE_TTL`` environment variable.\n\nWhen invoking the program with the ``--drop-cache`` option, it will drop its cache upfront.\n\n\n\n*****\nUsage\n*****\n\n\nGeneral information\n===================\n\n::\n\n    # Display a bunch of meta information and statistics.\n    grafana-wtf info --format=yaml\n\n    # Display Grafana version.\n    grafana-wtf info --format=json | jq -r '.grafana.version'\n\n\nExplore data sources\n====================\n\nHow to find unused data sources?\n::\n\n    # Display all data sources and the dashboards using them, as well as unused data sources.\n    grafana-wtf explore datasources --format=yaml\n\n    # Display names of unused datasources as a flat list.\n    grafana-wtf explore datasources --format=json | jq -r '.unused[].datasource.name'\n\n\nExplore dashboards\n==================\n\nHow to find dashboards which use non-existing data sources?\n::\n\n    # Display some details of all dashboards, including names of missing data sources.\n    grafana-wtf explore dashboards --format=yaml\n\n    # Display only dashboards which have missing data sources, along with their names.\n    grafana-wtf explore dashboards --format=json | \\\n        jq '.[] | select(.datasources_missing) | .dashboard + {ds_missing: .datasources_missing[] | [.name]}'\n\nHow to find dashboards using specific data sources?\n::\n\n    # Display all dashboards which use a specific data source, filtered by data source name.\n    grafana-wtf explore dashboards --format=json | jq '.[] | select(.datasources | .[].type==\"<datasource_name>\")'\n\n    # Display all dashboards using data sources with a specific type. Here: InfluxDB.\n    grafana-wtf explore dashboards --format=json | jq '.[] | select(.datasources | .[].type==\"influxdb\")'\n\nHow to list all queries used in all dashboards?\n::\n\n    grafana-wtf explore dashboards --data-details --queries-only --format=json | \\\n        jq '.[].details | values[] | .[] | .expr,.jql,.query,.rawSql | select( . != null and . != \"\" )'\n\n\nSearching for strings\n=====================\n\nFind the string ``weatherbase`` throughout all dashboards and data sources::\n\n    grafana-wtf find weatherbase\n\nReplacing strings\n=================\n\nReplace all occurrences of ``ldi_v2`` with ``ldi_v3`` within dashboard with\nUID ``_JJ22OZZk``::\n\n    grafana-wtf --select-dashboard=_JJ22OZZk replace ldi_v2 ldi_v3\n\nIn order to preview the changes, you should use the ``--dry-run`` option\nbeforehand::\n\n    grafana-wtf --select-dashboard=_JJ22OZZk replace ldi_v2 ldi_v3 --dry-run\n\n\nDisplay edit history\n====================\n\nWatching out for recent editing activity on any dashboards?\n::\n\n    # Display 50 most recent changes across all dashboards.\n    grafana-wtf log --number=50\n\n\n\n********\nExamples\n********\n\nFor discovering more command line parameters and their arguments, please invoke\n``grafana-wtf --help`` and have a look at `grafana-wtf examples`_.\n\n\n\n***********\nDevelopment\n***********\n::\n\n    git clone https://github.com/panodata/grafana-wtf\n    cd grafana-wtf\n\n    # Run all tests.\n    make test\n\n    # Run selected tests.\n    pytest --keepalive -vvv -k test_find_textual\n\n\n.. _grafana-wtf examples: https://github.com/panodata/grafana-wtf/blob/master/doc/examples.rst\n",
    "bugtrack_url": null,
    "license": "AGPL 3, EUPL 1.2",
    "summary": "Grep through all Grafana entities in the spirit of git-wtf",
    "version": "0.19.1",
    "project_urls": {
        "Homepage": "https://github.com/panodata/grafana-wtf"
    },
    "split_keywords": [
        "grafana",
        "search",
        "index"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa2355bf230d075bcd53f6841ab85b437be42f199853ddd7a6ece270cb67b138",
                "md5": "8d617dabc01a7940883c75c4239777ae",
                "sha256": "1024cc53be4d425eee5943c835ba013bf10e7cd493b37a927dd199bda65a768e"
            },
            "downloads": -1,
            "filename": "grafana_wtf-0.19.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d617dabc01a7940883c75c4239777ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 37300,
            "upload_time": "2024-04-20T19:55:46",
            "upload_time_iso_8601": "2024-04-20T19:55:46.432291Z",
            "url": "https://files.pythonhosted.org/packages/fa/23/55bf230d075bcd53f6841ab85b437be42f199853ddd7a6ece270cb67b138/grafana_wtf-0.19.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "32c7b09b7ce6246fb497574a88b6ddb81c96416c5320da41b4314eefc07f051d",
                "md5": "4f0bf477030f1f465203c896baa8c879",
                "sha256": "c0b0d2595ca8e9130e1dbb505f328bb466d15ce6661fea13956ccc35c4b80cb3"
            },
            "downloads": -1,
            "filename": "grafana_wtf-0.19.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4f0bf477030f1f465203c896baa8c879",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 40636,
            "upload_time": "2024-04-20T19:55:48",
            "upload_time_iso_8601": "2024-04-20T19:55:48.547467Z",
            "url": "https://files.pythonhosted.org/packages/32/c7/b09b7ce6246fb497574a88b6ddb81c96416c5320da41b4314eefc07f051d/grafana_wtf-0.19.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-20 19:55:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "panodata",
    "github_project": "grafana-wtf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "grafana-wtf"
}
        
Elapsed time: 0.23603s