mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
parent
e9941914d9
commit
8c0261f3ad
@ -28,7 +28,10 @@ type httpListen struct {
|
||||
}
|
||||
|
||||
func NewHTTP(cfg *Config) (*httpListen, error) {
|
||||
ma := newMetricsAgent()
|
||||
ma, err := newMetricsAgent(cfg.Identity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
go ma.run()
|
||||
|
||||
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity)
|
||||
|
@ -3,12 +3,18 @@ package frontend
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/util"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
"github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
type metricsAgent struct {
|
||||
metrics map[string]sessionMetrics
|
||||
updates chan metricsUpdate
|
||||
zCtx ziti.Context
|
||||
}
|
||||
|
||||
type sessionMetrics struct {
|
||||
@ -23,11 +29,21 @@ type metricsUpdate struct {
|
||||
bytesWritten int64
|
||||
}
|
||||
|
||||
func newMetricsAgent() *metricsAgent {
|
||||
func newMetricsAgent(identityName string) (*metricsAgent, error) {
|
||||
zif, err := zrokdir.ZitiIdentityFile(identityName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error getting '%v' identity file", identityName)
|
||||
}
|
||||
zCfg, err := config.NewFromFile(zif)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error loading '%v' identity", identityName)
|
||||
}
|
||||
logrus.Infof("loaded '%v' identity", identityName)
|
||||
return &metricsAgent{
|
||||
metrics: make(map[string]sessionMetrics),
|
||||
updates: make(chan metricsUpdate, 10240),
|
||||
}
|
||||
zCtx: ziti.NewContextWithConfig(zCfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ma *metricsAgent) run() {
|
||||
@ -56,7 +72,7 @@ func (ma *metricsAgent) run() {
|
||||
out += fmt.Sprintf("\t[%v]: %s/%s (%s)\n", k, util.BytesToSize(v.bytesRead), util.BytesToSize(v.bytesWritten), age.String())
|
||||
}
|
||||
out += "}\n"
|
||||
//fmt.Println(out)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user