@@ -27,6 +27,7 @@ import (
27
27
"runtime"
28
28
"strconv"
29
29
"strings"
30
+ "time"
30
31
31
32
"github.com/ethereum/go-ethereum/accounts"
32
33
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -48,6 +49,7 @@ import (
48
49
"github.com/ethereum/go-ethereum/les"
49
50
"github.com/ethereum/go-ethereum/log"
50
51
"github.com/ethereum/go-ethereum/metrics"
52
+ "github.com/ethereum/go-ethereum/metrics/influxdb"
51
53
"github.com/ethereum/go-ethereum/node"
52
54
"github.com/ethereum/go-ethereum/p2p"
53
55
"github.com/ethereum/go-ethereum/p2p/discover"
@@ -360,10 +362,6 @@ var (
360
362
Name : "ethstats" ,
361
363
Usage : "Reporting URL of a ethstats service (nodename:secret@host:port)" ,
362
364
}
363
- MetricsEnabledFlag = cli.BoolFlag {
364
- Name : metrics .MetricsEnabledFlag ,
365
- Usage : "Enable metrics collection and reporting" ,
366
- }
367
365
FakePoWFlag = cli.BoolFlag {
368
366
Name : "fakepow" ,
369
367
Usage : "Disables proof-of-work verification" ,
@@ -532,6 +530,45 @@ var (
532
530
Usage : "Minimum POW accepted" ,
533
531
Value : whisper .DefaultMinimumPoW ,
534
532
}
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
+ }
535
572
)
536
573
537
574
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1184,6 +1221,27 @@ func SetupNetwork(ctx *cli.Context) {
1184
1221
params .TargetGasLimit = ctx .GlobalUint64 (TargetGasLimitFlag .Name )
1185
1222
}
1186
1223
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
+
1187
1245
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
1188
1246
func MakeChainDatabase (ctx * cli.Context , stack * node.Node ) ethdb.Database {
1189
1247
var (
0 commit comments