diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index 21f41af65c..f1e50372ec 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -20,7 +20,6 @@ import ( "fmt" "os" "sort" - "time" "github.com/ethereum/go-ethereum/cmd/utils" gethmetrics "github.com/ethereum/go-ethereum/metrics" @@ -36,10 +35,6 @@ var ( gitCommit string // Git SHA1 commit hash of the release (set via linker flags) ) -const ( - collectionInterval = 5 * time.Second -) - var ( endpoints []string includeLocalhost bool @@ -149,22 +144,20 @@ func main() { app.Before = func(ctx *cli.Context) error { return nil } + app.After = func(ctx *cli.Context) error { + emitMetrics(ctx) + return nil + } err := app.Run(os.Args) if err != nil { log.Error(err.Error()) - // wait for metrics reporter to push latest measurements - time.Sleep(collectionInterval + 1*time.Second) - os.Exit(1) } - - // wait for metrics reporter to push latest measurements - time.Sleep(collectionInterval + 1*time.Second) } -func setupMetrics(ctx *cli.Context) { +func emitMetrics(ctx *cli.Context) { if gethmetrics.Enabled { var ( endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) @@ -174,7 +167,7 @@ func setupMetrics(ctx *cli.Context) { hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name) ) - go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, collectionInterval, endpoint, database, username, password, "swarm-smoke.", map[string]string{ + influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", map[string]string{ "host": hosttag, "version": gitCommit, "filesize": fmt.Sprintf("%v", filesize), diff --git a/cmd/swarm/swarm-smoke/upload_and_sync.go b/cmd/swarm/swarm-smoke/upload_and_sync.go index f41d80d947..e5699dd50a 100644 --- a/cmd/swarm/swarm-smoke/upload_and_sync.go +++ b/cmd/swarm/swarm-smoke/upload_and_sync.go @@ -59,8 +59,6 @@ func cliUploadAndSync(c *cli.Context) error { 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) diff --git a/metrics/influxdb/influxdb.go b/metrics/influxdb/influxdb.go index 31a5c21b5f..5f99bb0146 100644 --- a/metrics/influxdb/influxdb.go +++ b/metrics/influxdb/influxdb.go @@ -58,6 +58,34 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna rep.run() } +// InfluxDBWithTagsOnce runs once an InfluxDB reporter and post the given metrics.Registry with the specified tags +func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, namespace string, tags map[string]string) { + u, err := uurl.Parse(url) + if err != nil { + log.Warn("Unable to parse InfluxDB", "url", url, "err", err) + return + } + + rep := &reporter{ + reg: r, + url: *u, + database: database, + username: username, + password: password, + namespace: namespace, + tags: tags, + cache: make(map[string]int64), + } + if err := rep.makeClient(); err != nil { + log.Warn("Unable to make InfluxDB client", "err", err) + return + } + + if err := rep.send(); err != nil { + log.Warn("Unable to send to InfluxDB", "err", err) + } +} + func (r *reporter) makeClient() (err error) { r.client, err = client.NewClient(client.Config{ URL: r.url,