The Sun and Moon Datasource Backend Plugin for Grafana provides astronomical metrics and events for the sun and moon. This Go backend plugin calculates position, illumination, and event times such as sunrise, sunset, moonrise, and moonset. It is a port of the original Grafana Sun and Moon Datasource using the Suncalc Go library.
This backend version was developed to address the limitations of frontend-only plugins, particularly their incompatibility with public dashboards in Grafana. By handling the calculations on the backend, this plugin is fully functional for public dashboards, making it ideal for shared or embedded use cases.
- Sun Position: Altitude and azimuth in degrees
- Moon Position: Altitude and azimuth in degrees
- Moon Illumination: Percentage (0-100%)
- Moon Distance: Distance from Earth in kilometers
- Sun Maximum Altitude: Daily maximum altitude
Display solar and lunar events as time series markers or in table format:
- Solar Events: Sunrise, sunset, dawn, dusk, nautical dawn/dusk, solar noon, nadir
- Lunar Events: Moonrise, moonset
- All calculations performed server-side
- Compatible with Grafana public dashboards
- Supports variable latitude/longitude per query
Once published, install directly from Grafana:
grafana-cli plugins install simonbuehler-sunandmoon-datasource-
Download the Plugin:
- Download the latest version from GitHub Releases
-
Install the Plugin:
- Extract and place in the Grafana plugins directory:
unzip simonbuehler-sunandmoon-datasource-*.zip sudo mv simonbuehler-sunandmoon-datasource /var/lib/grafana/plugins/
- Extract and place in the Grafana plugins directory:
-
Configure Grafana (if unsigned):
- For unsigned development versions, edit
grafana.ini:[plugins] allow_loading_unsigned_plugins = simonbuehler-sunandmoon-datasource
- For unsigned development versions, edit
-
Restart Grafana:
sudo systemctl restart grafana-server
-
Add the Datasource:
- Go to Configuration > Data Sources in Grafana, click Add Data Source, and select Sun and Moon Datasource Backend from the list.
-
Configure the Datasource:
- Set default latitude and longitude for calculations. These defaults can be overridden per query if needed.
- The plugin will attempt to use your browser's geolocation to auto-fill coordinates.
-
Create Panels:
For Metrics:
- Add a Time Series panel
- Select metrics like
sun_altitude,moon_illumination,moon_distance, etc. - Visualize position and illumination changes over time
For Events (as markers):
- Add a Time Series panel with your base metric (e.g.,
sun_altitude) - Add a second query with events like
sunrise,sunset - Set event series to display as Points or Bars to show vertical markers
For Events (as table):
- Add a Table panel
- Select multiple events:
sunrise,sunset,moonrise,moonset, etc. - View event times in a structured table format
- Go 1.21+
- Node.js 18+
- Docker & Docker Compose
Frontend (TypeScript/React):
npm install
npm run dev # Watch mode for development
npm run build # Production buildBackend (Go):
export GOOS=linux GOARCH=amd64
go build -o dist/gpx_sunandmoon_linux_amd64 ./pkgdocker compose up
# Grafana runs at http://localhost:3000
# Default credentials: admin/admin- Original Plugin: fetzerch/grafana-sunandmoon-datasource
- Suncalc Library: sixdouglas/suncalc
- Author: Simon BΓΌhler
Contributions are welcome! Please feel free to submit issues or pull requests on GitHub.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.