suppress error logging when continuous

This commit is contained in:
David 2022-02-07 21:55:35 -05:00
parent 6f4dda4165
commit 6131333a93

23
main.go
View File

@ -55,8 +55,24 @@ var (
Name: "temp_nozzle",
Help: "Temperature, in celsius, of the print nozzle",
})
errCount = 0
)
func errLog(err error) {
errCount++
// reset metrics
opsFlowFactor.Set(0)
opsPrintSpeed.Set(0)
opsZPosition.Set(0)
opsBed.Set(0)
opsNozzle.Set(0)
if errCount > 5 {
log.Printf("suppressing further error logging")
return
}
log.Printf("error retrieving telemetry: %v", err)
}
func recordMetrics(ctx context.Context, config Config) {
go func() {
for {
@ -68,20 +84,21 @@ func recordMetrics(ctx context.Context, config Config) {
time.Sleep(time.Second * time.Duration(config.QueryInterval))
res, err := http.Get(config.QueryHostname + "/api/telemetry")
if err != nil {
log.Printf("error retrieving telemetry: %v", err)
errLog(err)
break
}
b, err := io.ReadAll(res.Body)
if err != nil {
log.Printf("error retrieving telemetry: %v", err)
errLog(err)
break
}
t := &Metrics{}
err = json.Unmarshal(b, t)
if err != nil {
log.Printf("error parsing telemetry: %v", err)
errLog(err)
break
}
errCount = 0
opsFlowFactor.Set(float64(t.FlowFactor))
opsPrintSpeed.Set(float64(t.PrintingSpeed))
opsZPosition.Set(t.ZPosition)