diff --git a/groups.go b/groups.go index b85f3dc2b992528b378800a85ea8854e278406f2..cc42a260b085cf29033170dfb606ca1c77d1ada5 100644 --- a/groups.go +++ b/groups.go @@ -7,11 +7,12 @@ import ( ) type groupCollector struct { - bridge *hue.Bridge - groupBrightness *prometheus.GaugeVec - groupHue *prometheus.GaugeVec - groupSaturation *prometheus.GaugeVec - groupOn *prometheus.GaugeVec + bridge *hue.Bridge + groupBrightness *prometheus.GaugeVec + groupHue *prometheus.GaugeVec + groupSaturation *prometheus.GaugeVec + groupOn *prometheus.GaugeVec + groupScrapesFailed prometheus.Counter } var variableGroupLabelNames = []string{ @@ -59,6 +60,14 @@ func NewGroupCollector(namespace string, bridge *hue.Bridge) prometheus.Collecto }, variableLightLabelNames, ), + groupScrapesFailed: prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: "group", + Name: "scrapes_failed", + Help: "Count of scrapes of group data from the Hue bridge that have failed", + }, + ), } return c @@ -69,6 +78,7 @@ func (c groupCollector) Describe(ch chan<- *prometheus.Desc) { c.groupBrightness.Describe(ch) c.groupHue.Describe(ch) c.groupSaturation.Describe(ch) + c.groupScrapesFailed.Describe(ch) } func (c groupCollector) Collect(ch chan<- prometheus.Metric) { @@ -80,6 +90,7 @@ func (c groupCollector) Collect(ch chan<- prometheus.Metric) { groups, err := c.bridge.GetAllGroups() if err != nil { log.Errorf("Failed to update groups: %v", err) + c.groupScrapesFailed.Inc() } for _, group := range groups { @@ -108,4 +119,5 @@ func (c groupCollector) Collect(ch chan<- prometheus.Metric) { c.groupBrightness.Collect(ch) c.groupHue.Collect(ch) c.groupSaturation.Collect(ch) + c.groupScrapesFailed.Collect(ch) } diff --git a/lights.go b/lights.go index f7219d5ba0c656a795957c0e42c1f5a897fe55b4..1e291ddf740ef992d1fc8d471bac4c579883801a 100644 --- a/lights.go +++ b/lights.go @@ -7,12 +7,13 @@ import ( ) type lightCollector struct { - bridge *hue.Bridge - lightBrightness *prometheus.GaugeVec - lightHue *prometheus.GaugeVec - lightSaturation *prometheus.GaugeVec - lightOn *prometheus.GaugeVec - lightReachable *prometheus.GaugeVec + bridge *hue.Bridge + lightBrightness *prometheus.GaugeVec + lightHue *prometheus.GaugeVec + lightSaturation *prometheus.GaugeVec + lightOn *prometheus.GaugeVec + lightReachable *prometheus.GaugeVec + lightScrapesFailed prometheus.Counter } var variableLightLabelNames = []string{ @@ -73,6 +74,14 @@ func NewLightCollector(namespace string, bridge *hue.Bridge) prometheus.Collecto }, variableLightLabelNames, ), + lightScrapesFailed: prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: "light", + Name: "scrapes_failed", + Help: "Count of scrapes of light data from the Hue bridge that have failed", + }, + ), } return c @@ -84,6 +93,7 @@ func (c lightCollector) Describe(ch chan<- *prometheus.Desc) { c.lightHue.Describe(ch) c.lightSaturation.Describe(ch) c.lightReachable.Describe(ch) + c.lightScrapesFailed.Describe(ch) } func (c lightCollector) Collect(ch chan<- prometheus.Metric) { @@ -96,6 +106,7 @@ func (c lightCollector) Collect(ch chan<- prometheus.Metric) { lights, err := c.bridge.GetAllLights() if err != nil { log.Errorf("Failed to update lights: %v", err) + c.lightScrapesFailed.Inc() } for _, light := range lights { @@ -128,4 +139,5 @@ func (c lightCollector) Collect(ch chan<- prometheus.Metric) { c.lightHue.Collect(ch) c.lightSaturation.Collect(ch) c.lightReachable.Collect(ch) + c.lightScrapesFailed.Collect(ch) } diff --git a/sensors.go b/sensors.go index 3d27277c9bdbcd68267994a053b5ced1dbcaadad..5699a9e8f926669b567d7b370940a8da44b673ec 100644 --- a/sensors.go +++ b/sensors.go @@ -7,13 +7,14 @@ import ( ) type sensorCollector struct { - bridge *hue.Bridge - ignoreTypes []string - sensorValue *prometheus.GaugeVec - sensorLastUpdated *prometheus.GaugeVec - sensorOn *prometheus.GaugeVec - sensorBattery *prometheus.GaugeVec - sensorReachable *prometheus.GaugeVec + bridge *hue.Bridge + ignoreTypes []string + sensorValue *prometheus.GaugeVec + sensorLastUpdated *prometheus.GaugeVec + sensorOn *prometheus.GaugeVec + sensorBattery *prometheus.GaugeVec + sensorReachable *prometheus.GaugeVec + sensorScrapesFailed prometheus.Counter } var variableSensorLabelNames = []string{ @@ -84,6 +85,14 @@ func NewSensorCollector(namespace string, bridge *hue.Bridge, ignoreTypes []stri }, variableSensorLabelNames, ), + sensorScrapesFailed: prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: "sensor", + Name: "scrapes_failed", + Help: "Count of scrapes of sensor data from the Hue bridge that have failed", + }, + ), } return c @@ -95,6 +104,7 @@ func (c sensorCollector) Describe(ch chan<- *prometheus.Desc) { c.sensorLastUpdated.Describe(ch) c.sensorOn.Describe(ch) c.sensorReachable.Describe(ch) + c.sensorScrapesFailed.Describe(ch) } func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { @@ -107,6 +117,7 @@ func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { sensors, err := c.bridge.GetAllSensors() if err != nil { log.Errorf("Failed to update sensors: %v", err) + c.sensorScrapesFailed.Inc() } for _, sensor := range sensors { @@ -165,4 +176,5 @@ func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { c.sensorLastUpdated.Collect(ch) c.sensorOn.Collect(ch) c.sensorReachable.Collect(ch) + c.sensorScrapesFailed.Collect(ch) }