@@ -27,6 +27,7 @@ import (
2727 "runtime"
2828 "strconv"
2929 "strings"
30+ "time"
3031
3132 "github.com/ethereum/go-ethereum/accounts"
3233 "github.com/ethereum/go-ethereum/accounts/keystore"
@@ -48,6 +49,7 @@ import (
4849 "github.com/ethereum/go-ethereum/les"
4950 "github.com/ethereum/go-ethereum/log"
5051 "github.com/ethereum/go-ethereum/metrics"
52+ "github.com/ethereum/go-ethereum/metrics/influxdb"
5153 "github.com/ethereum/go-ethereum/node"
5254 "github.com/ethereum/go-ethereum/p2p"
5355 "github.com/ethereum/go-ethereum/p2p/discover"
@@ -360,10 +362,6 @@ var (
360362 Name : "ethstats" ,
361363 Usage : "Reporting URL of a ethstats service (nodename:secret@host:port)" ,
362364 }
363- MetricsEnabledFlag = cli.BoolFlag {
364- Name : metrics .MetricsEnabledFlag ,
365- Usage : "Enable metrics collection and reporting" ,
366- }
367365 FakePoWFlag = cli.BoolFlag {
368366 Name : "fakepow" ,
369367 Usage : "Disables proof-of-work verification" ,
@@ -532,6 +530,45 @@ var (
532530 Usage : "Minimum POW accepted" ,
533531 Value : whisper .DefaultMinimumPoW ,
534532 }
533+
534+ // Metrics flags
535+ MetricsEnabledFlag = cli.BoolFlag {
536+ Name : metrics .MetricsEnabledFlag ,
537+ Usage : "Enable metrics collection and reporting" ,
538+ }
539+ MetricsEnableInfluxDBFlag = cli.BoolFlag {
540+ Name : "metrics.influxdb" ,
541+ Usage : "Enable metrics export/push to an external InfluxDB database" ,
542+ }
543+ MetricsInfluxDBEndpointFlag = cli.StringFlag {
544+ Name : "metrics.influxdb.endpoint" ,
545+ Usage : "InfluxDB API endpoint to report metrics to" ,
546+ Value : "http://localhost:8086" ,
547+ }
548+ MetricsInfluxDBDatabaseFlag = cli.StringFlag {
549+ Name : "metrics.influxdb.database" ,
550+ Usage : "InfluxDB database name to push reported metrics to" ,
551+ Value : "geth" ,
552+ }
553+ MetricsInfluxDBUsernameFlag = cli.StringFlag {
554+ Name : "metrics.influxdb.username" ,
555+ Usage : "Username to authorize access to the database" ,
556+ Value : "test" ,
557+ }
558+ MetricsInfluxDBPasswordFlag = cli.StringFlag {
559+ Name : "metrics.influxdb.password" ,
560+ Usage : "Password to authorize access to the database" ,
561+ Value : "test" ,
562+ }
563+ // The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
564+ // It is used so that we can group all nodes and average a measurement across all of them, but also so
565+ // that we can select a specific node and inspect its measurements.
566+ // https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
567+ MetricsInfluxDBHostTagFlag = cli.StringFlag {
568+ Name : "metrics.influxdb.host.tag" ,
569+ Usage : "InfluxDB `host` tag attached to all measurements" ,
570+ Value : "localhost" ,
571+ }
535572)
536573
537574// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1184,6 +1221,27 @@ func SetupNetwork(ctx *cli.Context) {
11841221 params .TargetGasLimit = ctx .GlobalUint64 (TargetGasLimitFlag .Name )
11851222}
11861223
1224+ func SetupMetrics (ctx * cli.Context ) {
1225+ if metrics .Enabled {
1226+ log .Info ("Enabling metrics collection" )
1227+ var (
1228+ enableExport = ctx .GlobalBool (MetricsEnableInfluxDBFlag .Name )
1229+ endpoint = ctx .GlobalString (MetricsInfluxDBEndpointFlag .Name )
1230+ database = ctx .GlobalString (MetricsInfluxDBDatabaseFlag .Name )
1231+ username = ctx .GlobalString (MetricsInfluxDBUsernameFlag .Name )
1232+ password = ctx .GlobalString (MetricsInfluxDBPasswordFlag .Name )
1233+ hosttag = ctx .GlobalString (MetricsInfluxDBHostTagFlag .Name )
1234+ )
1235+
1236+ if enableExport {
1237+ log .Info ("Enabling metrics export to InfluxDB" )
1238+ go influxdb .InfluxDBWithTags (metrics .DefaultRegistry , 10 * time .Second , endpoint , database , username , password , "geth." , map [string ]string {
1239+ "host" : hosttag ,
1240+ })
1241+ }
1242+ }
1243+ }
1244+
11871245// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
11881246func MakeChainDatabase (ctx * cli.Context , stack * node.Node ) ethdb.Database {
11891247 var (
0 commit comments