Write plugin settings to sqlite3 db


I’m working on writing a plugin and want to allow the user to specify metrics to use in the plugin. If a user changes the metrics, I want it to replicate for all users viewing the plugin on this dashboard.

One approach might be to write to a local file in the plugin that I can read/write to.

I’d rather write to Grafana’s sqlite db. I have tried to save it either to /frontend/settings, /org, /user/preferences, but these have restrictions on which keys I can add. I even tried hijacking the address object for the org to store values but haven’t had any success.

So, my question is: is there a place in Grafana sqlite where I can store plugin settings?

Any and all suggestions are welcome. Thanks!

1 Like

There is a plugin_settings table and datasource table. Both have a column called json_data which is just a blob of custom data for a plugin/datasource. I don’t have any example code for what you are trying to do (usually global settings are handled on the config page for a data source or app).

This is digging into Grafana internals so no guarantees that this will always work in the future (but we are not planning any changes so it should be fine).

The plugin edit page is where you can set app specific settings and this is how it saves them to the db:

https://github.com/grafana/grafana/blob/master/public/app/features/plugins/plugin_edit_ctrl.ts#L88-L94 and this is how you would fetch the plugin settings:

This would work too.

Thanks so much for the reply!

I was overthinking this one (as well), I can just save them on the panel object and they will persist. Thanks for the info though, that’s good to know that I could write to that table if needed.

@lovisa - I’m try to achieve the same result (saving custom plugin data).
Did this work for you ?
Can you explain what is the panel object, and how do I write to it ?