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 {
out := "metrics = {\n"
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 += "}"
logrus.Info(out)

View File

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

View File

@ -1,7 +1,8 @@
package model
type Metrics struct {
Now int64 `json:"now"`
LocalNow int64
Namespace string
Sessions map[string]SessionMetrics
}