github.com/nitinawathare/ethereumassignment3@v0.0.0-20211021213010-f07344c2b868/go-ethereum/cmd/swarm/swarm-smoke/main.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 "sort" 23 24 "github.com/ethereum/go-ethereum/cmd/utils" 25 gethmetrics "github.com/ethereum/go-ethereum/metrics" 26 "github.com/ethereum/go-ethereum/metrics/influxdb" 27 swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics" 28 "github.com/ethereum/go-ethereum/swarm/tracing" 29 30 "github.com/ethereum/go-ethereum/log" 31 32 cli "gopkg.in/urfave/cli.v1" 33 ) 34 35 var ( 36 gitCommit string // Git SHA1 commit hash of the release (set via linker flags) 37 ) 38 39 var ( 40 allhosts string 41 hosts []string 42 filesize int 43 inputSeed int 44 syncDelay int 45 httpPort int 46 wsPort int 47 verbosity int 48 timeout int 49 single bool 50 trackTimeout int 51 ) 52 53 func main() { 54 55 app := cli.NewApp() 56 app.Name = "smoke-test" 57 app.Usage = "" 58 59 app.Flags = []cli.Flag{ 60 cli.StringFlag{ 61 Name: "hosts", 62 Value: "", 63 Usage: "comma-separated list of swarm hosts", 64 Destination: &allhosts, 65 }, 66 cli.IntFlag{ 67 Name: "http-port", 68 Value: 80, 69 Usage: "http port", 70 Destination: &httpPort, 71 }, 72 cli.IntFlag{ 73 Name: "ws-port", 74 Value: 8546, 75 Usage: "ws port", 76 Destination: &wsPort, 77 }, 78 cli.IntFlag{ 79 Name: "seed", 80 Value: 0, 81 Usage: "input seed in case we need deterministic upload", 82 Destination: &inputSeed, 83 }, 84 cli.IntFlag{ 85 Name: "filesize", 86 Value: 1024, 87 Usage: "file size for generated random file in KB", 88 Destination: &filesize, 89 }, 90 cli.IntFlag{ 91 Name: "sync-delay", 92 Value: 5, 93 Usage: "duration of delay in seconds to wait for content to be synced", 94 Destination: &syncDelay, 95 }, 96 cli.IntFlag{ 97 Name: "verbosity", 98 Value: 1, 99 Usage: "verbosity", 100 Destination: &verbosity, 101 }, 102 cli.IntFlag{ 103 Name: "timeout", 104 Value: 120, 105 Usage: "timeout in seconds after which kill the process", 106 Destination: &timeout, 107 }, 108 cli.BoolFlag{ 109 Name: "single", 110 Usage: "whether to fetch content from a single node or from all nodes", 111 Destination: &single, 112 }, 113 cli.IntFlag{ 114 Name: "track-timeout", 115 Value: 5, 116 Usage: "timeout in seconds to wait for GetAllReferences to return", 117 Destination: &trackTimeout, 118 }, 119 } 120 121 app.Flags = append(app.Flags, []cli.Flag{ 122 utils.MetricsEnabledFlag, 123 swarmmetrics.MetricsInfluxDBEndpointFlag, 124 swarmmetrics.MetricsInfluxDBDatabaseFlag, 125 swarmmetrics.MetricsInfluxDBUsernameFlag, 126 swarmmetrics.MetricsInfluxDBPasswordFlag, 127 swarmmetrics.MetricsInfluxDBTagsFlag, 128 }...) 129 130 app.Flags = append(app.Flags, tracing.Flags...) 131 132 app.Commands = []cli.Command{ 133 { 134 Name: "upload_and_sync", 135 Aliases: []string{"c"}, 136 Usage: "upload and sync", 137 Action: wrapCliCommand("upload-and-sync", uploadAndSyncCmd), 138 }, 139 { 140 Name: "feed_sync", 141 Aliases: []string{"f"}, 142 Usage: "feed update generate, upload and sync", 143 Action: wrapCliCommand("feed-and-sync", feedUploadAndSyncCmd), 144 }, 145 { 146 Name: "upload_speed", 147 Aliases: []string{"u"}, 148 Usage: "measure upload speed", 149 Action: wrapCliCommand("upload-speed", uploadSpeedCmd), 150 }, 151 { 152 Name: "sliding_window", 153 Aliases: []string{"s"}, 154 Usage: "measure network aggregate capacity", 155 Action: wrapCliCommand("sliding-window", slidingWindowCmd), 156 }, 157 } 158 159 sort.Sort(cli.FlagsByName(app.Flags)) 160 sort.Sort(cli.CommandsByName(app.Commands)) 161 162 app.Before = func(ctx *cli.Context) error { 163 tracing.Setup(ctx) 164 return nil 165 } 166 167 app.After = func(ctx *cli.Context) error { 168 return emitMetrics(ctx) 169 } 170 171 err := app.Run(os.Args) 172 if err != nil { 173 log.Error(err.Error()) 174 175 os.Exit(1) 176 } 177 } 178 179 func emitMetrics(ctx *cli.Context) error { 180 if gethmetrics.Enabled { 181 var ( 182 endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) 183 database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name) 184 username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name) 185 password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name) 186 tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name) 187 ) 188 189 tagsMap := utils.SplitTagsFlag(tags) 190 tagsMap["version"] = gitCommit 191 tagsMap["filesize"] = fmt.Sprintf("%v", filesize) 192 193 return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", tagsMap) 194 } 195 196 return nil 197 }