Sun and Moon Datasource Plugin for Grafana
While working on atMETEO, I found it useful to bring the measured temperature and atmospheric pressure values into relation with the position of the sun or the current moon phase and see how they correlate. Back then when Grafana only supported the Graphite datasource this was done with a simple script that calculated those values every minute and stored them in the Graphite database along with the other measurements.
Now that Grafana supports a sophisticated plugin framework (starting with v3.0), I have created the Sun and Moon Datasource Plugin for Grafana which uses SunCalc to calculate the position of sun and moon on demand when rendering on the frontend. Additional features are the calculation of the moon illumination and annotations for various events such as sunrise or sunset.
Like all Grafana plugins the Sun and Moon Datasource Plugin is now hosted on Grafana.net and the source code is available in a GitHub repository. An example dashboard can be found as well.
Technical aspects
The main advantage of doing the calculation in a datasource on the client side is that the values don’t have to be pregenerated which is not optimal with Graphite because it does not allow to submit future values and therefore the calculation has to be done just in time.
From a technical point of view the plugin is interesting because as of today it is the only Grafana plugin that doesn’t rely on a server providing the data. Therefore it might be a useful example for new plugin authors.
Feedback
When submitting the plugin to Grafana.net I received very positive feedback from raintank, the company behind Grafana and Torkel Ödegaard even demoed the datasource in his talk at this year’s Monitorama which happened to take place two days after I created the Pull Request on GitHub. Thanks for this! A recording is available on YouTube.
Outlook and further work
The current version of the plugin implements all features that SunCalc currently offers. Nevertheless there are already a few ideas for future improvements.
I could imagine that the plugin might be useful when monitoring photovoltaic systems (maybe even solar parks). For this the calculation of the clear sky radiation could be added. Additionally the annotations could be extended to be able to show additional astronomic events such as full and new moon or solstices/equinoxes and perihelion/aphelion.
If you have additional ideas or want to help out for example with the calculation of the mentioned values, please use the issue tracker on GitHub.