@ -51,6 +51,7 @@ import (
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"
"github.com/ethereum/go-ethereum/metrics/influxdb"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node"
@ -689,6 +690,21 @@ var (
Name : "metrics.expensive" ,
Usage : "Enable expensive metrics collection and reporting" ,
}
// MetricsHTTPFlag defines the endpoint for a stand-alone metrics HTTP endpoint.
// Since the pprof service enables sensitive/vulnerable behavior, this allows a user
// to enable a public-OK metrics endpoint without having to worry about ALSO exposing
// other profiling behavior or information.
MetricsHTTPFlag = cli . StringFlag {
Name : "metrics.addr" ,
Usage : "Enable stand-alone metrics HTTP server listening interface" ,
Value : "127.0.0.1" ,
}
MetricsPortFlag = cli . IntFlag {
Name : "metrics.port" ,
Usage : "Metrics HTTP server listening port" ,
Value : 6060 ,
}
MetricsEnableInfluxDBFlag = cli . BoolFlag {
Name : "metrics.influxdb" ,
Usage : "Enable metrics export/push to an external InfluxDB database" ,
@ -1734,6 +1750,7 @@ func RegisterGraphQLService(stack *node.Node, endpoint string, cors, vhosts []st
func SetupMetrics ( ctx * cli . Context ) {
if metrics . Enabled {
log . Info ( "Enabling metrics collection" )
var (
enableExport = ctx . GlobalBool ( MetricsEnableInfluxDBFlag . Name )
endpoint = ctx . GlobalString ( MetricsInfluxDBEndpointFlag . Name )
@ -1749,6 +1766,12 @@ func SetupMetrics(ctx *cli.Context) {
go influxdb . InfluxDBWithTags ( metrics . DefaultRegistry , 10 * time . Second , endpoint , database , username , password , "geth." , tagsMap )
}
if ctx . GlobalIsSet ( MetricsHTTPFlag . Name ) {
address := fmt . Sprintf ( "%s:%d" , ctx . GlobalString ( MetricsHTTPFlag . Name ) , ctx . GlobalInt ( MetricsPortFlag . Name ) )
log . Info ( "Enabling stand-alone metrics HTTP endpoint" , "address" , address )
exp . Setup ( address )
}
}
}