Skip to content

Commit

Permalink
Merge pull request #8 from jmesserli/feature/re-add-average-power_upd…
Browse files Browse the repository at this point in the history
…ate-docs

Re-add average power consumption and update documentation
  • Loading branch information
peschmae authored May 30, 2024
2 parents 97cd8b6 + 0da8a82 commit dc109af
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 257 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.22

- name: install stringer
run: go install golang.org/x/tools/cmd/stringer@latest
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ jobs:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.30
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: 1.22
goos: linux
goarch: amd64
pre_command: |
Expand All @@ -22,10 +23,11 @@ jobs:
name: release linux/arm64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.30
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: 1.22
goos: linux
goarch: arm64
pre_command: |
Expand All @@ -35,10 +37,11 @@ jobs:
name: release linux/arm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.30
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: 1.22
goos: linux
goarch: arm
pre_command: |
Expand All @@ -48,12 +51,13 @@ jobs:
name: release darwin/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1.30
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goversion: 1.22
goos: darwin
goarch: amd64
pre_command: |
go install golang.org/x/tools/cmd/stringer@latest
&& go generate ./...
&& go generate ./...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ WORKDIR /app
USER mystrom
COPY --from=build /root/mystrom-exporter /app

CMD /app/mystrom-exporter -web.listen-address $LISTEN_ADDRESS:$LISTEN_PORT
CMD /app/mystrom-exporter -web.listen-address $LISTEN_ADDRESS:$LISTEN_PORT
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
80 changes: 48 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ Export [myStrom WiFi Switch](https://mystrom.ch/de/wifi-switch-ch/) report
statistics to [Prometheus](https://prometheus.io).

Metrics are retrieved using the [switch REST api](https://api.mystrom.ch/).
This has only be testet using a WiFi switch with firmware 3.82.60, but should be
backwards compatible with all 3.x firmwares.
This has only been tested using a Wi-Fi switch with firmware 3.82.60, but should be backwards compatible with all 3.x
firmwares. It was also tested on the 4.0.7 firmware.

To run it:

```bash
$ go build
$ ./mystrom-exporter [flags]
```

## Build instructions
The package uses `stringer` to generate `String()` methods on structs, to build the package you need to install `stringer` through `gotools`.

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
Expand All @@ -23,69 +26,82 @@ $ go generate ./...
```

## 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 |

| Metric | Description |
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `mystrom_info` | General information about the device (in the labels) |
| `mystrom_relay` | The current state of the relay (whether or not the relay is currently turned on) |
| `mystrom_power` | The current power consumed by devices attached to the switch |
| `mystrom_average_power` | The average power since the last call. For continuous consumption measurements. |
| `mystrom_temperature` | The currently measured temperature by the switch. (Might initially be wrong, but will automatically correct itself over the span of a few hours) |

## Flags

```bash
$ ./mystrom-exporter --help
```
| Flag | Description | Default |
| ---- | ----------- | ------- |
| web.listen-address | Address to listen on | `:9452` |
| web.metrics-path | Path under which to expose exporters own metrics | `/metrics` |
| web.device-path | Path under which the metrics of the devices are fetched, requires `target` parameter | `/device` |

| Flag | Description | Default |
|----------------------|--------------------------------------------------------------------------------------|------------|
| `web.listen-address` | Address to listen on | `:9452` |
| `web.metrics-path` | Path under which to expose exporters own metrics | `/metrics` |
| `web.device-path` | Path under which the metrics of the devices are fetched, requires `target` parameter | `/device` |

## Prometheus configuration
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
the Prometheus.

An 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 same machine as 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'
- targets:
- '192.168.105.11'
- '192.168.105.12'
- '192.168.105.13'
- '192.168.105.14'
relabel_configs:
- source_labels: [__address__]
- source_labels: [ __address__ ]
target_label: __param_target
- target_label: __address__
replacement: 127.0.0.1:9452
```
## Supported architectures
Using the make file, you can easily build for the following architectures, those can also be considered the tested ones:
| OS | Arch |
| -- | ---- |
| OS | Arch |
|-------|-------|
| Linux | amd64 |
| Linux | arm64 |
| Linux | arm |
| Mac | amd64 |
| Mac | arm64 |
| Linux | arm |
| Mac | amd64 |
| Mac | arm64 |
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.
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.
The docker image is only built & tested for amd64.
## Packages
Packages are built automatically on release, and container images on push to the main branch.
Take a look at the `Releases` or `Packages` tabs on Github.
Take a look at the `Releases` or `Packages` tabs on GitHub.

### Container images
There is a multiplatform build available here https://github.com/peschmae/exporter-go-mystrom/pkgs/container/exporter-go-mystrom

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
```
## License
MIT License, See the included LICENSE file for terms and conditions.
23 changes: 17 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
module mystrom-exporter

go 1.15
go 1.22

require (
github.com/gorilla/mux v1.7.3
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/common v0.26.0
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/tools v0.1.12
github.com/gorilla/mux v1.8.1
github.com/prometheus/client_golang v1.19.1
github.com/sirupsen/logrus v1.9.3
golang.org/x/tools v0.21.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit dc109af

Please sign in to comment.