Merge branch 'v0.4_metrics' into v0.4.0

This commit is contained in:
Michael Quigley 2023-03-09 14:29:54 -05:00
commit cbbd62c3fc
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -2,8 +2,11 @@ package metrics
import ( import (
"context" "context"
"fmt"
influxdb2 "github.com/influxdata/influxdb-client-go/v2" influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api" "github.com/influxdata/influxdb-client-go/v2/api"
"github.com/influxdata/influxdb-client-go/v2/api/write"
"github.com/openziti/zrok/util"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -19,14 +22,30 @@ func openInfluxDb(cfg *InfluxConfig) *influxDb {
} }
func (i *influxDb) Write(u *Usage) error { func (i *influxDb) Write(u *Usage) error {
pt := influxdb2.NewPoint("xfer", out := fmt.Sprintf("share: %v, circuit: %v", u.ShareToken, u.ZitiCircuitId)
map[string]string{"namespace": "backend", "share": u.ShareToken}, var pts []*write.Point
map[string]interface{}{"bytesRead": u.BackendRx, "bytesWritten": u.BackendTx}, if u.BackendTx > 0 || u.BackendRx > 0 {
u.IntervalStart) pt := influxdb2.NewPoint("xfer",
if err := i.writeApi.WritePoint(context.Background(), pt); err == nil { map[string]string{"namespace": "backend", "share": u.ShareToken},
logrus.Infof("share: %v, circuit: %v, rx: %d, tx: %d", u.ShareToken, u.ZitiCircuitId, u.BackendRx, u.BackendTx) map[string]interface{}{"bytesRead": u.BackendRx, "bytesWritten": u.BackendTx},
} else { u.IntervalStart)
return err pts = append(pts, pt)
out += fmt.Sprintf(" backend {rx: %v, tx: %v}", util.BytesToSize(u.BackendRx), util.BytesToSize(u.BackendTx))
}
if u.FrontendTx > 0 || u.FrontendRx > 0 {
pt := influxdb2.NewPoint("xfer",
map[string]string{"namespace": "frontend", "share": u.ShareToken},
map[string]interface{}{"bytesRead": u.FrontendRx, "bytesWritten": u.FrontendTx},
u.IntervalStart)
pts = append(pts, pt)
out += fmt.Sprintf(" frontend {rx: %v, tx: %v}", util.BytesToSize(u.FrontendRx), util.BytesToSize(u.FrontendTx))
}
if len(pts) > 0 {
if err := i.writeApi.WritePoint(context.Background(), pts...); err == nil {
logrus.Info(out)
} else {
return err
}
} }
return nil return nil
} }