2017年12月26日星期二

Importing a dashboard with Grafana

What I'm about to write will probably be out-of-date quite soon, as they are based on Grafana version 4.6.3, and version 5.0 is rolling out (already at the alpha stage as of this writing). In version 5.0 there will be a different, way more sensible approach of provisioning data sources and dashboards. Nevertheless, I still plan to write this down, for there is still a large user base of Grafana v4, and I do have a poor memory!

Thanks to Grafana, you can choose from tons of open source dashboards for your targets of monitoring (my personal favorite in terms of Docker host and container monitoring), instead of building everything from scratch on your own. On your Grafana UI you can import the dashboard as simply as inputting its ID and selecting its data source.

Neat, right? But what if you need to bootstrap your Grafana programmatically? UI is clearly not an option. The official way, as of Grafana v4, is through its HTTP API. Throughout the API document, however, there is only mentioning about creating/updating dashboard, not importing it, and creating a dashboard with downloaded json file did run into errors (complaining alert configuration error).

I kept digging until I found this comment, which sort of tells how the import API should be fabricated. I tried it and succeeded, but still wish it were properly documented.

没有评论:

发表评论