@@ -23,7 +23,7 @@ import (
23
23
gethmetrics "github.com/ethereum/go-ethereum/metrics"
24
24
"github.com/ethereum/go-ethereum/metrics/influxdb"
25
25
"github.com/ethereum/go-ethereum/swarm/log"
26
- "gopkg.in/urfave/cli.v1"
26
+ cli "gopkg.in/urfave/cli.v1"
27
27
)
28
28
29
29
var (
@@ -55,14 +55,14 @@ var (
55
55
Usage : "Metrics InfluxDB password" ,
56
56
Value : "" ,
57
57
}
58
- // The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
59
- // It is used so that we can group all nodes and average a measurement across all of them, but also so
60
- // that we can select a specific node and inspect its measurements.
58
+ // Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
59
+ // For example `host` tag could be used so that we can group all nodes and average a measurement
60
+ // across all of them, but also so that we can select a specific node and inspect its measurements.
61
61
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
62
- MetricsInfluxDBHostTagFlag = cli.StringFlag {
63
- Name : "metrics.influxdb.host.tag " ,
64
- Usage : "Metrics InfluxDB `host` tag attached to all measurements" ,
65
- Value : "localhost" ,
62
+ MetricsInfluxDBTagsFlag = cli.StringFlag {
63
+ Name : "metrics.influxdb.tags " ,
64
+ Usage : "Comma-separated InfluxDB tags (key/values) attached to all measurements" ,
65
+ Value : "host= localhost" ,
66
66
}
67
67
)
68
68
@@ -75,37 +75,34 @@ var Flags = []cli.Flag{
75
75
MetricsInfluxDBDatabaseFlag ,
76
76
MetricsInfluxDBUsernameFlag ,
77
77
MetricsInfluxDBPasswordFlag ,
78
- MetricsInfluxDBHostTagFlag ,
78
+ MetricsInfluxDBTagsFlag ,
79
79
}
80
80
81
81
func Setup (ctx * cli.Context ) {
82
82
if gethmetrics .Enabled {
83
83
log .Info ("Enabling swarm metrics collection" )
84
84
var (
85
- enableExport = ctx .GlobalBool (MetricsEnableInfluxDBExportFlag .Name )
86
- enableAccountingExport = ctx .GlobalBool (MetricsEnableInfluxDBAccountingExportFlag .Name )
87
85
endpoint = ctx .GlobalString (MetricsInfluxDBEndpointFlag .Name )
88
86
database = ctx .GlobalString (MetricsInfluxDBDatabaseFlag .Name )
89
87
username = ctx .GlobalString (MetricsInfluxDBUsernameFlag .Name )
90
88
password = ctx .GlobalString (MetricsInfluxDBPasswordFlag .Name )
91
- hosttag = ctx .GlobalString (MetricsInfluxDBHostTagFlag .Name )
89
+ enableExport = ctx .GlobalBool (MetricsEnableInfluxDBExportFlag .Name )
90
+ enableAccountingExport = ctx .GlobalBool (MetricsEnableInfluxDBAccountingExportFlag .Name )
92
91
)
93
92
94
93
// Start system runtime metrics collection
95
94
go gethmetrics .CollectProcessMetrics (2 * time .Second )
96
95
96
+ tagsMap := utils .SplitTagsFlag (ctx .GlobalString (MetricsInfluxDBTagsFlag .Name ))
97
+
97
98
if enableExport {
98
99
log .Info ("Enabling swarm metrics export to InfluxDB" )
99
- go influxdb .InfluxDBWithTags (gethmetrics .DefaultRegistry , 10 * time .Second , endpoint , database , username , password , "swarm." , map [string ]string {
100
- "host" : hosttag ,
101
- })
100
+ go influxdb .InfluxDBWithTags (gethmetrics .DefaultRegistry , 10 * time .Second , endpoint , database , username , password , "swarm." , tagsMap )
102
101
}
103
102
104
103
if enableAccountingExport {
105
- log .Info ("Exporting accounting metrics to InfluxDB" )
106
- go influxdb .InfluxDBWithTags (gethmetrics .AccountingRegistry , 10 * time .Second , endpoint , database , username , password , "accounting." , map [string ]string {
107
- "host" : hosttag ,
108
- })
104
+ log .Info ("Exporting swarm accounting metrics to InfluxDB" )
105
+ go influxdb .InfluxDBWithTags (gethmetrics .AccountingRegistry , 10 * time .Second , endpoint , database , username , password , "accounting." , tagsMap )
109
106
}
110
107
}
111
108
}
0 commit comments