How does the grafana sql backend work?

Grafana is stored in either sqlite or mysql on the backend. I’m looking at the grafana server and trying to automate dashboard updates (since I can’t get the variables to work the way I’d like) and I am trying to understand the relationship between all of the tables in the grafana database.

I know the dashboard table has the current version of the dashboard and I believe the dashboard_snapshot or maybe it was the dashboard_provisioning that had the previous version history in it. But there are several other dashboard related tables. What do they all do?

Thanks!!

Read the code :slight_smile:

There is no docs for each table. Read the API docs if you want to automate dashboard creation & updates.

Or look at the provisioning docs

1 Like

I didn’t know there was a grafana API!

Though I’m going to be honest I haven’t done much with REST APIs. Am I structuring this correct? I think I’m missing something because I’m getting a malformed error from curl.

curl -o curl.txt -H "Authorization: Bearer Key" /dashboards/uid/:UIDNUMBERS

that does not look like anything like the examples in the doc, missing content type header, and json body

I followed the docs and sent the following information in a get request:

url = ‘…/api/dashboards/uid/000000815’
TOKEN = ‘Bearer’ + token
headers = {‘Authorization’: TOKEN, ‘Content-Type’: ‘application/json’, ‘Accept’: ‘application/json’}

what returns in a bunch of html but not the actual dashboard json code for each of the panels on the dashboard.

What does the “bunch of HTML” appear to say?

Do you get anything meaningful if you feed it through lynx?

Antony.

Not sure how to feed through lynx. But if I save it to a .html file and try to load it, I get the grafana message:

"If you’re seeing this Grafana has failed to load its application files

  1. This could be caused by your reverse proxy settings.

  2. If you host grafana under subpath make sure your grafana.ini root_path setting includes subpath

  3. If you have a local dev build make sure you build frontend using: npm run dev, npm run watch, or npm runbuild

  4. Sometimes restarting grafana-server can help
    "

It looks like the html and css for a basic dashboard. It doesn’t appear to have any specific json pertaining to my actual dashboard but it does show some javascript such as below:

settings: {"alertingEnabled":true,"alertingErrorOrTimeout":"alerting","alertingNoDataOrNullValues":"no_data","allowOrgCreate":false,"appSubUrl":"","authProxyEnabled":false,"buildInfo":{"buildstamp":1544450912,"commit":"308c818","env":"production","hasUpdate":true,"isEnterprise":false,"latestVersion":"6.2.2","version":"5.4.1"},"datasources":{"-- Grafana --":{"meta":{"type":"datasource","name":"-- Grafana --","id":"grafana","info":{"author":{"name":"","url":""},"description":"","links":null,"logos":{"small":