cmd/puppeth: reorganize stats reports to make it readable

parent 00566586
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"html/template" "html/template"
"math/rand" "math/rand"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -499,9 +500,13 @@ type dashboardInfos struct { ...@@ -499,9 +500,13 @@ type dashboardInfos struct {
port int port int
} }
// String implements the stringer interface. // Report converts the typed struct into a plain string->string map, cotnaining
func (info *dashboardInfos) String() string { // most - but not all - fields for reporting to the user.
return fmt.Sprintf("host=%s, port=%d", info.host, info.port) func (info *dashboardInfos) Report() map[string]string {
return map[string]string{
"Website address": info.host,
"Website listener port": strconv.Itoa(info.port),
}
} }
// checkDashboard does a health-check against a dashboard container to verify if // checkDashboard does a health-check against a dashboard container to verify if
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"text/template" "text/template"
...@@ -123,9 +124,15 @@ type ethstatsInfos struct { ...@@ -123,9 +124,15 @@ type ethstatsInfos struct {
banned []string banned []string
} }
// String implements the stringer interface. // Report converts the typed struct into a plain string->string map, cotnaining
func (info *ethstatsInfos) String() string { // most - but not all - fields for reporting to the user.
return fmt.Sprintf("host=%s, port=%d, secret=%s, banned=%v", info.host, info.port, info.secret, info.banned) func (info *ethstatsInfos) Report() map[string]string {
return map[string]string{
"Website address": info.host,
"Website listener port": strconv.Itoa(info.port),
"Login secret": info.secret,
"Banned addresses": fmt.Sprintf("%v", info.banned),
}
} }
// checkEthstats does a health-check against an ethstats server to verify whether // checkEthstats does a health-check against an ethstats server to verify whether
......
...@@ -18,6 +18,7 @@ package main ...@@ -18,6 +18,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"math/rand" "math/rand"
...@@ -25,6 +26,7 @@ import ( ...@@ -25,6 +26,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -162,9 +164,31 @@ type faucetInfos struct { ...@@ -162,9 +164,31 @@ type faucetInfos struct {
captchaSecret string captchaSecret string
} }
// String implements the stringer interface. // Report converts the typed struct into a plain string->string map, cotnaining
func (info *faucetInfos) String() string { // most - but not all - fields for reporting to the user.
return fmt.Sprintf("host=%s, api=%d, eth=%d, amount=%d, minutes=%d, tiers=%d, github=%s, captcha=%v, ethstats=%s", info.host, info.port, info.node.portFull, info.amount, info.minutes, info.tiers, info.githubUser, info.captchaToken != "", info.node.ethstats) func (info *faucetInfos) Report() map[string]string {
report := map[string]string{
"Website address": info.host,
"Website listener port": strconv.Itoa(info.port),
"Ethereum listener port": strconv.Itoa(info.node.portFull),
"Funding amount (base tier)": fmt.Sprintf("%d Ethers", info.amount),
"Funding cooldown (base tier)": fmt.Sprintf("%d mins", info.minutes),
"Funding tiers": strconv.Itoa(info.tiers),
"Captha protection": fmt.Sprintf("%v", info.captchaToken != ""),
"Ethstats username": info.node.ethstats,
"GitHub authentication": info.githubUser,
}
if info.node.keyJSON != "" {
var key struct {
Address string `json:"address"`
}
if err := json.Unmarshal([]byte(info.node.keyJSON), &key); err == nil {
report["Funding account"] = common.HexToAddress(key.Address).Hex()
} else {
log.Error("Failed to retrieve signer address", "err", err)
}
}
return report
} }
// checkFaucet does a health-check against an faucet server to verify whether // checkFaucet does a health-check against an faucet server to verify whether
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"html/template" "html/template"
"math/rand" "math/rand"
"path/filepath" "path/filepath"
"strconv"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -88,9 +89,12 @@ type nginxInfos struct { ...@@ -88,9 +89,12 @@ type nginxInfos struct {
port int port int
} }
// String implements the stringer interface. // Report converts the typed struct into a plain string->string map, cotnaining
func (info *nginxInfos) String() string { // most - but not all - fields for reporting to the user.
return fmt.Sprintf("port=%d", info.port) func (info *nginxInfos) Report() map[string]string {
return map[string]string{
"Shared listener port": strconv.Itoa(info.port),
}
} }
// checkNginx does a health-check against an nginx reverse-proxy to verify whether // checkNginx does a health-check against an nginx reverse-proxy to verify whether
......
...@@ -18,6 +18,7 @@ package main ...@@ -18,6 +18,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"path/filepath" "path/filepath"
...@@ -25,6 +26,7 @@ import ( ...@@ -25,6 +26,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -164,14 +166,37 @@ type nodeInfos struct { ...@@ -164,14 +166,37 @@ type nodeInfos struct {
gasPrice float64 gasPrice float64
} }
// String implements the stringer interface. // Report converts the typed struct into a plain string->string map, cotnaining
func (info *nodeInfos) String() string { // most - but not all - fields for reporting to the user.
discv5 := "" func (info *nodeInfos) Report() map[string]string {
report := map[string]string{
"Data directory": info.datadir,
"Listener port (full nodes)": strconv.Itoa(info.portFull),
"Peer count (all total)": strconv.Itoa(info.peersTotal),
"Peer count (light nodes)": strconv.Itoa(info.peersLight),
"Ethstats username": info.ethstats,
}
if info.peersLight > 0 { if info.peersLight > 0 {
discv5 = fmt.Sprintf(", portv5=%d", info.portLight) report["Listener port (light nodes)"] = strconv.Itoa(info.portLight)
}
if info.gasTarget > 0 {
report["Gas limit (baseline target)"] = fmt.Sprintf("%0.3f MGas", info.gasTarget)
report["Gas price (minimum accepted)"] = fmt.Sprintf("%0.3f GWei", info.gasPrice)
}
if info.etherbase != "" {
report["Miner account"] = info.etherbase
}
if info.keyJSON != "" {
var key struct {
Address string `json:"address"`
}
if err := json.Unmarshal([]byte(info.keyJSON), &key); err == nil {
report["Signer account"] = common.HexToAddress(key.Address).Hex()
} else {
log.Error("Failed to retrieve signer address", "err", err)
}
} }
return fmt.Sprintf("port=%d%s, datadir=%s, peers=%d, lights=%d, ethstats=%s, gastarget=%0.3f MGas, gasprice=%0.3f GWei", return report
info.portFull, discv5, info.datadir, info.peersTotal, info.peersLight, info.ethstats, info.gasTarget, info.gasPrice)
} }
// checkNode does a health-check against an boot or seal node server to verify // checkNode does a health-check against an boot or seal node server to verify
......
...@@ -38,7 +38,7 @@ func main() { ...@@ -38,7 +38,7 @@ func main() {
}, },
cli.IntFlag{ cli.IntFlag{
Name: "loglevel", Name: "loglevel",
Value: 4, Value: 3,
Usage: "log level to emit to the screen", Usage: "log level to emit to the screen",
}, },
} }
......
...@@ -128,5 +128,5 @@ func (w *wizard) deployDashboard() { ...@@ -128,5 +128,5 @@ func (w *wizard) deployDashboard() {
return return
} }
// All ok, run a network scan to pick any changes up // All ok, run a network scan to pick any changes up
w.networkStats(false) w.networkStats()
} }
...@@ -112,5 +112,5 @@ func (w *wizard) deployEthstats() { ...@@ -112,5 +112,5 @@ func (w *wizard) deployEthstats() {
return return
} }
// All ok, run a network scan to pick any changes up // All ok, run a network scan to pick any changes up
w.networkStats(false) w.networkStats()
} }
...@@ -198,5 +198,5 @@ func (w *wizard) deployFaucet() { ...@@ -198,5 +198,5 @@ func (w *wizard) deployFaucet() {
return return
} }
// All ok, run a network scan to pick any changes up // All ok, run a network scan to pick any changes up
w.networkStats(false) w.networkStats()
} }
...@@ -88,7 +88,7 @@ func (w *wizard) run() { ...@@ -88,7 +88,7 @@ func (w *wizard) run() {
} }
w.servers[server] = client w.servers[server] = client
} }
w.networkStats(false) w.networkStats()
} }
// Basics done, loop ad infinitum about what to do // Basics done, loop ad infinitum about what to do
for { for {
...@@ -110,12 +110,11 @@ func (w *wizard) run() { ...@@ -110,12 +110,11 @@ func (w *wizard) run() {
} else { } else {
fmt.Println(" 4. Manage network components") fmt.Println(" 4. Manage network components")
} }
//fmt.Println(" 5. ProTips for common usecases")
choice := w.read() choice := w.read()
switch { switch {
case choice == "" || choice == "1": case choice == "" || choice == "1":
w.networkStats(false) w.networkStats()
case choice == "2": case choice == "2":
if w.conf.genesis == nil { if w.conf.genesis == nil {
...@@ -126,7 +125,7 @@ func (w *wizard) run() { ...@@ -126,7 +125,7 @@ func (w *wizard) run() {
case choice == "3": case choice == "3":
if len(w.servers) == 0 { if len(w.servers) == 0 {
if w.makeServer() != "" { if w.makeServer() != "" {
w.networkStats(false) w.networkStats()
} }
} else { } else {
w.manageServers() w.manageServers()
...@@ -138,9 +137,6 @@ func (w *wizard) run() { ...@@ -138,9 +137,6 @@ func (w *wizard) run() {
w.manageComponents() w.manageComponents()
} }
case choice == "5":
w.networkStats(true)
default: default:
log.Error("That's not something I can do") log.Error("That's not something I can do")
} }
......
This diff is collapsed.
...@@ -53,12 +53,12 @@ func (w *wizard) manageServers() { ...@@ -53,12 +53,12 @@ func (w *wizard) manageServers() {
w.conf.flush() w.conf.flush()
log.Info("Disconnected existing server", "server", server) log.Info("Disconnected existing server", "server", server)
w.networkStats(false) w.networkStats()
return return
} }
// If the user requested connecting a new server, do it // If the user requested connecting a new server, do it
if w.makeServer() != "" { if w.makeServer() != "" {
w.networkStats(false) w.networkStats()
} }
} }
......
...@@ -156,5 +156,5 @@ func (w *wizard) deployNode(boot bool) { ...@@ -156,5 +156,5 @@ func (w *wizard) deployNode(boot bool) {
log.Info("Waiting for node to finish booting") log.Info("Waiting for node to finish booting")
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
w.networkStats(false) w.networkStats()
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment