No description
Find a file
dependabot[bot] ef6a6ce5fa
Bump jest from 29.3.0 to 29.3.1 (#5)
Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) from 29.3.0 to 29.3.1.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v29.3.1/packages/jest)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-09 00:12:26 +01:00
.github Configure dependabot (#3) 2022-11-09 00:07:12 +01:00
dot-homebridge Initial version 2022-11-07 15:23:48 +01:00
src Remove bundled hap-nodejs dependency 2022-11-08 23:58:46 +01:00
tests Replace runtypes with zod, validate config, stricter eslint config 2022-11-08 19:13:34 +01:00
.eslintrc.js Let eslint check imports 2022-11-08 19:36:50 +01:00
.gitignore Initial version 2022-11-07 15:23:48 +01:00
.npmignore Release preparation 2022-11-08 14:51:36 +01:00
config.schema.json Replace runtypes with zod, validate config, stricter eslint config 2022-11-08 19:13:34 +01:00
flake.lock Initial version 2022-11-07 15:23:48 +01:00
flake.nix Replace runtypes with zod, validate config, stricter eslint config 2022-11-08 19:13:34 +01:00
jest.config.js Initial version 2022-11-07 15:23:48 +01:00
LICENSE Initial commit 2022-11-06 13:04:30 +01:00
nodemon.json Run tests via github actions 2022-11-08 22:59:00 +01:00
package-lock.json Bump jest from 29.3.0 to 29.3.1 (#5) 2022-11-09 00:12:26 +01:00
package.json Remove bundled hap-nodejs dependency 2022-11-08 23:58:46 +01:00
prettier.config.js Initial version 2022-11-07 15:23:48 +01:00
README.md Add build status to README 2022-11-09 00:05:19 +01:00
tsconfig.json Replace runtypes with zod, validate config, stricter eslint config 2022-11-08 19:13:34 +01:00

Homebridge Prometheus Exporter CI

What if we could store homebridge metrics in Prometheus

homebridge-prometheus-exporter is a plugin for homebridge that provides a metrics endpoint for Prometheus to scrape. Once the metrics are in Prometheus, they can be consumed and presented in various ways. One can use Prometheus Alerting Rules to trigger actions on certain thresholds or Grafana to build informative graphs or alerts.

A Grafana timeseries showing wattage and voltage of two home appliances on a timeseries chart

Installing

Install the plugin

Run this command to install the plugin as a global nodejs module:

npm install -g homebridge-prometheus-exporter

Configure homebridge

Edit the homebridge config.json to load the plugin:

{
    // …
    "platforms": [
    {
      "platform": "PrometheusExporter",
      "pin": "123-12-123",
    },
    // …
  ]
}

Customize homebridge startup

For homebridge-prometheus-exporter to work, homebridge has to run in "insecure mode". This means that any user who has access to your network can control your homebridge devices. This is usually not a big problem but it is still something you should consciously decide. homebridge-config-ui-x requires running in insecure mode if you want to control your devices from homebridge-config-ui-x.

To enable "insecure mode", edit the startup script for homebridge and add --insecure or -I. Assuming you run systemd, the proper way to override the config would be to use systemds drop-in mechanism.

Create /etc/systemd/system/homebridge.service.d folder:

mkdir /etc/systemd/system/homebridge.service.d

Write this drop-in configuration file to /etc/systemd/system/homebridge.service.d/insecure.conf:

[Service]
ExecStart=
ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge --insecure

The first and empty ExecStart tells systemd to forget about the ExecStart from the original service definition and the second ExecStart declares the new file. Run systemctl daemon-reload to refresh systemds unit database and then run systemd-delta --type=extended to check if the drop-in worked as expected.

You should see something like this in the output:

…
[EXTENDED]   /lib/systemd/system/homebridge.service → /etc/systemd/system/homebridge.service.d/insecure.conf
…

If you are not using systemd, first of all, you absolutely should but second of all you will likely have some sort of env file, e.g. /etc/defaults/homebridge to customize the homebridge start command. Restart homebridge using systemctl restart homebridge.

Test that the metrics endpoint is available by accesing http://homebridge-host:36123/metrics. You should see a response similar to this:

# TYPE homebridge_air_purifier_active gauge
homebridge_air_purifier_active{name="…",…} 0 1667914208196
# TYPE homebridge_air_purifier_current_air_purifier_state gauge
homebridge_air_purifier_current_air_purifier_state{name="…",…} 0 1667914208196

Configuring Prometheus

With homebridge-prometheus-exporter up and running, it is now time to configure Prometheus to scrape the config endpoint. Go to your prometheus host and edit /etc/prometheus/prometheus.yml and add the following scrape config:


scrape_configs:
  - job_name: homebridge-exporter
    static_configs:
    - targets:
      - homebridge-host:36123

Once Prometheus is restarted, metrics with the homebridge_ prefix should start to be ingested.

Customize homebridge-prometheus-exporter

homebridge-prometheus-exporter offers a few advanced settings to customize its behavior.

{
  // …
  "platforms": [
    {
      "platform": "PrometheusExporter",
      // Homebridge PIN for service authentication. String of digits, format XXX-XX-XXX. Required
      "pin": string,

      // Toggle debug mode. Run homebridge with -D if you want to see the debug output. Default: false
      "debug": boolean,

      // Prefix for all metrics. Default: "homebridge"
      "prefix": string,

      // TCP port where the Prometheus metrics server listens. Default: 36123
      "port": number,

      // How frequently the services should be rediscovered (in seconds). Default: 60
      "refresh_interval": number,

      // Timeout for the HTTP request that retrieves the homekit devices (in seconds). Default: 10
      "request_timeout": number,

      // Timeout for the service discovery (in seconds). Default: 20
      "discovery_timeout": number,
    },
    // …
  ]
}