grafana-toolbox / grafana-wtf

Grep through all Grafana entities in the spirit of git-wtf.
GNU Affero General Public License v3.0
144 stars 13 forks source link

Find MetricName used by Datasource #88

Open jared-kupidura-simplisafe opened 10 months ago

jared-kupidura-simplisafe commented 10 months ago

First off, this tools is great. I am trying to use it to get every MetricName associated with a specific datasource. I was wondering if this was possible through the current setup but cant find the input combo? Looking for something like, if datasource name is 'CloudWatch', list all of the MetricsNames used in any panel in Grafana.

amotl commented 10 months ago

Dear Jared,

thank you for writing in. Your proposal sounds like a good idea to be tackled by grafana-wtf. I can't promise anything, but maybe someone from the community will pick it up for implementation.

As I am not working with grafana-wtf on a daily basis, can I ask for further guidance on your request to get us on the same page? I mean, if we would already have the feature to inquire data source items in all dashboard panels, how far away would be filtering that by datasource name?

Or are you actually looking at filtering that output by database type instead?

With kind regards, Andreas.

amotl commented 10 months ago

What about this kind of inquiry, combining grafana-wtf with jq?

It discovers used datasources by name, and reports about the spots (dashboards) where those are used. Do you need the report to drill down into more details, down to the metrics level, or would that be satisfactory already?

grafana-wtf explore datasources --format=json | \
  jq '.used[] | select(.datasource.name == "weewx_097287c4_6fb0_4aeb_a095_00d65ecb15f7")'
{
  "datasource": {
    "uid": null,
    "name": "weewx_097287c4_6fb0_4aeb_a095_00d65ecb15f7",
    "type": "influxdb",
    "url": "http://localhost:8086/"
  },
  "dashboards": [
    {
      "title": "weewx 097287c4-6fb0-4aeb-a095-00d65ecb15f7 automatic",
      "uid": "000000190",
      "path": "/grafana/d/000000190/weewx-097287c4-6fb0-4aeb-a095-00d65ecb15f7-automatic",
      "url": "https://swarm.hiveeyes.org/grafana/d/000000190/weewx-097287c4-6fb0-4aeb-a095-00d65ecb15f7-automatic"
    },
    {
      "title": "Wetter in Leoni",
      "uid": "000000191",
      "path": "/grafana/d/000000191/wetter-in-leoni",
      "url": "https://swarm.hiveeyes.org/grafana/d/000000191/wetter-in-leoni"
    },
    {
      "title": "weewx-097287c4-6fb0-4aeb-a095-00d65ecb15f7",
      "uid": "w-kZrPmiz",
      "path": "/grafana/d/w-kZrPmiz/weewx-097287c4-6fb0-4aeb-a095-00d65ecb15f7",
      "url": "https://swarm.hiveeyes.org/grafana/d/w-kZrPmiz/weewx-097287c4-6fb0-4aeb-a095-00d65ecb15f7"
    }
  ]
}

Or are you actually looking at filtering that output by database type instead?

The example can easily be adjusted to filter by type instead, so that would be covered already.

select(.datasource.type == "foobar")
amotl commented 10 months ago

Do you need the report to drill down into more details, down to the metrics level?

grafana-wtf find mostly yields massive output, but may offer a better chance to learn about details slightly beyond the dashboard entity level, because it also informs you about details down to the panels and metrics (targets) levels.

grafana-wtf find weewx_097287c4_6fb0_4aeb_a095_00d65ecb15f7

Let me know about any improvements which could support your use case better. As the acquisition and querying machinery is in place already, adding more features on the level you are asking for would most probably only need a bit of data structure wrangling, and/or adjusting output templates.

jared-kupidura-simplisafe commented 10 months ago

Yes, i would need more information about the panels in the dashboard to be able to pull out what metricName is being used with that datasource. I did get a great list of dashboards and which panels are using the datasource, just not enough information to parse that into jq to pull out the details i need.

amotl commented 10 months ago

Dear Jared,

you may want to have a look at the new --data-details option to explore dashboards, effectively adding a details slot to the output data, which conveys more information. See GH-89.

Setup

It is not released yet, but you can use this command to install the development version of the package.

pip install --upgrade 'git+https://github.com/panodata/grafana-wtf'

If you are using the Docker image, you may want to use the nightly tag for the same purposes of running the preview version.

Usage

When combining it with jq in this way, you can generate a flat list of all data queries used within all dashboards:

grafana-wtf explore dashboards --data-details --format=json | \
    jq -r '.[].details | values[] | .[].query // "null"'

Outlook

Let us know if that goes into the right direction, and/or if you need any improvements. If you think the raw output data is all you need, and will come up with a corresponding jq-based query to fit your needs, please share it back with us, so we can add it to the documentation as another example.

With kind regards, Andreas.

amotl commented 9 months ago

Hi again,

we just released grafana-wtf 0.16.0, where the command outlined above should work, see also https://github.com/panodata/grafana-wtf/issues/70#issuecomment-1745705322.

With kind regards, Andreas.