Coder Social home page Coder Social logo

rivian_exporter's Introduction

rivian_exporter

WARNING: This is still a work in progress. Come find me on the Rivian Discord in the #tech-software channel if you have issues.

This is a prometheus_exporter that is scrapes data from the Rivian GraphAPI thanks to the rivian-python-client.

It is designed to be run as a docker image for the exporter daemon. There are also CLI sub-commands to authenticate and fetch information about vehicles. The intended flow is something like

image

You can get my dashboard from Grafana. Warning, I'm odd and use miles for distance and celsius for temperature. If you build your own dash, pull request to link it here.

How to run

The image is published to ghcr.io/oxo42/rivian_exporter:latest

Build

docker build -t ghcr.io/oxo42/rivian_exporter .

Login and save credentials

docker run -it ghcr.io/oxo42/rivian_exporter login

Save the last 3 lines to /tmp/rivian-creds

Get user info

docker run --env-file /tmp/rivian-creds -it ghcr.io/oxo42/rivian_exporter user-info 
# add `| jq` to prettify it

Then add VIN=<YourVin> to the credentials file

Dump vehicle info

This calls the same function the prometheus exporter calls

docker run --env-file /tmp/rivian-creds -it ghcr.io/oxo42/rivian_exporter vehicle-state | jq

Run the exporter for the final step, run the exporter

docker run -p 8000 --env-file /tmp/rivian-creds ghcr.io/oxo42/rivian_exporter
curl http://localhost:8000

Using Docker Secrets

Instead of having all the tokens and VIN as environment variables, you can store each one in a file then use docker secrets to populate those files. You need to specificy the environment variables

  • ACCESS_TOKEN_FILE => /run/secrets/access_token
  • REFRESH_TOKEN_FILE => /run/secrets/refresh_token
  • USER_SESSION_TOKEN_FILE => /run/secrets/user_session_token
  • VIN_FILE => /run/secrets/vin

TODO

  • Add metrics into the collector
  • Split RivianCollector into RivianGauge and RivianInfo
    • The Info collector needs to take things from multiple fields, e.g. version having otaCurrentVersion and otaCurrentVersionGitHash. This is a prometheus thing that I want to lean into
  • Add a get-vehicles CLI to help with setup

Dev notes

Run the app with

poetry run python -m rivian_exporter --help
# or
bin/rivian_exporter --help

Tests

poetry run pytest

rivian_exporter's People

Contributors

oxo42 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

rivian_exporter's Issues

Accept Docker Secrets

When using Docker Secrets, by default the secrets are put into /run/secrets (that can be changed by using the target flag, as per documentation). In this current form, rivian_exporter doesn't read the secret files in /run/secrets. It would be nice to get that updated!

appuser@48d44f6be181:/app$ ls -l /run/secrets/
total 16
-rw-r--r--. 1 1000 1001 1506 Oct  2 20:33 rivian_access_token
-rw-r--r--. 1 1000 1001  682 Oct  2 20:34 rivian_refresh_token
-rw-r--r--. 1 1000 1001  129 Oct  2 20:34 rivian_user_session_token
-rw-r--r--. 1 1000 1001   18 Oct  2 20:34 rivian_vin
❯ cat rivian-creds-secrets                                                                                                                                                                                   ─╯
ACCESS_TOKEN=/run/secrets/rivian_access_token
REFRESH_TOKEN=/run/secrets/rivian_refresh_token
USER_SESSION_TOKEN=/run/secrets/rivian_user_session_token
VIN=/run/secrets/rivian_vin

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.