wizard_ethstats.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2017 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. "github.com/ethereum/go-ethereum/log"
  20. )
  21. // deployEthstats queries the user for various input on deploying an ethstats
  22. // monitoring server, after which it executes it.
  23. func (w *wizard) deployEthstats() {
  24. // Select the server to interact with
  25. server := w.selectServer()
  26. if server == "" {
  27. return
  28. }
  29. client := w.servers[server]
  30. // Retrieve any active ethstats configurations from the server
  31. infos, err := checkEthstats(client, w.network)
  32. if err != nil {
  33. infos = &ethstatsInfos{
  34. port: 80,
  35. host: client.server,
  36. secret: "",
  37. }
  38. }
  39. // Figure out which port to listen on
  40. fmt.Println()
  41. fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port)
  42. infos.port = w.readDefaultInt(infos.port)
  43. // Figure which virtual-host to deploy ethstats on
  44. if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil {
  45. log.Error("Failed to decide on ethstats host", "err", err)
  46. return
  47. }
  48. // Port and proxy settings retrieved, figure out the secret and boot ethstats
  49. fmt.Println()
  50. if infos.secret == "" {
  51. fmt.Printf("What should be the secret password for the API? (must not be empty)\n")
  52. infos.secret = w.readString()
  53. } else {
  54. fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret)
  55. infos.secret = w.readDefaultString(infos.secret)
  56. }
  57. // Try to deploy the ethstats server on the host
  58. trusted := make([]string, 0, len(w.servers))
  59. for _, client := range w.servers {
  60. if client != nil {
  61. trusted = append(trusted, client.address)
  62. }
  63. }
  64. if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted); err != nil {
  65. log.Error("Failed to deploy ethstats container", "err", err)
  66. if len(out) > 0 {
  67. fmt.Printf("%s\n", out)
  68. }
  69. return
  70. }
  71. // All ok, run a network scan to pick any changes up
  72. w.networkStats(false)
  73. }