mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 01:37:52 +02:00
parent
e9941914d9
commit
8c0261f3ad
@ -28,7 +28,10 @@ type httpListen struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTP(cfg *Config) (*httpListen, error) {
|
func NewHTTP(cfg *Config) (*httpListen, error) {
|
||||||
ma := newMetricsAgent()
|
ma, err := newMetricsAgent(cfg.Identity)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
go ma.run()
|
go ma.run()
|
||||||
|
|
||||||
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity)
|
zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.Identity)
|
||||||
|
@ -3,12 +3,18 @@ package frontend
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openziti-test-kitchen/zrok/util"
|
"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"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metricsAgent struct {
|
type metricsAgent struct {
|
||||||
metrics map[string]sessionMetrics
|
metrics map[string]sessionMetrics
|
||||||
updates chan metricsUpdate
|
updates chan metricsUpdate
|
||||||
|
zCtx ziti.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
type sessionMetrics struct {
|
type sessionMetrics struct {
|
||||||
@ -23,11 +29,21 @@ type metricsUpdate struct {
|
|||||||
bytesWritten int64
|
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{
|
return &metricsAgent{
|
||||||
metrics: make(map[string]sessionMetrics),
|
metrics: make(map[string]sessionMetrics),
|
||||||
updates: make(chan metricsUpdate, 10240),
|
updates: make(chan metricsUpdate, 10240),
|
||||||
}
|
zCtx: ziti.NewContextWithConfig(zCfg),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ma *metricsAgent) run() {
|
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 += fmt.Sprintf("\t[%v]: %s/%s (%s)\n", k, util.BytesToSize(v.bytesRead), util.BytesToSize(v.bytesWritten), age.String())
|
||||||
}
|
}
|
||||||
out += "}\n"
|
out += "}\n"
|
||||||
//fmt.Println(out)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user