mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
swarm: update metrics flags names. remove redundant Timer.
This commit is contained in:
parent
b7516e4540
commit
76dd62cb7f
3 changed files with 30 additions and 28 deletions
|
|
@ -38,7 +38,7 @@ func init() {
|
||||||
//exp.Exp(DefaultRegistry)
|
//exp.Exp(DefaultRegistry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewResettingTimer create a new ResettingTimer, either a real one of a NOP stub depending
|
// NewResettingTimer creates a new ResettingTimer, either a real one of a NOP stub depending
|
||||||
// on the metrics flag.
|
// on the metrics flag.
|
||||||
func NewResettingTimer(name string) metrics.ResettingTimer {
|
func NewResettingTimer(name string) metrics.ResettingTimer {
|
||||||
if !Enabled {
|
if !Enabled {
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ var (
|
||||||
getListCount = metrics.NewCounter("api.http.get.list.count")
|
getListCount = metrics.NewCounter("api.http.get.list.count")
|
||||||
getListFail = metrics.NewCounter("api.http.get.list.fail")
|
getListFail = metrics.NewCounter("api.http.get.list.fail")
|
||||||
requestCount = metrics.NewCounter("http.request.count")
|
requestCount = metrics.NewCounter("http.request.count")
|
||||||
requestTimer = metrics.NewTimer("http.request.time")
|
requestTimer = metrics.NewResettingTimer("http.request.time")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServerConfig is the basic configuration needed for the HTTP server and also
|
// ServerConfig is the basic configuration needed for the HTTP server and also
|
||||||
|
|
@ -644,9 +644,7 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
requestCount.Inc(1)
|
requestCount.Inc(1)
|
||||||
startTime := time.Now()
|
defer requestTimer.UpdateSince(time.Now())
|
||||||
defer requestTimer.UpdateSince(startTime)
|
|
||||||
defer metrics.NewResettingTimer("http.request.time_resetting").UpdateSince(startTime)
|
|
||||||
s.logDebug("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, r.URL.Host, r.URL.Path, r.Referer(), r.Header.Get("Accept"))
|
s.logDebug("HTTP %s request URL: '%s', Host: '%s', Path: '%s', Referer: '%s', Accept: '%s'", r.Method, r.RequestURI, r.URL.Host, r.URL.Path, r.Referer(), r.Header.Get("Accept"))
|
||||||
|
|
||||||
uri, err := api.Parse(strings.TrimLeft(r.URL.Path, "/"))
|
uri, err := api.Parse(strings.TrimLeft(r.URL.Path, "/"))
|
||||||
|
|
|
||||||
|
|
@ -28,29 +28,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
metricsEndpointFlag = cli.StringFlag{
|
metricsInfluxDBEndpointFlag = cli.StringFlag{
|
||||||
Name: "metricsendpoint",
|
Name: "metrics.influxdb.endpoint",
|
||||||
Usage: "metrics backend endpoint",
|
Usage: "Metrics InfluxDB endpoint",
|
||||||
Value: "http://127.0.0.1:8086",
|
Value: "http://127.0.0.1:8086",
|
||||||
}
|
}
|
||||||
metricsDatabaseFlag = cli.StringFlag{
|
metricsInfluxDBDatabaseFlag = cli.StringFlag{
|
||||||
Name: "metricsdatabase",
|
Name: "metrics.influxdb.database",
|
||||||
Usage: "metrics backend database",
|
Usage: "metrics InfluxDB database",
|
||||||
Value: "metrics",
|
Value: "metrics",
|
||||||
}
|
}
|
||||||
metricsUsernameFlag = cli.StringFlag{
|
metricsInfluxDBUsernameFlag = cli.StringFlag{
|
||||||
Name: "metricsusername",
|
Name: "metrics.influxdb.username",
|
||||||
Usage: "metrics backend username",
|
Usage: "metrics InfluxDB username",
|
||||||
Value: "admin",
|
Value: "",
|
||||||
}
|
}
|
||||||
metricsPasswordFlag = cli.StringFlag{
|
metricsInfluxDBPasswordFlag = cli.StringFlag{
|
||||||
Name: "metricspassword",
|
Name: "metrics.influxdb.password",
|
||||||
Usage: "metrics backend password",
|
Usage: "metrics InfluxDB password",
|
||||||
Value: "admin",
|
Value: "",
|
||||||
}
|
}
|
||||||
metricsHostTagFlag = cli.StringFlag{
|
// The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
|
||||||
Name: "metricshosttag",
|
// It is used so that we can group all nodes and average a measurement across all of them, but also so
|
||||||
Usage: "metrics host tag",
|
// that we can select a specific node and inspect its measurements.
|
||||||
|
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
|
||||||
|
metricsInfluxDBHostTagFlag = cli.StringFlag{
|
||||||
|
Name: "metrics.influxdb.host.tag",
|
||||||
|
Usage: "metrics InfluxDB `host` tag attached to all measurements",
|
||||||
Value: "localhost",
|
Value: "localhost",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -58,17 +62,17 @@ var (
|
||||||
// Flags holds all command-line flags required for metrics collection.
|
// Flags holds all command-line flags required for metrics collection.
|
||||||
var Flags = []cli.Flag{
|
var Flags = []cli.Flag{
|
||||||
utils.MetricsEnabledFlag,
|
utils.MetricsEnabledFlag,
|
||||||
metricsEndpointFlag, metricsDatabaseFlag, metricsUsernameFlag, metricsPasswordFlag, metricsHostTagFlag,
|
metricsInfluxDBEndpointFlag, metricsInfluxDBDatabaseFlag, metricsInfluxDBUsernameFlag, metricsInfluxDBPasswordFlag, metricsInfluxDBHostTagFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(ctx *cli.Context) {
|
func Setup(ctx *cli.Context) {
|
||||||
if gethmetrics.Enabled {
|
if gethmetrics.Enabled {
|
||||||
var (
|
var (
|
||||||
endpoint = ctx.GlobalString(metricsEndpointFlag.Name)
|
endpoint = ctx.GlobalString(metricsInfluxDBEndpointFlag.Name)
|
||||||
database = ctx.GlobalString(metricsDatabaseFlag.Name)
|
database = ctx.GlobalString(metricsInfluxDBDatabaseFlag.Name)
|
||||||
username = ctx.GlobalString(metricsUsernameFlag.Name)
|
username = ctx.GlobalString(metricsInfluxDBUsernameFlag.Name)
|
||||||
password = ctx.GlobalString(metricsPasswordFlag.Name)
|
password = ctx.GlobalString(metricsInfluxDBPasswordFlag.Name)
|
||||||
hosttag = ctx.GlobalString(metricsHostTagFlag.Name)
|
hosttag = ctx.GlobalString(metricsInfluxDBHostTagFlag.Name)
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Info("Enabling swarm metrics collection and export")
|
log.Info("Enabling swarm metrics collection and export")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue