mirror of
https://github.com/openziti/zrok.git
synced 2025-05-31 15:16:41 +02:00
parent
095024c179
commit
83c12e30cb
@ -36,15 +36,22 @@ type metricsAgent struct {
|
|||||||
cfg *MetricsConfig
|
cfg *MetricsConfig
|
||||||
influx influxdb2.Client
|
influx influxdb2.Client
|
||||||
writeApi api.WriteAPIBlocking
|
writeApi api.WriteAPIBlocking
|
||||||
|
envCache map[string]*envCacheEntry
|
||||||
zCtx ziti.Context
|
zCtx ziti.Context
|
||||||
zListener edge.Listener
|
zListener edge.Listener
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
joined chan struct{}
|
joined chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type envCacheEntry struct {
|
||||||
|
env string
|
||||||
|
lastAccess time.Time
|
||||||
|
}
|
||||||
|
|
||||||
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
|
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
|
||||||
ma := &metricsAgent{
|
ma := &metricsAgent{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
envCache: make(map[string]*envCacheEntry),
|
||||||
shutdown: make(chan struct{}),
|
shutdown: make(chan struct{}),
|
||||||
joined: make(chan struct{}),
|
joined: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
@ -80,28 +80,30 @@ func (ma *metricsAgent) pushUpdate(mu metricsUpdate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ma *metricsAgent) sendMetrics() error {
|
func (ma *metricsAgent) sendMetrics() error {
|
||||||
m := &model.Metrics{
|
if len(ma.accum) > 0 {
|
||||||
Namespace: ma.cfg.Identity,
|
m := &model.Metrics{
|
||||||
Sessions: ma.accum,
|
Namespace: ma.cfg.Identity,
|
||||||
|
Sessions: ma.accum,
|
||||||
|
}
|
||||||
|
metricsJson, err := bson.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error marshaling metrics")
|
||||||
|
}
|
||||||
|
conn, err := ma.zCtx.Dial(ma.cfg.Metrics.Service)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error connecting to metrics service")
|
||||||
|
}
|
||||||
|
n, err := conn.Write(metricsJson)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error sending metrics")
|
||||||
|
}
|
||||||
|
defer func() { _ = conn.Close() }()
|
||||||
|
if n != len(metricsJson) {
|
||||||
|
return errors.Wrap(err, "short metrics write")
|
||||||
|
}
|
||||||
|
logrus.Infof("sent %d bytes of metrics data", n)
|
||||||
|
ma.accum = make(map[string]model.SessionMetrics)
|
||||||
|
ma.lastSend = time.Now()
|
||||||
}
|
}
|
||||||
metricsJson, err := bson.Marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "error marshaling metrics")
|
|
||||||
}
|
|
||||||
conn, err := ma.zCtx.Dial(ma.cfg.Metrics.Service)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "error connecting to metrics service")
|
|
||||||
}
|
|
||||||
n, err := conn.Write(metricsJson)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "error sending metrics")
|
|
||||||
}
|
|
||||||
defer func() { _ = conn.Close() }()
|
|
||||||
if n != len(metricsJson) {
|
|
||||||
return errors.Wrap(err, "short metrics write")
|
|
||||||
}
|
|
||||||
logrus.Infof("sent %d bytes of metrics data", n)
|
|
||||||
ma.accum = make(map[string]model.SessionMetrics)
|
|
||||||
ma.lastSend = time.Now()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user