github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/swarm/metrics/flags.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:47</date> 10 //</624342671753744384> 11 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 // 25 // 26 // 27 28 package metrics 29 30 import ( 31 "time" 32 33 "github.com/ethereum/go-ethereum/cmd/utils" 34 gethmetrics "github.com/ethereum/go-ethereum/metrics" 35 "github.com/ethereum/go-ethereum/metrics/influxdb" 36 "github.com/ethereum/go-ethereum/swarm/log" 37 "gopkg.in/urfave/cli.v1" 38 ) 39 40 var ( 41 metricsEnableInfluxDBExportFlag = cli.BoolFlag{ 42 Name: "metrics.influxdb.export", 43 Usage: "Enable metrics export/push to an external InfluxDB database", 44 } 45 metricsInfluxDBEndpointFlag = cli.StringFlag{ 46 Name: "metrics.influxdb.endpoint", 47 Usage: "Metrics InfluxDB endpoint", 48 Value: "http:// 49 } 50 metricsInfluxDBDatabaseFlag = cli.StringFlag{ 51 Name: "metrics.influxdb.database", 52 Usage: "Metrics InfluxDB database", 53 Value: "metrics", 54 } 55 metricsInfluxDBUsernameFlag = cli.StringFlag{ 56 Name: "metrics.influxdb.username", 57 Usage: "Metrics InfluxDB username", 58 Value: "", 59 } 60 metricsInfluxDBPasswordFlag = cli.StringFlag{ 61 Name: "metrics.influxdb.password", 62 Usage: "Metrics InfluxDB password", 63 Value: "", 64 } 65 // 66 // 67 // 68 // 69 metricsInfluxDBHostTagFlag = cli.StringFlag{ 70 Name: "metrics.influxdb.host.tag", 71 Usage: "Metrics InfluxDB `host` tag attached to all measurements", 72 Value: "localhost", 73 } 74 ) 75 76 // 77 var Flags = []cli.Flag{ 78 utils.MetricsEnabledFlag, 79 metricsEnableInfluxDBExportFlag, 80 metricsInfluxDBEndpointFlag, metricsInfluxDBDatabaseFlag, metricsInfluxDBUsernameFlag, metricsInfluxDBPasswordFlag, metricsInfluxDBHostTagFlag, 81 } 82 83 func Setup(ctx *cli.Context) { 84 if gethmetrics.Enabled { 85 log.Info("Enabling swarm metrics collection") 86 var ( 87 enableExport = ctx.GlobalBool(metricsEnableInfluxDBExportFlag.Name) 88 endpoint = ctx.GlobalString(metricsInfluxDBEndpointFlag.Name) 89 database = ctx.GlobalString(metricsInfluxDBDatabaseFlag.Name) 90 username = ctx.GlobalString(metricsInfluxDBUsernameFlag.Name) 91 password = ctx.GlobalString(metricsInfluxDBPasswordFlag.Name) 92 hosttag = ctx.GlobalString(metricsInfluxDBHostTagFlag.Name) 93 ) 94 95 // 96 go gethmetrics.CollectProcessMetrics(2 * time.Second) 97 98 if enableExport { 99 log.Info("Enabling swarm metrics export to InfluxDB") 100 go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "swarm.", map[string]string{ 101 "host": hosttag, 102 }) 103 } 104 } 105 } 106