exporter-go-mystrom/README.md

91 lines
3.2 KiB
Markdown
Raw Normal View History

2021-03-18 15:33:22 +01:00
# myStrom prometheus exporter
2021-03-18 15:38:15 +01:00
Export [myStrom WiFi Switch](https://mystrom.ch/de/wifi-switch-ch/) report
2021-03-18 15:33:22 +01:00
statistics to [Prometheus](https://prometheus.io).
Metrics are retrieved using the [switch REST api](https://api.mystrom.ch/).
2022-08-29 21:59:45 +02:00
This has only be testet using a WiFi switch with firmware 3.82.60, but should be
2021-03-18 15:33:22 +01:00
backwards compatible with all 3.x firmwares.
To run it:
```bash
$ go build
$ ./mystrom-exporter [flags]
```
2022-08-29 21:59:45 +02:00
## Build instructions
The package uses `stringer` to generate `String()` methods on structs, to build the package you need to install `stringer` through `gotools`.
```bash
$ go install golang.org/x/tools/cmd/stringer@latest
# optional, should also be triggered by go build
$ go generate ./...
```
2021-03-18 15:33:22 +01:00
## Exported Metrics
| Metric | Description |
| ------ | ------- |
| mystrom_up | Was the last REST api call to the switch successful |
| mystrom_report_watt_per_sec | The average of energy consumed per second from last call this request |
| mystrom_report_temperatur | The currently measured temperature by the switch. (Might initially be wrong, but will automatically correct itself over the span of a few hours) |
| mystrom_report_relay | The current state of the relay (wether or not the relay is currently turned on) |
| mystrom_report_power | The current power consumed by devices attached to the switch |
## Flags
```bash
$ ./mystrom-exporter --help
```
| Flag | Description | Default |
| ---- | ----------- | ------- |
| web.listen-address | Address to listen on | `:9452` |
2021-12-23 16:36:04 +01:00
| web.metrics-path | Path under which to expose exporters own metrics | `/metrics` |
2022-08-29 21:59:45 +02:00
| web.device-path | Path under which the metrics of the devices are fetched, requires `target` parameter | `/device` |
2021-12-23 16:36:04 +01:00
## Prometheus configuration
2022-08-29 21:59:45 +02:00
A enhancement has been made to have only one exporter which can scrape multiple devices. This is configured in
Prometheus as follows assuming we have 4 mystrom devices and the exporter is running locally on the smae machine as
2021-12-23 16:36:04 +01:00
the Prometheus.
```yaml
- job_name: mystrom
scrape_interval: 30s
metrics_path: /device
honor_labels: true
static_configs:
- targets:
- '192.168.105.11'
- '192.168.105.12'
- '192.168.105.13'
- '192.168.105.14'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 127.0.0.1:9452
```
2021-03-18 15:33:22 +01:00
2021-11-12 12:06:57 +01:00
## Supported architectures
Using the make file, you can easily build for the following architectures, those can also be considered the tested ones:
| OS | Arch |
| -- | ---- |
| Linux | amd64 |
| Linux | arm64 |
| Linux | arm |
| Mac | amd64 |
2021-12-23 16:36:04 +01:00
| Mac | arm64 |
2021-11-12 12:06:57 +01:00
2022-08-29 21:59:45 +02:00
Since go is cross compatible with windows, and mac arm as well, you should be able to build the binary for those as well, but they aren't tested.
2021-11-12 12:06:57 +01:00
The docker image is only built & tested for amd64.
2021-03-18 15:33:22 +01:00
2021-11-12 15:34:41 +01:00
## Packages
Packages are built automatically on release, and container images on push to the main branch.
2022-08-29 21:59:45 +02:00
Take a look at the `Releases` or `Packages` tabs on Github.
2021-11-12 15:34:41 +01:00
### Container images
There is a multiplatform build available here https://github.com/peschmae/exporter-go-mystrom/pkgs/container/exporter-go-mystrom
```
docker pull ghcr.io/peschmae/exporter-go-mystrom:latest
```
2021-03-18 15:33:22 +01:00
## License
MIT License, See the included LICENSE file for terms and conditions.