-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d0c1a99
Showing
192 changed files
with
53,102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/hue_exporter.yml | ||
/hue_exporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM quay.io/prometheus/busybox:latest | ||
MAINTAINER Richard Mitchell <[email protected]> | ||
|
||
COPY hue_exporter /bin/hue_exporter | ||
COPY hue_exporter.example.yml /etc/hue_exporter/config.yml | ||
|
||
EXPOSE 9366 | ||
ENTRYPOINT [ "/bin/hue_exporter" ] | ||
CMD [ "--config.file=/etc/hue_exporter/config.yml" ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/collinux/gohue" | ||
source = "github.com/mitchellrj/gohue" | ||
branch = "group_support" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/golang/glog" | ||
|
||
[[constraint]] | ||
name = "github.com/prometheus/client_golang" | ||
version = "0.8.0" | ||
|
||
[[constraint]] | ||
name = "gopkg.in/yaml.v2" | ||
version = "2.2.1" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MIT / X Consortium License | ||
========================== | ||
|
||
Copyright (C) 2018 Richard Mitchell | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM 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. | ||
|
||
Except as contained in this notice, the name of Richard Mitchell shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Richard Mitchell. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
all: style staticcheck build test | ||
|
||
style: | ||
gofmt -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' | ||
|
||
test: | ||
go test ./... | ||
|
||
format: | ||
go fmt ./... | ||
|
||
vet: | ||
go vet ./... | ||
|
||
staticcheck: | ||
staticcheck ./... | ||
|
||
build: | ||
go build | ||
|
||
docker: | ||
|
||
|
||
.PHONY: all style test format vet staticcheck build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Hue exporter | ||
|
||
This is a Prometheus exporter for the Philips Hue system. It's written in Go. | ||
|
||
It exposes metrics about lights, groups and sensors. I hope you like it. | ||
|
||
There are other Hue exporter projects. They didn't quite do what I wanted and to make them do what I wanted would have meant some pretty major changes. They might work for you though: | ||
|
||
* [huepro](https://github.com/stevenbower/huepro) | ||
* [hue_exporter](https://github.com/nilsding/hue_exporter) | ||
|
||
## Light metrics | ||
|
||
Each light metric is labelled with the friendly name, the model, the type, the product name, the manufacturer name, and the unique ID. | ||
|
||
* `hue_light_brightness` | ||
* `hue_light_hue` | ||
* `hue_light_saturation` | ||
* `hue_light_on`: `0` means off, `1` means on | ||
* `hue_light_reachable`: `0` or `1` representing false or true | ||
|
||
## Group metrics | ||
|
||
Each group metric is labelled with the name, and the type. | ||
|
||
* `hue_group_brightness` | ||
* `hue_group_hue` | ||
* `hue_group_saturation` | ||
* `hue_group_on`: `0` means off, `1` means some lights within the group are on, `2` means all lights within the group are on | ||
|
||
## Sensor metrics | ||
|
||
Each sensor metric is labelled with the friendly name, the model, the type, the product name, the manufacturer name, and the unique ID. | ||
|
||
* `hue_sensor_value`: value varies depending on the `type` of the sensor. For switches, it's the value of the last button pressed; for daylight and presence sensors it's a `0` or `1` representing false or true values; for the temperature sensor it's hundredths of a degree celsius; for the light level sensor it's Lux. | ||
* `hue_sensor_battery`: battery level percentage (0 for sensors that have no battery) | ||
* `hue_sensor_last_updated`: last updated timestamp (Unix epoch) | ||
* `hue_sensor_on`: `0` or `1` representing false or true | ||
* `hue_sensor_reachable`: `0` or `1` representing false or true | ||
|
||
Some sensor type values you might find useful: | ||
|
||
* `Daylight`: the Hue Hub's built-in "daylight" sensor, based on sunset / sunrise in your configured location | ||
* `ZGPSwitch`: the Hue tap switch | ||
* `ZLLSwitch`: the Hue dimmer switch | ||
* `ClipGenericStatus`: a generic sensor, usually a pseudo-sensor created through the API for automation purposes | ||
* `ZLLTemperature`: the temperature sensor in the Hue motion sensor | ||
* `ZLLPresence`: the presence sensor in the Hue motion sensor | ||
* `ZLLLightLevel`: the light level sensor in the Hue motion sensor | ||
|
||
## Metric structure | ||
|
||
> Hey, why didn't you combine the metrics for brightness and hue and saturation and on and reachable? | ||
I tried that, but because of the different label combinations, it didn't really work and you ended up with a load of empty labels. | ||
|
||
## Configuration | ||
|
||
There's an example configuration file `hue_exporter.example.yml` in this repository, but you can also generate one! Run `hue_exporter generate` to have the app discover to your Hue bridge and create an API user for itself, then write the necessary configuration. | ||
|
||
## Running | ||
|
||
``` | ||
hue_exporter --config.file hue_exporter.yml --listen.address :9366 | ||
``` | ||
|
||
Those flag values are the defaults, so you could just run `hue_exporter` on its own if you're happy with those. | ||
|
||
## License | ||
|
||
MIT / X11 Consortium license. I'd prefer to use Apache 2.0, but the excellent Hue library that this app uses is GPL 2.0 and that isn't compatible with Apache. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
hue "github.com/collinux/gohue" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func generateConfig(outputFile *string) { | ||
bridges, err := hue.FindBridges() | ||
if err != nil { | ||
panic(fmt.Sprintf("Error while searching for Hue bridges on the local network: %v\n", err)) | ||
} | ||
if len(bridges) == 0 { | ||
panic("No Hue bridges found on the local network.\n") | ||
} else if len(bridges) == 1 { | ||
fmt.Printf("Found 1 Hue bridge on the local network: %s (%v).\n", bridges[0].Info.Device.FriendlyName, bridges[0].IPAddress) | ||
} else { | ||
panic("Found multiple Hue bridges on the local network.\n") | ||
} | ||
|
||
bridge := bridges[0] | ||
var apiKey string | ||
|
||
for { | ||
apiKey, err = bridge.CreateUser("hue_exporter") | ||
if err != nil { | ||
print("Creating API key failed. Have you pushed the link button on your hub?\nPress Enter to continue.") | ||
bufio.NewReader(os.Stdin).ReadBytes('\n') | ||
} else { | ||
break | ||
} | ||
} | ||
println("Successfully created API user.") | ||
|
||
config, err := yaml.Marshal(Config{ | ||
IPAddr: bridge.IPAddress, | ||
APIKey: apiKey, | ||
}) | ||
|
||
if err != nil { | ||
panic(fmt.Sprintf("Error while generating configuration file content: %v.\n", err)) | ||
} | ||
|
||
err = ioutil.WriteFile(*outputFile, config, 0660) | ||
if err != nil { | ||
panic(fmt.Sprintf("Error while writing configuration file content to %s: %v.\n", *outputFile, err)) | ||
} | ||
fmt.Printf("Configuration written to %s.", *outputFile) | ||
} |
Oops, something went wrong.