@@ -756,6 +756,29 @@ var (
756
756
Value : metrics .DefaultConfig .InfluxDBTags ,
757
757
}
758
758
759
+ MetricsEnableInfluxDBV2Flag = cli.BoolFlag {
760
+ Name : "metrics.influxdbv2" ,
761
+ Usage : "Enable metrics export/push to an external InfluxDB v2 database" ,
762
+ }
763
+
764
+ MetricsInfluxDBTokenFlag = cli.StringFlag {
765
+ Name : "metrics.influxdb.token" ,
766
+ Usage : "Token to authorize access to the database (v2 only)" ,
767
+ Value : metrics .DefaultConfig .InfluxDBToken ,
768
+ }
769
+
770
+ MetricsInfluxDBBucketFlag = cli.StringFlag {
771
+ Name : "metrics.influxdb.bucket" ,
772
+ Usage : "InfluxDB bucket name to push reported metrics to (v2 only)" ,
773
+ Value : metrics .DefaultConfig .InfluxDBBucket ,
774
+ }
775
+
776
+ MetricsInfluxDBOrganizationFlag = cli.StringFlag {
777
+ Name : "metrics.influxdb.organization" ,
778
+ Usage : "InfluxDB organization name (v2 only)" ,
779
+ Value : metrics .DefaultConfig .InfluxDBOrganization ,
780
+ }
781
+
759
782
CatalystFlag = cli.BoolFlag {
760
783
Name : "catalyst" ,
761
784
Usage : "Catalyst mode (eth2 integration testing)" ,
@@ -1739,11 +1762,36 @@ func SetupMetrics(ctx *cli.Context) {
1739
1762
log .Info ("Enabling metrics collection" )
1740
1763
1741
1764
var (
1742
- enableExport = ctx .GlobalBool (MetricsEnableInfluxDBFlag .Name )
1743
- endpoint = ctx .GlobalString (MetricsInfluxDBEndpointFlag .Name )
1744
- database = ctx .GlobalString (MetricsInfluxDBDatabaseFlag .Name )
1745
- username = ctx .GlobalString (MetricsInfluxDBUsernameFlag .Name )
1746
- password = ctx .GlobalString (MetricsInfluxDBPasswordFlag .Name )
1765
+ enableExport = ctx .GlobalBool (MetricsEnableInfluxDBFlag .Name )
1766
+ enableExportV2 = ctx .GlobalBool (MetricsEnableInfluxDBV2Flag .Name )
1767
+ )
1768
+
1769
+ if enableExport || enableExportV2 {
1770
+ CheckExclusive (ctx , MetricsEnableInfluxDBFlag , MetricsEnableInfluxDBV2Flag )
1771
+
1772
+ v1FlagIsSet := ctx .GlobalIsSet (MetricsInfluxDBUsernameFlag .Name ) ||
1773
+ ctx .GlobalIsSet (MetricsInfluxDBPasswordFlag .Name )
1774
+
1775
+ v2FlagIsSet := ctx .GlobalIsSet (MetricsInfluxDBTokenFlag .Name ) ||
1776
+ ctx .GlobalIsSet (MetricsInfluxDBOrganizationFlag .Name ) ||
1777
+ ctx .GlobalIsSet (MetricsInfluxDBBucketFlag .Name )
1778
+
1779
+ if enableExport && v2FlagIsSet {
1780
+ Fatalf ("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2" )
1781
+ } else if enableExportV2 && v1FlagIsSet {
1782
+ Fatalf ("Flags --influxdb.metrics.username, --influxdb.metrics.password are only available for influxdb-v1" )
1783
+ }
1784
+ }
1785
+
1786
+ var (
1787
+ endpoint = ctx .GlobalString (MetricsInfluxDBEndpointFlag .Name )
1788
+ database = ctx .GlobalString (MetricsInfluxDBDatabaseFlag .Name )
1789
+ username = ctx .GlobalString (MetricsInfluxDBUsernameFlag .Name )
1790
+ password = ctx .GlobalString (MetricsInfluxDBPasswordFlag .Name )
1791
+
1792
+ token = ctx .GlobalString (MetricsInfluxDBTokenFlag .Name )
1793
+ bucket = ctx .GlobalString (MetricsInfluxDBBucketFlag .Name )
1794
+ organization = ctx .GlobalString (MetricsInfluxDBOrganizationFlag .Name )
1747
1795
)
1748
1796
1749
1797
if enableExport {
@@ -1752,6 +1800,12 @@ func SetupMetrics(ctx *cli.Context) {
1752
1800
log .Info ("Enabling metrics export to InfluxDB" )
1753
1801
1754
1802
go influxdb .InfluxDBWithTags (metrics .DefaultRegistry , 10 * time .Second , endpoint , database , username , password , "geth." , tagsMap )
1803
+ } else if enableExportV2 {
1804
+ tagsMap := SplitTagsFlag (ctx .GlobalString (MetricsInfluxDBTagsFlag .Name ))
1805
+
1806
+ log .Info ("Enabling metrics export to InfluxDB (v2)" )
1807
+
1808
+ go influxdb .InfluxDBV2WithTags (metrics .DefaultRegistry , 10 * time .Second , endpoint , token , bucket , organization , "geth." , tagsMap )
1755
1809
}
1756
1810
1757
1811
if ctx .GlobalIsSet (MetricsHTTPFlag .Name ) {
0 commit comments