github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/metrics/flags.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 25 package metrics 26 27 import ( 28 "time" 29 30 "github.com/ethereum/go-ethereum/cmd/utils" 31 gethmetrics "github.com/ethereum/go-ethereum/metrics" 32 "github.com/ethereum/go-ethereum/metrics/influxdb" 33 "github.com/ethereum/go-ethereum/swarm/log" 34 "gopkg.in/urfave/cli.v1" 35 ) 36 37 var ( 38 metricsEnableInfluxDBExportFlag = cli.BoolFlag{ 39 Name: "metrics.influxdb.export", 40 Usage: "Enable metrics export/push to an external InfluxDB database", 41 } 42 metricsInfluxDBEndpointFlag = cli.StringFlag{ 43 Name: "metrics.influxdb.endpoint", 44 Usage: "Metrics InfluxDB endpoint", 45 Value: "http:// 46 } 47 metricsInfluxDBDatabaseFlag = cli.StringFlag{ 48 Name: "metrics.influxdb.database", 49 Usage: "Metrics InfluxDB database", 50 Value: "metrics", 51 } 52 metricsInfluxDBUsernameFlag = cli.StringFlag{ 53 Name: "metrics.influxdb.username", 54 Usage: "Metrics InfluxDB username", 55 Value: "", 56 } 57 metricsInfluxDBPasswordFlag = cli.StringFlag{ 58 Name: "metrics.influxdb.password", 59 Usage: "Metrics InfluxDB password", 60 Value: "", 61 } 62 // 63 // 64 // 65 // 66 metricsInfluxDBHostTagFlag = cli.StringFlag{ 67 Name: "metrics.influxdb.host.tag", 68 Usage: "Metrics InfluxDB `host` tag attached to all measurements", 69 Value: "localhost", 70 } 71 ) 72 73 // 74 var Flags = []cli.Flag{ 75 utils.MetricsEnabledFlag, 76 metricsEnableInfluxDBExportFlag, 77 metricsInfluxDBEndpointFlag, metricsInfluxDBDatabaseFlag, metricsInfluxDBUsernameFlag, metricsInfluxDBPasswordFlag, metricsInfluxDBHostTagFlag, 78 } 79 80 func Setup(ctx *cli.Context) { 81 if gethmetrics.Enabled { 82 log.Info("Enabling swarm metrics collection") 83 var ( 84 enableExport = ctx.GlobalBool(metricsEnableInfluxDBExportFlag.Name) 85 endpoint = ctx.GlobalString(metricsInfluxDBEndpointFlag.Name) 86 database = ctx.GlobalString(metricsInfluxDBDatabaseFlag.Name) 87 username = ctx.GlobalString(metricsInfluxDBUsernameFlag.Name) 88 password = ctx.GlobalString(metricsInfluxDBPasswordFlag.Name) 89 hosttag = ctx.GlobalString(metricsInfluxDBHostTagFlag.Name) 90 ) 91 92 // 93 go gethmetrics.CollectProcessMetrics(2 * time.Second) 94 95 if enableExport { 96 log.Info("Enabling swarm metrics export to InfluxDB") 97 go influxdb.InfluxDBWithTags(gethmetrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "swarm.", map[string]string{ 98 "host": hosttag, 99 }) 100 } 101 } 102 }