cmd/swarm/swarm-smoke: fix metrics collection

This commit is contained in:
Anton Evangelatov 2018-12-04 13:58:36 +01:00
parent 5f932263de
commit f9c231cf72
2 changed files with 27 additions and 21 deletions

View file

@ -17,8 +17,8 @@
package main
import (
"fmt"
"os"
"runtime"
"sort"
"time"
@ -32,6 +32,10 @@ import (
cli "gopkg.in/urfave/cli.v1"
)
const (
collectionInterval = 5 * time.Second
)
var (
endpoints []string
includeLocalhost bool
@ -45,14 +49,9 @@ var (
timeout int
)
var (
feedUploadAndSyncCount = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.count", nil)
feedUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.fail.count", nil)
feedUploadAndSyncRunTime = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.time", nil)
feedUploadAndSyncTimeout = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.timeout", nil)
smokeUploadAndSyncCount = gethmetrics.NewRegisteredCounter("swarm-smoke.upload-and-sync.count", nil)
smokeUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("swarm-smoke.upload-and-sync.fail.count", nil)
smokeUploadAndSyncRunTime = gethmetrics.NewRegisteredCounter("swarm-smoke.upload-and-sync.time", nil)
smokeUploadAndSyncTimeout = gethmetrics.NewRegisteredCounter("swarm-smoke.upload-and-sync.timeout", nil)
feedUploadAndSyncCount = gethmetrics.NewRegisteredCounter("feed-and-sync", nil)
feedUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("feed-and-sync.fail", nil)
feedUploadAndSyncTimeout = gethmetrics.NewRegisteredCounter("feed-and-sync.timeout", nil)
)
func main() {
@ -141,11 +140,14 @@ func main() {
},
}
// wait for metrics reporter to push latest measurements
defer func() {
time.Sleep(collectionInterval + 1*time.Second)
}()
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
app.Before = func(ctx *cli.Context) error {
runtime.GOMAXPROCS(runtime.NumCPU())
setupMetrics(ctx)
return nil
}
@ -166,11 +168,9 @@ func setupMetrics(ctx *cli.Context) {
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
)
// Start system runtime metrics collection
go gethmetrics.CollectProcessMetrics(2 * time.Second)
go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "swarm.", map[string]string{
"host": hosttag,
go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, collectionInterval, endpoint, database, username, password, "swarm-smoke.", map[string]string{
"host": hosttag,
"filesize": fmt.Sprintf("%v", filesize),
})
}
}

View file

@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/pborman/uuid"
metrics "github.com/rcrowley/go-metrics"
cli "gopkg.in/urfave/cli.v1"
)
@ -55,10 +56,13 @@ func generateEndpoints(scheme string, cluster string, app string, from int, to i
}
func cliUploadAndSync(c *cli.Context) error {
smokeUploadAndSyncCount.Inc(1)
log.PrintOrigins(true)
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))
setupMetrics(c)
metrics.GetOrRegisterCounter("upload-and-sync", nil).Inc(1)
errc := make(chan error)
go func() {
errc <- uploadAndSync(c)
@ -67,19 +71,21 @@ func cliUploadAndSync(c *cli.Context) error {
select {
case err := <-errc:
if err != nil {
smokeUploadAndSyncFailCount.Inc(1)
metrics.GetOrRegisterCounter("upload-and-sync.fail", nil).Inc(1)
}
return err
case <-time.After(time.Duration(timeout) * time.Second):
smokeUploadAndSyncTimeout.Inc(1)
metrics.GetOrRegisterCounter("upload-and-sync.timeout", nil).Inc(1)
return fmt.Errorf("timeout after %v sec", timeout)
}
}
func uploadAndSync(c *cli.Context) error {
defer func(now time.Time) {
log.Info("total time", "time", time.Since(now), "kb", filesize)
totalTime := time.Since(now)
log.Info("total time", "time", totalTime, "kb", filesize)
metrics.GetOrRegisterCounter("upload-and-sync.time", nil).Inc(int64(totalTime))
}(time.Now())
generateEndpoints(scheme, cluster, appName, from, to)