CLI tool that uploads the PVPC €/MWh data from REData API to influxdb on a daily basis
- go
- influxdb v2+
- Optional:
-
Configure
pvpc_exporter.json
(see the configuration section below). -
Run it.
docker compose up --detach
-
Build the docker image.
docker build . --tag pvpc-exporter
-
Configure
pvpc_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 ./pvpc_exporter.json:/app/pvpc_exporter.json:ro ghcr.io/rare-magma/pvpc-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/pvpc_exporter.json
-
Build
pvpc_exporter
with:go build -ldflags="-s -w" -o pvpc_exporter main.go
-
Copy
pvpc_exporter
to$HOME/.local/bin/
. -
Copy
pvpc_exporter.json
to$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 pvpc-exporter.* $HOME/.config/systemd/user/
-
and run the following command to activate the timer:
systemctl --user enable --now pvpc-exporter.timer
It's possible to trigger the execution by running manually:
systemctl --user start pvpc-exporter.service
The config file has a few options:
{
"InfluxDBHost": "influxdb.example.com",
"InfluxDBApiToken": "ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg==",
"Org": "home",
"Bucket": "pvpc",
}
InfluxDBHost
should be the FQDN of the influxdb server.Org
should be the name of the influxdb organization that contains the pvpc price data bucket defined below.Bucket
should be the name of the influxdb bucket that will hold the pvpc price data.InfluxDBApiToken
should be the influxdb API token value.- This token should have write access to the
Bucket
defined above.
- This token should have write access to the
If the cli is passed a number with the --days
cli flag, it will query the REData API for an interval in the past instead of the default date of "today".
This argument should correspond to the number of days in the past relative to the current date. Take into account that the REData API doesn't allow queries for dates prior to 2014-01-01.
Example:
~/.local/bin/pvpc_exporter --days 30
A simple bash loop can be used to query the API with an interval between "today" and 15 days ago:
for i in {0..15}; do echo "Exporting data from $(date -I -d "$i days ago")" && ~/.local/bin/pvpc_exporter --days "$i"; done
Run the tool manually with go set to debug:
GODEBUG=http1debug=2 $HOME/.local/bin/pvpc_exporter
Check the systemd service logs and timer info with:
journalctl --user --unit pvpc-exporter.service
systemctl --user list-timers
- price: The pvpc price in €/MWh
pvpc_price price=63.54 1672610400
In pvpc-dashboard.json
there is an example of the kind of dashboard that can be built with pvpc-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
pvpc-dashboard.json
file.
For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.
make uninstall
Run the following command to deactivate the timer:
systemctl --user disable --now pvpc-exporter.timer
Delete the following files:
~/.local/bin/pvpc_exporter
~/.config/pvpc_exporter.json
~/.config/systemd/user/pvpc-exporter.timer
~/.config/systemd/user/pvpc-exporter.service
This project takes inspiration from the following: