main.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. package main
  17. import (
  18. "fmt"
  19. "os"
  20. "sort"
  21. "github.com/ethereum/go-ethereum/cmd/utils"
  22. gethmetrics "github.com/ethereum/go-ethereum/metrics"
  23. "github.com/ethereum/go-ethereum/metrics/influxdb"
  24. swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
  25. "github.com/ethereum/go-ethereum/swarm/tracing"
  26. "github.com/ethereum/go-ethereum/log"
  27. cli "gopkg.in/urfave/cli.v1"
  28. )
  29. var (
  30. gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
  31. )
  32. var (
  33. allhosts string
  34. hosts []string
  35. filesize int
  36. syncDelay int
  37. httpPort int
  38. wsPort int
  39. verbosity int
  40. timeout int
  41. single bool
  42. )
  43. func main() {
  44. app := cli.NewApp()
  45. app.Name = "smoke-test"
  46. app.Usage = ""
  47. app.Flags = []cli.Flag{
  48. cli.StringFlag{
  49. Name: "hosts",
  50. Value: "",
  51. Usage: "comma-separated list of swarm hosts",
  52. Destination: &allhosts,
  53. },
  54. cli.IntFlag{
  55. Name: "http-port",
  56. Value: 80,
  57. Usage: "http port",
  58. Destination: &httpPort,
  59. },
  60. cli.IntFlag{
  61. Name: "ws-port",
  62. Value: 8546,
  63. Usage: "ws port",
  64. Destination: &wsPort,
  65. },
  66. cli.IntFlag{
  67. Name: "filesize",
  68. Value: 1024,
  69. Usage: "file size for generated random file in KB",
  70. Destination: &filesize,
  71. },
  72. cli.IntFlag{
  73. Name: "sync-delay",
  74. Value: 5,
  75. Usage: "duration of delay in seconds to wait for content to be synced",
  76. Destination: &syncDelay,
  77. },
  78. cli.IntFlag{
  79. Name: "verbosity",
  80. Value: 1,
  81. Usage: "verbosity",
  82. Destination: &verbosity,
  83. },
  84. cli.IntFlag{
  85. Name: "timeout",
  86. Value: 120,
  87. Usage: "timeout in seconds after which kill the process",
  88. Destination: &timeout,
  89. },
  90. cli.BoolFlag{
  91. Name: "single",
  92. Usage: "whether to fetch content from a single node or from all nodes",
  93. Destination: &single,
  94. },
  95. }
  96. app.Flags = append(app.Flags, []cli.Flag{
  97. utils.MetricsEnabledFlag,
  98. swarmmetrics.MetricsInfluxDBEndpointFlag,
  99. swarmmetrics.MetricsInfluxDBDatabaseFlag,
  100. swarmmetrics.MetricsInfluxDBUsernameFlag,
  101. swarmmetrics.MetricsInfluxDBPasswordFlag,
  102. swarmmetrics.MetricsInfluxDBTagsFlag,
  103. }...)
  104. app.Flags = append(app.Flags, tracing.Flags...)
  105. app.Commands = []cli.Command{
  106. {
  107. Name: "upload_and_sync",
  108. Aliases: []string{"c"},
  109. Usage: "upload and sync",
  110. Action: wrapCliCommand("upload-and-sync", uploadAndSyncCmd),
  111. },
  112. {
  113. Name: "feed_sync",
  114. Aliases: []string{"f"},
  115. Usage: "feed update generate, upload and sync",
  116. Action: wrapCliCommand("feed-and-sync", feedUploadAndSyncCmd),
  117. },
  118. {
  119. Name: "upload_speed",
  120. Aliases: []string{"u"},
  121. Usage: "measure upload speed",
  122. Action: wrapCliCommand("upload-speed", uploadSpeedCmd),
  123. },
  124. {
  125. Name: "sliding_window",
  126. Aliases: []string{"s"},
  127. Usage: "measure network aggregate capacity",
  128. Action: wrapCliCommand("sliding-window", slidingWindowCmd),
  129. },
  130. }
  131. sort.Sort(cli.FlagsByName(app.Flags))
  132. sort.Sort(cli.CommandsByName(app.Commands))
  133. app.Before = func(ctx *cli.Context) error {
  134. tracing.Setup(ctx)
  135. return nil
  136. }
  137. app.After = func(ctx *cli.Context) error {
  138. return emitMetrics(ctx)
  139. }
  140. err := app.Run(os.Args)
  141. if err != nil {
  142. log.Error(err.Error())
  143. os.Exit(1)
  144. }
  145. }
  146. func emitMetrics(ctx *cli.Context) error {
  147. if gethmetrics.Enabled {
  148. var (
  149. endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name)
  150. database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name)
  151. username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name)
  152. password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name)
  153. tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name)
  154. )
  155. tagsMap := utils.SplitTagsFlag(tags)
  156. tagsMap["version"] = gitCommit
  157. tagsMap["filesize"] = fmt.Sprintf("%v", filesize)
  158. return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", tagsMap)
  159. }
  160. return nil
  161. }