mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
parent
8c0261f3ad
commit
f578db3406
@ -1,8 +1,7 @@
|
|||||||
package frontend
|
package frontend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"encoding/json"
|
||||||
"github.com/openziti-test-kitchen/zrok/util"
|
|
||||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||||
"github.com/openziti/sdk-golang/ziti"
|
"github.com/openziti/sdk-golang/ziti"
|
||||||
"github.com/openziti/sdk-golang/ziti/config"
|
"github.com/openziti/sdk-golang/ziti/config"
|
||||||
@ -18,9 +17,9 @@ type metricsAgent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sessionMetrics struct {
|
type sessionMetrics struct {
|
||||||
bytesRead int64
|
BytesRead int64
|
||||||
bytesWritten int64
|
BytesWritten int64
|
||||||
lastUpdate time.Time
|
LastUpdate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type metricsUpdate struct {
|
type metricsUpdate struct {
|
||||||
@ -51,28 +50,25 @@ func (ma *metricsAgent) run() {
|
|||||||
select {
|
select {
|
||||||
case update := <-ma.updates:
|
case update := <-ma.updates:
|
||||||
if sm, found := ma.metrics[update.id]; found {
|
if sm, found := ma.metrics[update.id]; found {
|
||||||
sm.bytesRead += update.bytesRead
|
sm.BytesRead += update.bytesRead
|
||||||
sm.bytesWritten += update.bytesWritten
|
sm.BytesWritten += update.bytesWritten
|
||||||
sm.lastUpdate = time.Now()
|
sm.LastUpdate = time.Now()
|
||||||
ma.metrics[update.id] = sm
|
ma.metrics[update.id] = sm
|
||||||
} else {
|
} else {
|
||||||
sm := sessionMetrics{
|
sm := sessionMetrics{
|
||||||
bytesRead: update.bytesRead,
|
BytesRead: update.bytesRead,
|
||||||
bytesWritten: update.bytesWritten,
|
BytesWritten: update.bytesWritten,
|
||||||
lastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
}
|
}
|
||||||
ma.metrics[update.id] = sm
|
ma.metrics[update.id] = sm
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
now := time.Now()
|
if metricsJson, err := json.MarshalIndent(ma.metrics, "", " "); err == nil {
|
||||||
out := "metrics = {\n"
|
logrus.Info(string(metricsJson))
|
||||||
for k, v := range ma.metrics {
|
} else {
|
||||||
age := now.Sub(v.lastUpdate)
|
logrus.Errorf("error marshaling metrics: %v", err)
|
||||||
out += fmt.Sprintf("\t[%v]: %s/%s (%s)\n", k, util.BytesToSize(v.bytesRead), util.BytesToSize(v.bytesWritten), age.String())
|
|
||||||
}
|
}
|
||||||
out += "}\n"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user