Compare commits
No commits in common. "6f2a73f46e0625cc4a38074a02a1bbfd02f09de6" and "12f983b16d8dc3a5ca8cb60ed82a57b98334d8a8" have entirely different histories.
6f2a73f46e
...
12f983b16d
7 changed files with 37 additions and 207 deletions
|
@ -1,5 +1,3 @@
|
|||
USERNAME=*****
|
||||
HUE_URL=192.168.178.34
|
||||
LISTEN_ADDRESS=127.0.0.1:9773
|
||||
AUTH_USER=user
|
||||
AUTH_PASS=password
|
||||
METRICS_FILE=******
|
18
.github/workflows/docker-image.yml
vendored
18
.github/workflows/docker-image.yml
vendored
|
@ -1,18 +0,0 @@
|
|||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build the Docker image
|
||||
run: docker build . --file Dockerfile --tag hue_exporter:$(date +%s)
|
|
@ -9,7 +9,6 @@ RUN go build -o /hue_exporter
|
|||
FROM alpine:latest
|
||||
WORKDIR /
|
||||
COPY --from=build /hue_exporter /hue_exporter
|
||||
COPY hue_metrics.json ./
|
||||
EXPOSE 9773
|
||||
|
||||
ENTRYPOINT [ "sh", "-c", "/hue_exporter -username ${USERNAME} -hue-url ${HUE_URL} -metrics-file hue_metrics.json -listen-address ${LISTEN_ADDRESS} -auth.user ${AUTH_USER} -auth.pass ${AUTH_PASS}" ]
|
||||
ENTRYPOINT [ "sh", "-c", "/hue_exporter -username ${USERNAME} -hue-url ${HUE_URL} -metrics-file ${METRICS_FILE} " ]
|
12
README.md
12
README.md
|
@ -4,13 +4,13 @@ This exporter exports some variables from Philips Hue Bridge
|
|||
(https://www.philips-hue.com)
|
||||
to prometheus.
|
||||
|
||||
## Build
|
||||
## Building
|
||||
|
||||
go get github.com/aexel90/hue_exporter/
|
||||
cd $GOPATH/src/github.com/aexel90/hue_exporter
|
||||
go install
|
||||
|
||||
## Execute
|
||||
## Running
|
||||
|
||||
How to create a user for your bridge is described here: https://developers.meethue.com/develop/get-started-2/
|
||||
|
||||
|
@ -34,12 +34,6 @@ Usage:
|
|||
-username string
|
||||
The username token having bridge access
|
||||
|
||||
## Docker
|
||||
|
||||
cp .env.template .env
|
||||
vi .env
|
||||
docker-compose up -d --build
|
||||
|
||||
## Example execution
|
||||
|
||||
### Running within prometheus:
|
||||
|
@ -82,6 +76,4 @@ Usage:
|
|||
|
||||
Dashboard ID is 13645.
|
||||
|
||||
https://grafana.com/grafana/dashboards/13645
|
||||
|
||||
![Grafana](https://raw.githubusercontent.com/aexel90/hue_exporter/main/grafana/screenshot.jpg)
|
|
@ -1,14 +1,13 @@
|
|||
version: '3.4'
|
||||
|
||||
services:
|
||||
hue_exporter:
|
||||
stravakomootsync:
|
||||
image: hue_exporter
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
dockerfile: ./Dockerfile.multistage
|
||||
restart: unless-stopped
|
||||
container_name: hue_exporter
|
||||
#network_mode: "host"
|
||||
ports:
|
||||
- 9773:9773
|
||||
env_file:
|
||||
|
|
|
@ -1,47 +1,4 @@
|
|||
{
|
||||
"__inputs": [
|
||||
{
|
||||
"name": "DS_PROMETHEUS",
|
||||
"label": "Prometheus",
|
||||
"description": "",
|
||||
"type": "datasource",
|
||||
"pluginId": "prometheus",
|
||||
"pluginName": "Prometheus"
|
||||
}
|
||||
],
|
||||
"__elements": {},
|
||||
"__requires": [
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "9.2.1"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "graph",
|
||||
"name": "Graph (old)",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "stat",
|
||||
"name": "Stat",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "table",
|
||||
"name": "Table",
|
||||
"version": ""
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": [
|
||||
{
|
||||
|
@ -68,14 +25,14 @@
|
|||
"fiscalYearStartMonth": 0,
|
||||
"gnetId": 13645,
|
||||
"graphTooltip": 0,
|
||||
"id": null,
|
||||
"id": 4,
|
||||
"links": [],
|
||||
"liveNow": false,
|
||||
"panels": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -118,14 +75,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -140,7 +92,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -183,13 +135,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -204,7 +152,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -247,14 +195,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -269,7 +212,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -312,14 +255,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -334,7 +272,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -378,14 +316,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -400,7 +333,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -443,14 +376,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -465,7 +393,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -509,14 +437,9 @@
|
|||
"text": {},
|
||||
"textMode": "value"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_bridge_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -531,7 +454,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"description": "",
|
||||
"fieldConfig": {
|
||||
|
@ -574,14 +497,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "sum(hue_light_state)",
|
||||
"format": "table",
|
||||
"hide": false,
|
||||
|
@ -598,7 +516,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"description": "",
|
||||
"fieldConfig": {
|
||||
|
@ -641,14 +559,9 @@
|
|||
"text": {},
|
||||
"textMode": "auto"
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "count(hue_light_state)-sum(hue_light_state)",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -673,7 +586,7 @@
|
|||
"dashes": false,
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"decimals": 1,
|
||||
"fill": 0,
|
||||
|
@ -706,7 +619,7 @@
|
|||
"alertThreshold": false
|
||||
},
|
||||
"percentage": false,
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"pointradius": 2,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
|
@ -716,15 +629,9 @@
|
|||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "10^((hue_sensor_lightlevel-1)/10000)",
|
||||
"interval": "",
|
||||
"legendFormat": "{{name}}",
|
||||
"range": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
|
@ -774,7 +681,7 @@
|
|||
"dashes": false,
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"decimals": 1,
|
||||
"fill": 0,
|
||||
|
@ -807,7 +714,7 @@
|
|||
"alertThreshold": false
|
||||
},
|
||||
"percentage": false,
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"pointradius": 2,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
|
@ -817,15 +724,9 @@
|
|||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_sensor_temperature/100",
|
||||
"interval": "",
|
||||
"legendFormat": "{{name}}",
|
||||
"range": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
|
@ -866,7 +767,7 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
|
@ -1022,14 +923,9 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_sensor_info{type=~\"ZLL.*\"}",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -1082,9 +978,8 @@
|
|||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
"uid": "nLstfzWgz"
|
||||
},
|
||||
"description": "",
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"color": {
|
||||
|
@ -1277,14 +1172,9 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"pluginVersion": "9.2.1",
|
||||
"pluginVersion": "8.5.3",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "${DS_PROMETHEUS}"
|
||||
},
|
||||
"editorMode": "code",
|
||||
"expr": "hue_light_info",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
|
@ -1339,20 +1229,20 @@
|
|||
}
|
||||
],
|
||||
"refresh": "5m",
|
||||
"schemaVersion": 37,
|
||||
"schemaVersion": 36,
|
||||
"style": "dark",
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": []
|
||||
},
|
||||
"time": {
|
||||
"from": "now-30m",
|
||||
"from": "now-6h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {},
|
||||
"timezone": "",
|
||||
"title": "Philips Hue",
|
||||
"uid": "X7uYULiRk",
|
||||
"version": 1,
|
||||
"version": 6,
|
||||
"weekStart": ""
|
||||
}
|
32
main.go
32
main.go
|
@ -21,31 +21,12 @@ var (
|
|||
flagUsername = flag.String("username", "", "The username token having bridge access")
|
||||
flagAddress = flag.String("listen-address", "127.0.0.1:9773", "The address to listen on for HTTP requests.")
|
||||
flagMetricsFile = flag.String("metrics-file", "hue_metrics.json", "The JSON file with the metric definitions.")
|
||||
authUser = flag.String("auth.user", "", "Username for basic auth.")
|
||||
authPass = flag.String("auth.pass", "", "Password for basic auth. Enables basic auth if set.")
|
||||
|
||||
flagTest = flag.Bool("test", false, "Test configured metrics")
|
||||
flagCollect = flag.Bool("collect", false, "Collect all available metrics")
|
||||
flagCollectFile = flag.String("collect-file", "", "The JSON file where to store collect results")
|
||||
)
|
||||
|
||||
type basicAuthHandler struct {
|
||||
handler http.HandlerFunc
|
||||
user string
|
||||
password string
|
||||
}
|
||||
|
||||
func (h *basicAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
user, password, ok := r.BasicAuth()
|
||||
if !ok || password != h.password || user != h.user {
|
||||
w.Header().Set("WWW-Authenticate", "Basic realm=\"metrics\"")
|
||||
http.Error(w, "Invalid username or password", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
h.handler(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
@ -74,18 +55,7 @@ func main() {
|
|||
hueCollector.Test()
|
||||
} else {
|
||||
prometheus.MustRegister(hueCollector)
|
||||
handler := promhttp.Handler()
|
||||
if *authUser != "" || *authPass != "" {
|
||||
if *authUser == "" || *authPass == "" {
|
||||
log.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth")
|
||||
}
|
||||
handler = &basicAuthHandler{
|
||||
handler: promhttp.Handler().ServeHTTP,
|
||||
user: *authUser,
|
||||
password: *authPass,
|
||||
}
|
||||
}
|
||||
http.Handle("/metrics", handler)
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
fmt.Printf("metrics available at http://%s/metrics\n", *flagAddress)
|
||||
log.Fatal(http.ListenAndServe(*flagAddress, nil))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue