Private GIT

Skip to content
Snippets Groups Projects
Commit 8759908d authored by Richard Mitchell's avatar Richard Mitchell
Browse files

Add metrics for failed Hue API calls

parent 9fa0d8d5
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ type groupCollector struct {
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)
}
......@@ -13,6 +13,7 @@ type lightCollector struct {
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)
}
......@@ -14,6 +14,7 @@ type sensorCollector struct {
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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment