Can you update dashboard panels through HTTP requests?

In reference to this post:
https://localhost:3000/t/how-does-the-grafana-sql-backend-work/18297/2?u=damienclark

I can get the html of the particular dashboard I’m working with but it doesn’t include any of the actual json used to query the data. Is there something I am missing or is that not possible?

Does Share Dashboard -> Export -> Save to File help?

Antony.

Well the thing is I want to programatically schedule updates. Originally I was querying and thinking I could update the actual backend mysql tables grafana saves everything to BUT that has been tricky since if I make a change to the current json code in the table but no resulting new version is loaded I believe it breaks the dashboard. I made that first question and @torkel made it sound like using http requests would be easier to do what I was attempting.

How about https://grafana.com/docs/administration/provisioning/#dashboards

Set updateIntervalSeconds to whatever schedule you want for updates to be
detected.

Antony.

That could work. I’ve read through that page and don’t really understand how updates work with provisioning. So do I need to have a file with the entire dashboard html + json (or just json?) code and make changes to that file and then set grafana up to access that file periodically to reload the dashboard with the updates json code?

Create (if it doesn’t exist) a directory /etc/grafana/provisioning/dashboards

Create a file there called dashboard.yaml

In the file put something along the lines of:

Create (if it doesn’t exist) a directory
/etc/grafana/provisioning/dashboards

Create a file there called dashboard.yaml

In the file put something along the lines of:

Er, the forum / list software appears to have eaten the remainder of my
posting, so here is it again. I’ve changed the row of dashes I used to indate
start and end of the file contents to something else, so hopefully you’ll see
what I wrote this time:

---------- Forwarded Message Starts ----------

through HTTP requests?

Create (if it doesn’t exist) a directory
/etc/grafana/provisioning/dashboards

Create a file there called dashboard.yaml

In the file put something along the lines of:
Er, the forum / list software appears to have eaten the remainder of my
posting, so here is it again. I’ve changed the row of dashes I used to
indate start and end of the file contents to something else, so hopefully
you’ll see what I wrote this time:

---------- Forwarded Message Starts ----------

through HTTP requests?

I have no idea what this forum / list is doing to my postings (nor even where
that last phrase above came from).

Here it is again without any symbols I think it might choose to interpret as
me wanting it to delete what I wrote…

You could post a picture of it if that’s easier?

I’m trying one final time.

That could work. I’ve read through that page and don’t really understand
how updates work with provisioning.

Create (if it doesn’t exist) a directory /etc/grafana/provisioning/dashboards

Create a file there called dashboard.yaml

In the file put something along the lines of:

apiVersion: 1

providers:

  • name: ‘My dashboard name’
    orgId: 1
    folder: ‘’
    folderUid: ‘My dashboard folder name’
    type: file
    updateIntervalSeconds: 3600
    options:
    path: /var/lib/grafana/dashboards

Then in /var/lib/grafana/dashboards (the path you just specified) put one or
more JSON files of the dashboards you want to be available.

So do I need to have a file with the
entire dashboard html + json (or just json?) code

Just JSON. Exactly what you get from “Share Dashboard → Export → Save to
File”.

and make changes to that file and then set grafana up to access that file
periodically

Yes, that’s where the updateIntervalSeconds comes in.

to reload the dashboard with the updated json code?

Exactly. Works (for me) a treat.

You can do the same thing for data sources if you want to - just put a .yaml
file into /etc/grafana/provisioning/datasources.

Antony.

Thank you very much for this!! I need to request access permission to the server system files to update these but I will attempt this.

One more question: Does provisioning create versions of a dashboard? For example setting the update interval seconds to 3600 means that theoretically the dashboard could change every 3600 seconds. Will a new version be saved for the dashboard being updated that could be reverted to later or does it only update the current version of the dashboard?

On my system (Debian 9 Stretch, Grafana 6.2.2) it does create multiple
versions every time a new release is detected.

However, unless I’ve got something wrong with my setup (please speak up,
anyone who knows what this might be), the old version are useless, because if
you try to restore to one from the “Dashboard Settings - Versions” screen, you
get the message “Cannot save provisioned dashboard”.

So, yes, the old versions are preserved, but no, you can’t restore to any of
them…

Antony.

Oh. Well that is a bummer. Maybe I can make an external version table to save the version prior to updating unless this is supposed to work? On the provisioning page it does mention that you can’t save to a provisioned dashboard. I wonder if since the provisioning source is different than the mysql grafana db if it stops saving the old versions to the grafana_version table. Especially if dashboards are being updated every couple of minutes/seconds.

Quick question: So I have the dashboard.yaml in the provisioning/dashboard folder, then I put the json files from the dashboard export in the same dashboard file or a separate dashboard file? I don’t have a grafana/dashboard file so I can create one and change the path to that or can I keep it in the provisioning/dashboard file? How do I make it start ‘running’ and updating based on the newer json?

Quick question: So I have the dashboard.yaml in the provisioning/dashboard
folder

Yes - and that contains a line “path: /var/lib/grafana/dashboards”

then I put the json files from the dashboard export in the same dashboard file
or a separate dashboard file?

You put them into any file you like in /var/lib/grafana/dashboards

From Provision Grafana | Grafana documentation “When Grafana
starts, it will update/insert all dashboards available in the configured path.
Then later on poll that path every updateIntervalSeconds and look for updated
json files and update/insert those into the database.”

I don’t have a grafana/dashboard file

I’m not sure whether you meant to say “I don’t have a
/etc/grafana/provisiong/hasboards directory” or “I don’t have a file to put
into /var/lib/grafana/dashboards”.

so I can create one and change the path to that or can I keep it in the
provisioning/dashboard file?

No, sorry, you lost me. Please try to be more precise with your references to
filenames and directory names.

How do I make it start ‘running’ and updating based on the newer json?

Restart Grafana.

/etc/init.d/grafana-server restart (on Debian Stretch, at least)

Once you’ve done that, it will automatically pick up and implement any new
dashboard every updateIntervalSeconds.

Antony.

So is the full path name
/provisioning/dashboard/var/lib/grafana/dashboards ?

Hi, I’m assisting damienclark with this in our office. on the server, the path to the *.yaml is C:\Grafana\conf\provisioning\dashboards. we have a dashboard.yaml in that folder as well as a *.json file. After these files were updated, we went to cmd.exe and ran C:\Grafana\bin>grafana-server restart. However, we are still not seeing the dashboard appear. The code in the *.yaml is:

config file version

apiVersion: 1

providers:

  • name: ‘ND_TOBACCO_GARDEN’
    orgId: 12
    folder: ‘dashboards’

    type: file
    updateIntervalSeconds: 60
    options:
    path: /grafana/conf/provisioning

Is this correct? Thanks, NOelle

Hi, I’m assisting damienclark with this in our office. on the server, the
path to the *.yaml is C:\Grafana\conf\provisioning\dashboards.

Ah. That tells me you’re running this on Windows, and I have no experience of
how the Windows paths work. All I can say is that it does look plausible.

we have a dashboard.yaml in that folder as well as a *.json file.

What’s in the *.json file??

After these files were updated, we went to cmd.exe and ran
C:\Grafana\bin>grafana-server restart.

I can only assume that’s the normal Windows method of restarting Grafana.

However, we are still not seeing the dashboard appear.

Any clues in the log file (on Linux it’s in /var/log/grafana/grafana/log )?

The code in the *.yaml is:

config file version

apiVersion: 1

providers:

  • name: ‘ND_TOBACCO_GARDEN’
    orgId: 12
    folder: ‘dashboards’

    type: file
    updateIntervalSeconds: 60
    options:
    path: /grafana/conf/provisioning

I’m certain you’d need to change the path in the last line to point at
something plausible on your Windows machine.

From Provision Grafana | Grafana documentation “When Grafana
starts, it will update/insert all dashboards available in the configured
path. Then later on poll that path every updateIntervalSeconds and look
for updated json files and update/insert those into the database.”
[/quote]

So is the full path name
/provisioning/dashboard/var/lib/grafana/dashboards ?

No.

The .yaml file in (under Linux) /etc/grafana/provisioning/dashboards contains a
path (in my example /var/lib/grafana/dashboards but you can set it to anything
that suits you), and that is where the JSON file/s for the dashboard/s go.

Regards,

Antony.

It is the dashboard json file from exporting via the share button on the dashboard page.

t=2019-06-18T08:41:43-0600 lvl=info msg="Config loaded from" logger=settings file=C:\\Grafana/conf/defaults.ini
t=2019-06-18T08:41:43-0600 lvl=info msg="Config loaded from" logger=settings file=C:\\Grafana\\conf\\custom.ini
t=2019-06-18T08:41:43-0600 lvl=info msg="Path Home" logger=settings path=C:\\Grafana
t=2019-06-18T08:41:43-0600 lvl=info msg="Path Data" logger=settings path=C:\\Grafana\\data
t=2019-06-18T08:41:43-0600 lvl=info msg="Path Logs" logger=settings path=C:\\Grafana\\data\\log
t=2019-06-18T08:41:43-0600 lvl=info msg="Path Plugins" logger=settings path=C:\\Grafana\\data\\plugins
t=2019-06-18T08:41:43-0600 lvl=info msg="Path Provisioning" logger=settings path=C:\\Grafana\\conf\\provisioning
t=2019-06-18T08:41:43-0600 lvl=info msg="App mode production" logger=settings
t=2019-06-18T08:41:43-0600 lvl=info msg="Ldap enabled, reading config file" logger=ldap file=C:\\Grafana\\conf\\ldap.toml
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing HTTPServer" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing SqlStore" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Connecting to DB" logger=sqlstore dbtype=mysql
t=2019-06-18T08:41:43-0600 lvl=info msg="Starting DB migration" logger=migrator
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing SearchService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing RenderingService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing AlertingService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing DatasourceCacheService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing HooksService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing InternalMetricsService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing CleanUpService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing NotificationService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing ProvisioningService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing PluginManager" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Starting plugin search" logger=plugins
t=2019-06-18T08:41:43-0600 lvl=eror msg="Plugins: Failed to load plugin json file: C:\\Grafana\\public\\app\\plugins\\datasource\\testdata\\plugin.json,  err: Plugin with same id already exists"
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name="Datatable Panel"
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name="D3 Gauge"
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name="Azure Data Explorer Datasource"
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=Drill
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=SimpleSql
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=Diagram
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=Discrete
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=Plotly
t=2019-06-18T08:41:43-0600 lvl=info msg="Registering plugin" logger=plugins name=Heatmap
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing TracingService" logger=server
t=2019-06-18T08:41:43-0600 lvl=info msg="Initializing Stream Manager"
t=2019-06-18T08:41:43-0600 lvl=info msg="HTTP Server Listen" logger=http.server address=0.0.0.0:80 protocol=http subUrl= socket=
t=2019-06-18T08:41:43-0600 lvl=eror msg="Stopped HTTPServer" logger=server reason="listen tcp 0.0.0.0:80: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped Stream Manager"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped ProvisioningService" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped InternalMetricsService" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped NotificationService" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped CleanUpService" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped RenderingService" logger=server reason=nil
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped TracingService" logger=server reason=nil
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped AlertingService" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=info msg="Stopped PluginManager" logger=server reason="context canceled"
t=2019-06-18T08:41:43-0600 lvl=eror msg="Server shutdown" logger=server reason="listen tcp 0.0.0.0:80: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

These are the logs after restarting grafana.

config file version

apiVersion: 1

providers:

  • name: ‘ND_TOBACCO_GARDEN-1560804286932’
    orgId: 12
    folder: ‘dashboards’

    type: file
    updateIntervalSeconds: 60
    options:
    path: ‘C:\Grafana\conf\provisioning’

This is what I’ve changed it to.

Still not seeing updates to the dashboard though.

EDIT: Do you need to change the UID in the .json file to allow for provisioning?

It is the dashboard json file from exporting via the share button on the
dashboard page.

I would recommend removing it from that directory, because it is not needed
there and can only serve to confuse someone later on.

t=2019-06-18T08:41:43-0600 lvl=eror msg=“Plugins: Failed to load plugin json
file: C:\Grafana\public\app\plugins\datasource\testdata\plugin.json,
err: Plugin with same id already exists”

That’s not so serious, but you should still deal with it.

t=2019-06-18T08:41:43-0600 lvl=info msg=“HTTP Server Listen”
logger=http.server address=0.0.0.0:80 protocol=http subUrl= socket=

t=2019-06-18T08:41:43-0600 lvl=eror msg=“Stopped HTTPServer” logger=server
reason=“listen tcp 0.0.0.0:80: bind: Only one usage of each socket address
(protocol/network address/port) is normally permitted.”

That one is serious, and needs dealing with, otherwise Grafana will never
start.

It tells me you have some other process already listening on port 80 on this
machine (Grafana normally listens on port 3000, so you must have changed this
in a config file), therefore Grafana can’t use port 80 as well.

t=2019-06-18T08:41:43-0600 lvl=eror msg=“Server shutdown” logger=server
reason="listen tcp 0.0.0.0:80: bind: Only one usage of each socket address
(protocol/network address/port) is normally permitted.

path: 'C:\Grafana\conf\provisioning'

This is what I’ve changed it to.

I suppose that’s alright, although it strikes as being just a little bit
recursive…

If it works after you’ve fixed the network port problem, though, then it’s
obviously fine.

Antony.