Skip to content

Commit

Permalink
Merge pull request #9 from wywywywy/npm-publish
Browse files Browse the repository at this point in the history
Publish to Npm
  • Loading branch information
wywywywy authored Feb 5, 2022
2 parents 0bdeac5 + fb0c4ec commit d1ce69f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 597 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Npm

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm ci --production-only --no-audit
- run: npm audit fix
- run: npm run build
- run: npm publish
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
62 changes: 50 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# tesla-prometheus-exporter

A Prometheus exporter for your Tesla.
A Prometheus exporter for your Tesla vehicle.

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

Originally developed by [madchicken](https://github.com/madchicken/tesla-prometheus-exporter). I have now forked and continued development due to inactivity of the original repository.

Expand All @@ -10,20 +12,56 @@ Firstly get a Tesla API token. The easiest way is to use this [utility on the Te

Then pass the token to the exporter.

npm install
npm run serve -- --token=qts-a0123456789
# install
npm install @wywywywy/tesla-prometheus-exporter

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

Or if you're using Docker or Kubernetes, 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](https://hub.docker.com/r/wywywywy/tesla_exporter).

# docker
docker run -e TESLA_EXPORTER_TOKEN=qts-a0123456789 wywywywy/tesla_exporter

Or if you're using Docker or Kubernetes, set the required environment variables as listed below (at least the `TESLA_EXPORTER_TOKEN`), and simply run the `wywywywy/tesla_exporter` image.
And then access `http://localhost:9885/metrics`.

## Options

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

- `--version` Show version number [boolean]
- `--token` TESLA API Token [required] (environment variable name: `TESLA_EXPORTER_TOKEN`)
- `--port` Used HTTP port for metrics export [default: 9885] (environment variable name: `TESLA_EXPORTER_PORT`)
- `--interval` Scraping interval in seconds [default: 120] (environment variable name: `TESLA_EXPORTER_INTERVAL`)
- `--vin` VIN of the car to be monitored. If not provided the first one will be used (environment variable name: `TESLA_EXPORTER_VIN`)
- `--retries` Number of times to retry when encountering an error before quitting. Set to 0 to disable [default: 3] (environment variable name: `TESLA_EXPORTER_RETRIES`)
- `--debug` Debug mode (environment variable name: `TESLA_EXPORTER_DEBUG`)
- `--help` Show help
| Option | Environment Variable | Description | Notes |
|---|---|---|---|
| `--version` | | Show version number | |
| `--token` | `TESLA_EXPORTER_TOKEN`| Tesla API token | **Required** |
| `--port` | `TESLA_EXPORTER_PORT`| HTTP port to serve on | Default: **9885** |
| `--interval` | `TESLA_EXPORTER_INTERVAL`| Scraping interval in seconds | Default: **120** |
| `--vin` | `TESLA_EXPORTER_VIN`| VIN of the car to be monitored | If not provided, the first one will be used |
| `--retries` | `TESLA_EXPORTER_RETRIES`| Number of times to retry when encountering an error before quitting | Set to 0 to disable. Default: **3** |
| `--debug` | `TESLA_EXPORTER_DEBUG` | Debug mode | |
| `--help` | | Show 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.
Loading

0 comments on commit d1ce69f

Please sign in to comment.