mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 17:27:54 +02:00
naming (#271)
This commit is contained in:
parent
40ae2da2c9
commit
7360598df5
@ -40,15 +40,15 @@ func (a *Agent) Stop() {
|
|||||||
|
|
||||||
func (a *Agent) Handle(u *metrics.Usage) error {
|
func (a *Agent) Handle(u *metrics.Usage) error {
|
||||||
logrus.Infof("handling: %v", u)
|
logrus.Infof("handling: %v", u)
|
||||||
acctRx, acctTx, err := a.ifx.totalForAccount(u.AccountId, 24*time.Hour)
|
acctRx, acctTx, err := a.ifx.totalRxTxForAccount(u.AccountId, 24*time.Hour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
envRx, envTx, err := a.ifx.totalForEnvironment(u.EnvironmentId, 24*time.Hour)
|
envRx, envTx, err := a.ifx.totalRxTxForEnvironment(u.EnvironmentId, 24*time.Hour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
shareRx, shareTx, err := a.ifx.totalForShare(u.ShareToken, 24*time.Hour)
|
shareRx, shareTx, err := a.ifx.totalRxTxForShare(u.ShareToken, 24*time.Hour)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func newInfluxReader(cfg *metrics.InfluxConfig) *influxReader {
|
|||||||
return &influxReader{cfg, idb, queryApi}
|
return &influxReader{cfg, idb, queryApi}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *influxReader) totalForAccount(acctId int64, duration time.Duration) (int64, int64, error) {
|
func (r *influxReader) totalRxTxForAccount(acctId int64, duration time.Duration) (int64, int64, error) {
|
||||||
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
||||||
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
||||||
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
||||||
@ -33,10 +33,10 @@ func (r *influxReader) totalForAccount(acctId int64, duration time.Duration) (in
|
|||||||
fmt.Sprintf("|> filter(fn: (r) => r[\"acctId\"] == \"%d\")\n", acctId) +
|
fmt.Sprintf("|> filter(fn: (r) => r[\"acctId\"] == \"%d\")\n", acctId) +
|
||||||
"|> drop(columns: [\"share\", \"envId\"])\n" +
|
"|> drop(columns: [\"share\", \"envId\"])\n" +
|
||||||
"|> sum()"
|
"|> sum()"
|
||||||
return r.runQueryForSum(query)
|
return r.runQueryForRxTx(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *influxReader) totalForEnvironment(envId int64, duration time.Duration) (int64, int64, error) {
|
func (r *influxReader) totalRxTxForEnvironment(envId int64, duration time.Duration) (int64, int64, error) {
|
||||||
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
||||||
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
||||||
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
||||||
@ -45,10 +45,10 @@ func (r *influxReader) totalForEnvironment(envId int64, duration time.Duration)
|
|||||||
fmt.Sprintf("|> filter(fn: (r) => r[\"envId\"] == \"%d\")\n", envId) +
|
fmt.Sprintf("|> filter(fn: (r) => r[\"envId\"] == \"%d\")\n", envId) +
|
||||||
"|> drop(columns: [\"share\", \"acctId\"])\n" +
|
"|> drop(columns: [\"share\", \"acctId\"])\n" +
|
||||||
"|> sum()"
|
"|> sum()"
|
||||||
return r.runQueryForSum(query)
|
return r.runQueryForRxTx(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *influxReader) totalForShare(shrToken string, duration time.Duration) (int64, int64, error) {
|
func (r *influxReader) totalRxTxForShare(shrToken string, duration time.Duration) (int64, int64, error) {
|
||||||
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
query := fmt.Sprintf("from(bucket: \"%v\")\n", r.cfg.Bucket) +
|
||||||
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
fmt.Sprintf("|> range(start: -%v)\n", duration) +
|
||||||
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")\n" +
|
||||||
@ -56,10 +56,10 @@ func (r *influxReader) totalForShare(shrToken string, duration time.Duration) (i
|
|||||||
"|> filter(fn: (r) => r[\"namespace\"] == \"backend\")\n" +
|
"|> filter(fn: (r) => r[\"namespace\"] == \"backend\")\n" +
|
||||||
fmt.Sprintf("|> filter(fn: (r) => r[\"share\"] == \"%v\")\n", shrToken) +
|
fmt.Sprintf("|> filter(fn: (r) => r[\"share\"] == \"%v\")\n", shrToken) +
|
||||||
"|> sum()"
|
"|> sum()"
|
||||||
return r.runQueryForSum(query)
|
return r.runQueryForRxTx(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *influxReader) runQueryForSum(query string) (rx int64, tx int64, err error) {
|
func (r *influxReader) runQueryForRxTx(query string) (rx int64, tx int64, err error) {
|
||||||
result, err := r.queryApi.Query(context.Background(), query)
|
result, err := r.queryApi.Query(context.Background(), query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, -1, err
|
return -1, -1, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user