Code Monkey home page Code Monkey logo

datadis-exporter's Introduction

datadis-exporter

Bash script that uploads the energy consumption and maximum power usage data from the DATADIS API to influxdb on a daily basis

Dependencies

Relevant documentation

Installation

With Docker

docker-compose

  1. Configure datadis_exporter.conf (see the configuration section below).

  2. Run it.

    docker compose up --detach

docker build & run

  1. Build the docker image.

    docker build . --tag datadis-exporter
  2. Configure datadis_exporter.conf (see the configuration section below).

  3. Run it.

    docker run --rm --init --tty --interactive --read-only --cap-drop ALL --security-opt no-new-privileges:true --cpus 2 -m 64m --pids-limit 16 --volume ./datadis_exporter.conf:/app/datadis_exporter.conf:ro ghcr.io/rare-magma/datadis-exporter:latest

With the Makefile

For convenience, you can install this exporter with the following command or follow the manual process described in the next paragraph.

make install
$EDITOR $HOME/.config/datadis_exporter.conf

Manually

  1. Copy datadis_exporter.sh to $HOME/.local/bin/ and make it executable.

  2. Copy datadis_exporter.conf to $HOME/.config/, configure it (see the configuration section below) and make it read only.

  3. Copy the systemd unit and timer to $HOME/.config/systemd/user/:

cp datadis-exporter.* $HOME/.config/systemd/user/
  1. and run the following command to activate the timer:
systemctl --user enable --now datadis-exporter.timer

It's possible to trigger the execution by running manually:

systemctl --user start datadis-exporter.service

Config file

The config file has a few options:

INFLUXDB_HOST='influxdb.example.com'
INFLUXDB_API_TOKEN='ZXhhbXBsZXRva2VuZXhhcXdzZGFzZGptcW9kcXdvZGptcXdvZHF3b2RqbXF3ZHFhc2RhCg=='
ORG='home'
BUCKET='datadis'
DATADIS_USERNAME='username'
DATADIS_PASSWORD='password'
CUPS='ES0000000000000000XX0X'
DISTRIBUTOR_CODE='1'
  • INFLUXDB_HOST should be the FQDN of the influxdb server.
  • ORG should be the name of the influxdb organization that contains the energy consumption data bucket defined below.
  • BUCKET should be the name of the influxdb bucket that will hold the energy consumption data.
  • INFLUXDB_API_TOKEN should be the influxdb API token value.
    • This token should have write access to the BUCKET defined above.
  • DATADIS_USERNAME and DATADIS_PASSWORDshould be the credentials used to access the DATADIS website
  • CUPS should be the Código Unificado de Punto de Suministro (CUPS)
  • DISTRIBUTOR_CODE should be one of:
    • 1: Viesgo,
    • 2: E-distribución
    • 3: E-redes
    • 4: ASEME
    • 5: UFD
    • 6: EOSA
    • 7: CIDE
    • 8: IDE

Troubleshooting

Run the script manually with bash set to trace:

bash -x $HOME/.local/bin/datadis_exporter.sh

Check the systemd service logs and timer info with:

journalctl --user --unit datadis-exporter.service
systemctl --user list-timers

Exported metrics

The consumption DATADIS API call period is limited to the last 30 days by default. The power call is limited to the current year's first and last day.

  • consumption: The energy consumption in kWh
  • period: The period type (p1: punta, p2: llano, p3: valle)
  • cups: The cups corresponding to the consumption point above
  • max_power: The highest electrical power demanded in kWh

Exported metrics example

datadis_consumption,cups=ES0000000000000000XX0X,period=1 consumption=0.123 1672610400
datadis_power,cups=ES0000000000000000XX0X,period=1 max_power=0.123 1686869100

Example grafana dashboard

In datadis-dashboard.json there is an example of the kind of dashboard that can be built with datadis-exporter data:

Import it by doing the following:

  1. Create a dashboard
  2. Click the dashboard's settings button on the top right.
  3. Go to JSON Model and then paste there the content of the datadis-dashboard.json file.

Uninstallation

With the Makefile

For convenience, you can uninstall this exporter with the following command or follow the process described in the next paragraph.

make uninstall

Manually

Run the following command to deactivate the timer:

systemctl --user disable --now datadis-exporter.timer

Delete the following files:

~/.local/bin/datadis_exporter.sh
~/.config/datadis_exporter.conf
~/.config/systemd/user/datadis-exporter.timer
~/.config/systemd/user/datadis-exporter.service

Credits

This project takes inspiration from the following:

datadis-exporter's People

Contributors

rare-magma avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.