Skip to content

Commit 108e3b8

Browse files
committed
added new camera status metric
1 parent c5a1f48 commit 108e3b8

File tree

4 files changed

+189
-85
lines changed

4 files changed

+189
-85
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ ai_servererror | Count of AI server not responding errors in the current logfile
139139
ai_notresponding | Count of AI not responding errors in the current logfile
140140
logerror | Count of unique errors in the current logfile
141141
logerror_total | Count of total errors in the logs
142+
camera_status | Status of each camera. 0=up, 1=down

blueiris/blueirisMetrics.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type aidata struct {
2424
}
2525

2626
var latestai = make(map[string]string)
27+
var camerastatus = make(map[string]float64)
2728

2829
var (
2930
timeoutcount float64
@@ -94,6 +95,7 @@ func BlueIris(ch chan<- prometheus.Metric, m common.MetricInfo, SecMet []common.
9495
alertcount := aiMetrics[camera+matchType].alertcount
9596
alertcount++
9697

98+
camerastatus[camera] = 0
9799
aiMetrics[camera+matchType] = aidata{
98100
camera: camera,
99101
duration: duration,
@@ -156,6 +158,10 @@ func BlueIris(ch chan<- prometheus.Metric, m common.MetricInfo, SecMet []common.
156158
}
157159
case "logerror_total":
158160
ch <- prometheus.MustNewConstMetric(sm.Desc, sm.Type, errorMetricsTotal)
161+
case "camera_status":
162+
for k, a := range camerastatus {
163+
ch <- prometheus.MustNewConstMetric(sm.Desc, sm.Type, a, k)
164+
}
159165
}
160166
}
161167

@@ -168,19 +174,15 @@ func findObject(line string) (match []string, r *regexp.Regexp, matchType string
168174

169175
if strings.HasSuffix(line, "AI: timeout") {
170176
timeoutcount++
171-
return nil, nil, ""
172177

173178
} else if strings.Contains(line, "AI has been restarted") {
174179
restartCount++
175-
return nil, nil, ""
176180

177181
} else if strings.Contains(line, "DeepStack: Server error") {
178182
servererrorcount++
179-
return nil, nil, ""
180183

181184
} else if strings.HasSuffix(line, "AI: not responding") {
182185
notrespondingcount++
183-
return nil, nil, ""
184186

185187
} else if strings.Contains(line, "AI:") || strings.Contains(line, "DeepStack:") {
186188
newLine := strings.Join(strings.Fields(line), " ")
@@ -214,10 +216,24 @@ func findObject(line string) (match []string, r *regexp.Regexp, matchType string
214216
} else {
215217
errorMetrics[e] = 1
216218
}
217-
return nil, nil, ""
218-
// return match, r, "error"
219219

220220
}
221+
} else if strings.Contains(line, "Signal:") {
222+
r := regexp.MustCompile(`(?P<camera>[^\s\\]*)(\s*Signal:\s)(?P<status>.+)`)
223+
match := r.FindStringSubmatch(line)
224+
cameraMatch := r.SubexpIndex("camera")
225+
statusMatch := r.SubexpIndex("status")
226+
227+
camera := match[cameraMatch]
228+
status := match[statusMatch]
229+
230+
if strings.Contains(status, "Failed") || strings.Contains(status, "network retry") || strings.Contains(status, "error") {
231+
camerastatus[camera] = 1
232+
} else if strings.Contains(status, "restored") {
233+
camerastatus[camera] = 0
234+
} else {
235+
common.BIlogger(fmt.Sprintf("Unable to parse log line: \n%v", line), "console")
236+
}
221237
}
222238
return nil, nil, ""
223239
}

0 commit comments

Comments
 (0)