From 8bd7991b2bbb580bf44665a264c0d13a4b3f48d7 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 18 Oct 2022 13:31:49 -0400 Subject: [PATCH] tweak metrics logging to reduce irrelevant messages (#74, #76) --- controller/metrics.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/controller/metrics.go b/controller/metrics.go index ce36bfbc..df73bbc4 100644 --- a/controller/metrics.go +++ b/controller/metrics.go @@ -141,20 +141,22 @@ func (mh *metricsHandler) run() { } mtr := &model.Metrics{} if err := bson.Unmarshal(mtrBuf.Bytes(), &mtr); err == nil { - out := "metrics = {\n" var pts []*write.Point - for k, v := range mtr.Sessions { - if mh.writeApi != nil { - pt := influxdb2.NewPoint("xfer", - map[string]string{"namespace": mtr.Namespace, "session": k}, - map[string]interface{}{"bytesRead": v.BytesRead, "bytesWritten": v.BytesWritten}, - time.UnixMilli(v.LastUpdate)) - pts = append(pts, pt) + if len(mtr.Sessions) > 0 { + out := "metrics = {\n" + for k, v := range mtr.Sessions { + if mh.writeApi != nil { + pt := influxdb2.NewPoint("xfer", + map[string]string{"namespace": mtr.Namespace, "session": k}, + map[string]interface{}{"bytesRead": v.BytesRead, "bytesWritten": v.BytesWritten}, + time.UnixMilli(v.LastUpdate)) + pts = append(pts, pt) + } + out += fmt.Sprintf("\t[%v.%v]: %v/%v (%v)\n", mtr.Namespace, k, util.BytesToSize(v.BytesRead), util.BytesToSize(v.BytesWritten), time.Since(time.UnixMilli(v.LastUpdate))) } - out += fmt.Sprintf("\t[%v.%v]: %v/%v\n", mtr.Namespace, k, util.BytesToSize(v.BytesRead), util.BytesToSize(v.BytesWritten)) + out += "}" + logrus.Info(out) } - out += "}" - logrus.Info(out) if len(pts) > 0 { if err := mh.writeApi.WritePoint(context.Background(), pts...); err == nil {