mirror of
https://github.com/openziti/zrok.git
synced 2024-11-28 19:14:07 +01:00
rudimentary zrokloop metrics (#40)
This commit is contained in:
parent
00deaf3389
commit
ca9ff75f6b
@ -10,6 +10,7 @@ import (
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"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"
|
||||
@ -65,6 +66,17 @@ func (r *run) run(_ *cobra.Command, _ []string) {
|
||||
for _, l := range loopers {
|
||||
<-l.done
|
||||
}
|
||||
totalMismatches := 0
|
||||
totalXfer := int64(0)
|
||||
for _, l := range loopers {
|
||||
deltaSeconds := l.stopTime.Sub(l.startTime).Seconds()
|
||||
xfer := int64(float64(l.bytes) / deltaSeconds)
|
||||
totalXfer += xfer
|
||||
xferSec := util.BytesToSize(xfer)
|
||||
logrus.Infof("looper #%d: %d mismatches, %s/sec", l.id, l.mismatches, xferSec)
|
||||
}
|
||||
totalXferSec := util.BytesToSize(totalXfer)
|
||||
logrus.Infof("total: %d mismatches, %s/sec", totalMismatches, totalXferSec)
|
||||
}
|
||||
|
||||
type looper struct {
|
||||
@ -78,6 +90,10 @@ type looper struct {
|
||||
service string
|
||||
proxyEndpoint string
|
||||
auth runtime.ClientAuthInfoWriter
|
||||
mismatches int
|
||||
bytes int64
|
||||
startTime time.Time
|
||||
stopTime time.Time
|
||||
}
|
||||
|
||||
func newLooper(id int, r *run) *looper {
|
||||
@ -162,6 +178,9 @@ func (l *looper) dwell() {
|
||||
}
|
||||
|
||||
func (l *looper) iterate() {
|
||||
l.startTime = time.Now()
|
||||
defer func() { l.stopTime = time.Now() }()
|
||||
|
||||
for i := 0; i < l.r.iterations; i++ {
|
||||
if i > 0 && i%l.r.statusEvery == 0 {
|
||||
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
||||
@ -181,7 +200,9 @@ func (l *looper) iterate() {
|
||||
inbase64 := inpayload.String()
|
||||
if inbase64 != outbase64 {
|
||||
logrus.Errorf("looper #%d payload mismatch!", l.id)
|
||||
l.mismatches++
|
||||
} else {
|
||||
l.bytes += int64(len(outbase64))
|
||||
logrus.Debugf("looper #%d payload match", l.id)
|
||||
}
|
||||
} else {
|
||||
|
22
util/size.go
Normal file
22
util/size.go
Normal file
@ -0,0 +1,22 @@
|
||||
package util
|
||||
|
||||
import "fmt"
|
||||
|
||||
func BytesToSize(sz int64) string {
|
||||
absSz := sz
|
||||
if absSz < 0 {
|
||||
absSz *= -1
|
||||
}
|
||||
|
||||
const unit = 1000
|
||||
if absSz < unit {
|
||||
return fmt.Sprintf("%d B", sz)
|
||||
}
|
||||
div, exp := int64(unit), 0
|
||||
for n := absSz / unit; n >= unit; n /= unit {
|
||||
div *= unit
|
||||
exp++
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f %cB", float64(sz)/float64(div), "kMGTPE"[exp])
|
||||
}
|
Loading…
Reference in New Issue
Block a user