mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
cmd/swarm/swarm-smoke: fix metrics collection
This commit is contained in:
parent
5f932263de
commit
f9c231cf72
2 changed files with 27 additions and 21 deletions
|
|
@ -17,8 +17,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -32,6 +32,10 @@ import (
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
collectionInterval = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
endpoints []string
|
endpoints []string
|
||||||
includeLocalhost bool
|
includeLocalhost bool
|
||||||
|
|
@ -45,14 +49,9 @@ var (
|
||||||
timeout int
|
timeout int
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
feedUploadAndSyncCount = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.count", nil)
|
feedUploadAndSyncCount = gethmetrics.NewRegisteredCounter("feed-and-sync", nil)
|
||||||
feedUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.fail.count", nil)
|
feedUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("feed-and-sync.fail", nil)
|
||||||
feedUploadAndSyncRunTime = gethmetrics.NewRegisteredCounter("swarm-smoke.feed-and-sync.time", nil)
|
feedUploadAndSyncTimeout = gethmetrics.NewRegisteredCounter("feed-and-sync.timeout", 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)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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.FlagsByName(app.Flags))
|
||||||
sort.Sort(cli.CommandsByName(app.Commands))
|
sort.Sort(cli.CommandsByName(app.Commands))
|
||||||
app.Before = func(ctx *cli.Context) error {
|
app.Before = func(ctx *cli.Context) error {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
||||||
setupMetrics(ctx)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,11 +168,9 @@ func setupMetrics(ctx *cli.Context) {
|
||||||
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
|
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, collectionInterval, endpoint, database, username, password, "swarm-smoke.", map[string]string{
|
||||||
go gethmetrics.CollectProcessMetrics(2 * time.Second)
|
|
||||||
|
|
||||||
go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "swarm.", map[string]string{
|
|
||||||
"host": hosttag,
|
"host": hosttag,
|
||||||
|
"filesize": fmt.Sprintf("%v", filesize),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
|
metrics "github.com/rcrowley/go-metrics"
|
||||||
|
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
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 {
|
func cliUploadAndSync(c *cli.Context) error {
|
||||||
smokeUploadAndSyncCount.Inc(1)
|
|
||||||
log.PrintOrigins(true)
|
log.PrintOrigins(true)
|
||||||
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(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)
|
errc := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
errc <- uploadAndSync(c)
|
errc <- uploadAndSync(c)
|
||||||
|
|
@ -67,19 +71,21 @@ func cliUploadAndSync(c *cli.Context) error {
|
||||||
select {
|
select {
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
smokeUploadAndSyncFailCount.Inc(1)
|
metrics.GetOrRegisterCounter("upload-and-sync.fail", nil).Inc(1)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
case <-time.After(time.Duration(timeout) * time.Second):
|
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)
|
return fmt.Errorf("timeout after %v sec", timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadAndSync(c *cli.Context) error {
|
func uploadAndSync(c *cli.Context) error {
|
||||||
defer func(now time.Time) {
|
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())
|
}(time.Now())
|
||||||
|
|
||||||
generateEndpoints(scheme, cluster, appName, from, to)
|
generateEndpoints(scheme, cluster, appName, from, to)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue