prom.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package telemetry
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/prometheus/client_golang/prometheus/promauto"
  7. "github.com/prometheus/client_golang/prometheus/promhttp"
  8. )
  9. var (
  10. //LightbulbActivations is a counter for the number of times the screen
  11. // has changed power states
  12. LightbulbActivations = promauto.NewCounter(prometheus.CounterOpts{
  13. Name: "occupancyd_lightbulb_activations",
  14. Help: "The number of times the screen has changed power states",
  15. })
  16. //OccupancyActivations is a counter for the number of times the occupancy
  17. // sensor has changed state
  18. OccupancyActivations = promauto.NewCounter(prometheus.CounterOpts{
  19. Name: "occupancyd_occupancy_activations",
  20. Help: "The number of times the occupancy sensor has changed state",
  21. })
  22. //IdleTime is a counter for the number of idle seconds, reported by xgb
  23. IdleTime = promauto.NewGauge(prometheus.GaugeOpts{
  24. Name: "occupancyd_idle_seconds",
  25. Help: "Number of seconds x11 has been idle",
  26. })
  27. )
  28. //PrometheusMetricsHandler Turn on promtheus metrics handler
  29. func PrometheusMetricsHandler(promPort int) {
  30. serveAddress := fmt.Sprintf(":%d", promPort)
  31. http.Handle("/metrics", promhttp.Handler())
  32. http.ListenAndServe(serveAddress, nil)
  33. }