Git Product home page Git Product logo

smartdevicemanagement_exporter's Introduction

smartdevicemanagement_exporter

Google Nest Smart Device Management exporter for Prometheus.

Prerequisites

Guides you through the prerequisite items required to start using this exporter.

Nest account migration

Ensure you migrate your Nest account to Google if you have not already done so https://www.blog.google/products/google-nest/its-time-nest-users-can-now-switch-google-accounts.

Sign up for Google Device Access Console

Follow the getting started guide https://developers.google.com/nest/device-access/get-started.

When you are done you should have the following items completed.

  1. Register for the Device Access program.
  2. Activate a supported Nest device with a Google account.
  3. Create a Google Cloud Platform (GCP) project to enable the SDM API and get an OAuth 2.0 client ID.
  4. Create a Device Access project to receive a Project ID.

Installation

You can download the binary for your OS and Architecture on the releases page. A Docker image is also provided which is also found on the releases page.

https://github.com/ryancurrah/smartdevicemanagement_exporter/releases

Configuration

All the configuration parameters for this exporter.

  • -listen-address. Envvar: LISTEN_ADDRESS. Default: :8080. Address to listen on for HTTP requests.
  • -project-id. Envvar: PROJECT_ID. Default: . ID of the Smart Device Management project (Required).
  • -credentials. Envvar: CREDENTIALS. Default: client_secret.json. Location on disk to the Oauth2 credentials JSON file.
  • -refresh-token. Envvar: REFRESH_TOKEN. Default: refresh_token.json. Location on disk to store the Oauth2 refresh token JSON file.
  • -record-metrics-delay. Envvar: RECORD_METRICS_DELAY. Default: 1m. Delay between queries to the Smart Device Management API for recording metrics.

Endpoints

All the HTTP endpoints for this exporter.

  • /metrics. Prometheus metrics are exposed here for scraping.
  • /authstatus. Provides the current authentication status of the exporter with Google APIs.
  • /authorize. Starts or resets the authentication of the exporter with the Partner Connection Manager.

Usage

Assuming you have stored the client_secret.json file in the current working directory start the exporter.

./smartdevicemanagement_exporter -project-id e14044ff-a995-4733-9672-ddad34c970d5
2021/01/03 14:19:48 running

Now authorize the exporter to use the Google APIs by visiting the authorize endpoint in your browser. You only have to do this once or when the refresh_token.json file is no longer valid.

open http://127.0.0.1:8080/authorize

Once your done filling out the prompts that authorize the exporter you will be redirected back to the exporter on a page that says: authorization code received from partner connection manager.

You can check the stdout and /authstatus page to see if the exporter has been successfully authorized.

open http://127.0.0.1:8080/authstatus

Now the exporter will start recording metrics.

open http://127.0.0.1:8080/metrics

Metrics

Currently only Thermostat devices are supported.

# HELP sdm_thermostat_humidity_ambientHumidityPercent Percent humidity, measured at the device.
# TYPE sdm_thermostat_humidity_ambientHumidityPercent gauge
sdm_thermostat_humidity_ambientHumidityPercent{CustomName="",Name="DU1AeyLeA",Room="Hallway",Type="sdm.devices.types.THERMOSTAT"} 34

# HELP sdm_thermostat_temperature_ambientTemperatureCelsius Temperature in degrees Celsius, measured at the device.
# TYPE sdm_thermostat_temperature_ambientTemperatureCelsius gauge
sdm_thermostat_temperature_ambientTemperatureCelsius{CustomName="",Name="DU1AeyLeA",Room="Hallway",Type="sdm.devices.types.THERMOSTAT"} 22.189987

# HELP sdm_thermostat_thermostatTemperatureSetpoint_coolCelsius Target temperature in Celsius for thermostat COOL and HEATCOOL modes.
# TYPE sdm_thermostat_thermostatTemperatureSetpoint_coolCelsius gauge
sdm_thermostat_thermostatTemperatureSetpoint_coolCelsius{CustomName="",Name="DU1AeyLeA",Room="Hallway",Type="sdm.devices.types.THERMOSTAT"} 0

# HELP sdm_thermostat_thermostatTemperatureSetpoint_heatCelsius Target temperature in Celsius for thermostat HEAT and HEATCOOL modes.
# TYPE sdm_thermostat_thermostatTemperatureSetpoint_heatCelsius gauge
sdm_thermostat_thermostatTemperatureSetpoint_heatCelsius{CustomName="",Name="DU1AeyLeA",Room="Hallway",Type="sdm.devices.types.THERMOSTAT"} 22

smartdevicemanagement_exporter's People

Contributors

ryancurrah avatar dependabot[bot] avatar dependabot-preview[bot] avatar

Stargazers

Roman avatar Jiri Tyr avatar  avatar Steven Tobias avatar Tom Carrio avatar John Adams avatar Greg Sharpe avatar Julien avatar

Watchers

Julien avatar  avatar

Forkers

stobias123

smartdevicemanagement_exporter's Issues

CI

Thanks for your work. Would you like to have some help? I think we could use github action to set up some CI.

Using refresh_token not refreshing?

It looks like the refresh token support isn't working as expected. Once you get the exporter up and running with --credentials and --refresh-token, it scrapes Nest API endpoints as expected, but then stops working after two hours returning:

2023/08/05 09:47:24 unable to get devices: googleapi: Error 401: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
More details:
Reason: authError, Message: Invalid Credentials

My understanding is that tools should use the refresh token to refresh access, but I'm no expert in OATH2 so maybe I'm missing something? I'm running the exporter with:

./smartdevicemanagement_exporter --listen-address :9788 --project-id <red_guid> --credentials ./client_secret.json --refresh-token ./refresh_token.json

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.