2.0.1 • Published 2 years ago

@wywywywy/tesla-prometheus-exporter v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

tesla-prometheus-exporter

A Prometheus exporter for your Tesla vehicle.

It exposes metrics such as Remaining Battery Percentage, Remaining Range, Charger Current, etc.

Originally developed by madchicken. I have now forked and continued development due to inactivity of the original repository.

Usage

Firstly get a Tesla API refresh token (not access token). The easiest way is to use this utility on the Tesla-info.com website. Note that since version 2.0.0, it's the refresh token, not the access token, that's required.

Then pass the token to the exporter.

# install
npm install -g @wywywywy/tesla-prometheus-exporter

# run
tesla-prometheus-exporter --token=qts-a0123456789

Or if you're using Docker, set the required environment variables as listed below (at least the TESLA_EXPORTER_TOKEN), and simply run the wywywywy/tesla_exporter image on Docker Hub.

# docker
docker run -e TESLA_EXPORTER_TOKEN=eyJa0123456789 -p 9885:9885 wywywywy/tesla_exporter

And then access http://localhost:9885/metrics.

Since version 2.0.0, it will try to get a new access token from the provided refresh token once every 7 hours, so you don't have to keep providing new access tokens.

For Docker Compose & Kubernetes deployments, see the examples directory.

Notes

If the car is sleeping, it will not attempt to get data from Tesla, as that will wake the car up which is a major battery drain.

If the car is awake, but the screen is off, the exporter will stop for 15 mins, in order to not keep the car awake and allow it to go to sleep gracefully.

Options

Some options can be set as environment variables instead of command line arguments.

OptionEnvironment VariableDescriptionNotes
--versionShow version number
--tokenTESLA_EXPORTER_TOKENTesla API refresh tokenRequired
--portTESLA_EXPORTER_PORTHTTP port to serve onDefault: 9885
--intervalTESLA_EXPORTER_INTERVALScraping interval in secondsDefault: 120
--vinTESLA_EXPORTER_VINVIN of the car to be monitoredIf not provided, the first one will be used
--retriesTESLA_EXPORTER_RETRIESNumber of times to retry when encountering an error before quittingSet to 0 to disable. Default: 3
--debugTESLA_EXPORTER_DEBUGDebug mode
--helpShow help

Prometheus

This is an example Prometheus config

  - job_name: 'tesla_exporter'
    scrape_interval: 2m
    metrics_path: '/metrics'
    static_configs:
      - targets:
        - '192.168.1.77:9885'

Contributing

Yes, contributions are always welcome.
Fork it & submit a pull request.

License

This is licensed under the Apache License 2.0.

Disclaimer

This project is not affiliated with or endorsed by Tesla.