CLI tool that uploads the last 24h weather conditions from the AEMET OpenData API to influxdb on a hourly basis
- go
- influxdb v2+
- Optional:
-
Configure
aemet_exporter.json(see the configuration section below). -
Run it.
docker compose up --detach
-
Build the docker image.
docker build . --tag aemet-exporter -
Configure
aemet_exporter.json(see the configuration section below). -
Run it.
docker run --rm --tty --interactive --read-only --cap-drop ALL --security-opt no-new-privileges:true --cpus 2 -m 64m --pids-limit 16 --volume ./aemet_exporter.json:/app/aemet_exporter.json:ro ghcr.io/rare-magma/aemet-exporter:latest
For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.
make build
make install
$EDITOR $HOME/.config/aemet_exporter.json-
Build
aemet_exporterwith:go build -ldflags="-s -w" -o aemet_exporter main.go -
Copy
aemet_exporterto$HOME/.local/bin/. -
Copy
aemet_exporter.jsonto$HOME/.config/, configure it (see the configuration section below) and make it read only. -
Copy the systemd unit and timer to
$HOME/.config/systemd/user/:cp aemet-exporter.* $HOME/.config/systemd/user/
-
and run the following command to activate the timer:
systemctl --user enable --now aemet-exporter.timer
It's possible to trigger the execution by running manually:
systemctl --user start aemet-exporter.serviceThe config file has a few options:
{
"InfluxDBHost": "influxdb.example.com",
"InfluxDBApiToken": "ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg==",
"Org": "home",
"Bucket": "aemet",
"AemetApiKey": "ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg==",
"AemetWeatherStationCode": "1234Y"
}InfluxDBHostshould be the FQDN of the influxdb server.Orgshould be the name of the influxdb organization that contains the data bucket defined below.Bucketshould be the name of the influxdb bucket that will hold the data.InfluxDBApiTokenshould be the influxdb API token value.- This token should have write access to the
Bucketdefined above.
- This token should have write access to the
AemetApiKeyshould be the AEMET API key requested in the AEMET OpenData's websiteAemetWeatherStationCodeshould be the alphanumeric code assigned to the weather station. Can be found in AEMET OpenData's website "Seleccione una estación" dropdown.
Check the systemd service logs and timer info with:
journalctl --user --unit aemet-exporter.service
systemctl --user list-timersWeather stations might have a different set of sensors so not all metrics below might be populated.
- temperature:
°C - humidity:
% - pressure:
hPa - windspeed:
km/h - windgust:
km/h - winddirection:
° - precipitation:
mm - dewpoint:
°C - visibility:
km - insolation:
hours - snow:
cm
aemet_weather_conditions,station=3195 temperature=11.1,humidity=99.0,pressure=949.7,windspeed=0.9,winddirection=271.0,windgust=2.9,precipitation=0.0,dewpoint=11.0,visibility=1.0,insolation=1.0,snow=0.0 1702206000In aemet-dashboard.json there is an example of the kind of dashboard that can be built with aemet-exporter data:
Import it by doing the following:
- Create a dashboard
- Click the dashboard's settings button on the top right.
- Go to JSON Model and then paste there the content of the
aemet-dashboard.jsonfile.
For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.
make uninstallRun the following command to deactivate the timer:
systemctl --user disable --now aemet-exporter.timerDelete the following files:
~/.local/bin/aemet_exporter
~/.config/aemet_exporter.json
~/.config/systemd/user/aemet-exporter.timer
~/.config/systemd/user/aemet-exporter.serviceInformación elaborada por la Agencia Estatal de Meteorología © AEMET
