mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
emit metrics only once
This commit is contained in:
parent
d6ecdfeeba
commit
99a1c3095f
3 changed files with 34 additions and 15 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
gethmetrics "github.com/ethereum/go-ethereum/metrics"
|
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)
|
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
collectionInterval = 5 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
endpoints []string
|
endpoints []string
|
||||||
includeLocalhost bool
|
includeLocalhost bool
|
||||||
|
|
@ -149,22 +144,20 @@ func main() {
|
||||||
app.Before = func(ctx *cli.Context) error {
|
app.Before = func(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
app.After = func(ctx *cli.Context) error {
|
||||||
|
emitMetrics(ctx)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
|
||||||
// wait for metrics reporter to push latest measurements
|
|
||||||
time.Sleep(collectionInterval + 1*time.Second)
|
|
||||||
|
|
||||||
os.Exit(1)
|
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 {
|
if gethmetrics.Enabled {
|
||||||
var (
|
var (
|
||||||
endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name)
|
endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name)
|
||||||
|
|
@ -174,7 +167,7 @@ func setupMetrics(ctx *cli.Context) {
|
||||||
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
|
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,
|
"host": hosttag,
|
||||||
"version": gitCommit,
|
"version": gitCommit,
|
||||||
"filesize": fmt.Sprintf("%v", filesize),
|
"filesize": fmt.Sprintf("%v", filesize),
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,6 @@ func cliUploadAndSync(c *cli.Context) error {
|
||||||
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)
|
metrics.GetOrRegisterCounter("upload-and-sync", nil).Inc(1)
|
||||||
|
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,34 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna
|
||||||
rep.run()
|
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) {
|
func (r *reporter) makeClient() (err error) {
|
||||||
r.client, err = client.NewClient(client.Config{
|
r.client, err = client.NewClient(client.Config{
|
||||||
URL: r.url,
|
URL: r.url,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue