1 unstable release

0.1.0 Jan 22, 2019

#848 in Hardware support

MIT license

26KB
531 lines

kasa_exporter

Prometheus exporter for TP-Link Kasa smart home products.

This is an experiment in learning Rust and tokio library.

Supported products

Smart wifi plug (HS-110)

HS-110

Exported metrics

All three as reported by API with device_id and device_alias labels:

  • device_current
  • device_power
  • device_voltage

Building

Install Rust, then from cloned repo:

$ cargo build

If you wish to see debug output with requests and responses to Kasa API, you can pass --features kasa_debug to cargo build:

$ cargo build --features kasa_debug

Usage

After Building, run the command to get help:

$ ./target/debug/kasa_exporter --help
kasa_exporter 0.1.0
Ivan Babrou <hello@ivan.computer>


USAGE:
    kasa_exporter [OPTIONS] --kasa.password <kasa.password> --kasa.username <kasa.username>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --kasa.password <kasa.password>              Password to log into Kasa service
        --kasa.username <kasa.username>              Username to log into Kasa service
        --web.listen-address <web.listen-address>
            Address on which to expose metrics and web interface [default: [::1]:12345]

Note that web.listen-address expects <ip>:<port>, e.g.:

  • 127.0.0.1:12345 for IPv4
  • [::1]:12345 for IPv6

Example response:

$ curl http://localhost:12345/
# HELP device_electric_current_amperes Corrent reading from device
# TYPE device_electric_current_amperes gauge
device_electric_current_amperes{device_alias="Banana",device_id="800607035E84C0B634C36B7DF52CCEC3188C1BAB"} 0.256972
device_electric_current_amperes{device_alias="Potato",device_id="800691A498F774D60997B91E241EE2CC18D08921"} 0.031424
# HELP device_electric_potential_volts Voltage reading from device
# TYPE device_electric_potential_volts gauge
device_electric_potential_volts{device_alias="Banana",device_id="800607035E84C0B634C36B7DF52CCEC3188C1BAB"} 123.16094
device_electric_potential_volts{device_alias="Potato",device_id="800691A498F774D60997B91E241EE2CC18D08921"} 123.130631
# HELP device_electric_power_watts Power reading from device
# TYPE device_electric_power_watts gauge
device_electric_power_watts{device_alias="Banana",device_id="800607035E84C0B634C36B7DF52CCEC3188C1BAB"} 30.071476
device_electric_power_watts{device_alias="Potato",device_id="800691A498F774D60997B91E241EE2CC18D08921"} 0.750854

License

MIT

Dependencies

~13–26MB
~377K SLoC