local now; namespace (#74, #76)

This commit is contained in:
Michael Quigley 2022-10-17 13:45:52 -04:00
parent 339f07510d
commit 69c44bdd51
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 6 additions and 5 deletions

View File

@ -131,7 +131,7 @@ func (mh *metricsHandler) run() {
if err := bson.Unmarshal(mtrBuf.Bytes(), &mtr); err == nil { if err := bson.Unmarshal(mtrBuf.Bytes(), &mtr); err == nil {
out := "metrics = {\n" out := "metrics = {\n"
for k, v := range mtr.Sessions { for k, v := range mtr.Sessions {
out += fmt.Sprintf("\t[%v]: %v/%v (%v)\n", k, util.BytesToSize(v.BytesRead), util.BytesToSize(v.BytesWritten), time.Duration(mtr.Now-v.LastUpdate)*time.Millisecond) out += fmt.Sprintf("\t[%v.%v]: %v/%v (%v)\n", mtr.Namespace, k, util.BytesToSize(v.BytesRead), util.BytesToSize(v.BytesWritten), time.Duration(mtr.LocalNow-v.LastUpdate)*time.Millisecond)
} }
out += "}" out += "}"
logrus.Info(out) logrus.Info(out)

View File

@ -36,7 +36,7 @@ func newMetricsAgent(identityName, metricsServiceName string) (*metricsAgent, er
logrus.Infof("loaded '%v' identity", identityName) logrus.Infof("loaded '%v' identity", identityName)
return &metricsAgent{ return &metricsAgent{
metricsServiceName: metricsServiceName, metricsServiceName: metricsServiceName,
metrics: &model.Metrics{}, metrics: &model.Metrics{Namespace: identityName},
updates: make(chan metricsUpdate, 10240), updates: make(chan metricsUpdate, 10240),
zCtx: ziti.NewContextWithConfig(zCfg), zCtx: ziti.NewContextWithConfig(zCfg),
}, nil }, nil
@ -61,7 +61,7 @@ func (ma *metricsAgent) run() {
} }
func (ma *metricsAgent) sendMetrics() error { func (ma *metricsAgent) sendMetrics() error {
ma.metrics.Now = time.Now().UnixMilli() ma.metrics.LocalNow = time.Now().UnixMilli()
metricsJson, err := bson.Marshal(ma.metrics) metricsJson, err := bson.Marshal(ma.metrics)
if err != nil { if err != nil {
return errors.Wrap(err, "error marshaling metrics") return errors.Wrap(err, "error marshaling metrics")

View File

@ -1,8 +1,9 @@
package model package model
type Metrics struct { type Metrics struct {
Now int64 `json:"now"` LocalNow int64
Sessions map[string]SessionMetrics Namespace string
Sessions map[string]SessionMetrics
} }
func (m *Metrics) PushSession(svcName string, sm SessionMetrics) { func (m *Metrics) PushSession(svcName string, sm SessionMetrics) {