2023-03-03 19:31:57 +01:00
|
|
|
package metrics
|
|
|
|
|
2023-03-03 22:45:18 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/openziti/zrok/util"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Usage struct {
|
|
|
|
ProcessedStamp time.Time
|
|
|
|
IntervalStart time.Time
|
|
|
|
ZitiServiceId string
|
|
|
|
ZitiCircuitId string
|
2023-03-07 22:29:39 +01:00
|
|
|
ShareToken string
|
2023-03-13 21:20:56 +01:00
|
|
|
EnvironmentId int64
|
|
|
|
AccountId int64
|
2023-03-03 22:45:18 +01:00
|
|
|
FrontendTx int64
|
|
|
|
FrontendRx int64
|
|
|
|
BackendTx int64
|
|
|
|
BackendRx int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u Usage) String() string {
|
|
|
|
out := "Usage {"
|
|
|
|
out += fmt.Sprintf("processed '%v'", u.ProcessedStamp)
|
|
|
|
out += ", " + fmt.Sprintf("interval '%v'", u.IntervalStart)
|
|
|
|
out += ", " + fmt.Sprintf("service '%v'", u.ZitiServiceId)
|
|
|
|
out += ", " + fmt.Sprintf("circuit '%v'", u.ZitiCircuitId)
|
2023-03-07 22:29:39 +01:00
|
|
|
out += ", " + fmt.Sprintf("share '%v'", u.ShareToken)
|
2023-03-13 21:20:56 +01:00
|
|
|
out += ", " + fmt.Sprintf("environment '%d'", u.EnvironmentId)
|
|
|
|
out += ", " + fmt.Sprintf("account '%v'", u.AccountId)
|
2023-03-03 22:45:18 +01:00
|
|
|
out += ", " + fmt.Sprintf("fe {rx %v, tx %v}", util.BytesToSize(u.FrontendRx), util.BytesToSize(u.FrontendTx))
|
|
|
|
out += ", " + fmt.Sprintf("be {rx %v, tx %v}", util.BytesToSize(u.BackendRx), util.BytesToSize(u.BackendTx))
|
|
|
|
out += "}"
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:14:06 +01:00
|
|
|
type UsageSink interface {
|
|
|
|
Handle(u *Usage) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ZitiEventJson string
|
|
|
|
|
|
|
|
type ZitiEventJsonSource interface {
|
|
|
|
Start(chan ZitiEventJson) (join chan struct{}, err error)
|
2023-03-03 19:31:57 +01:00
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:14:06 +01:00
|
|
|
type ZitiEventJsonSink interface {
|
|
|
|
Handle(event ZitiEventJson) error
|
2023-03-03 19:31:57 +01:00
|
|
|
}
|