cmd/puppeth: reorganize stats reports to make it readable

parent 00566586
......@@ -22,6 +22,7 @@ import (
"html/template"
"math/rand"
"path/filepath"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/log"
......@@ -499,9 +500,13 @@ type dashboardInfos struct {
port int
}
// String implements the stringer interface.
func (info *dashboardInfos) String() string {
return fmt.Sprintf("host=%s, port=%d", info.host, info.port)
// Report converts the typed struct into a plain string->string map, cotnaining
// most - but not all - fields for reporting to the user.
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
......
......@@ -21,6 +21,7 @@ import (
"fmt"
"math/rand"
"path/filepath"
"strconv"
"strings"
"text/template"
......@@ -123,9 +124,15 @@ type ethstatsInfos struct {
banned []string
}
// String implements the stringer interface.
func (info *ethstatsInfos) String() string {
return fmt.Sprintf("host=%s, port=%d, secret=%s, banned=%v", info.host, info.port, info.secret, info.banned)
// Report converts the typed struct into a plain string->string map, cotnaining
// most - but not all - fields for reporting to the user.
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
......
......@@ -18,6 +18,7 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"math/rand"
......@@ -25,6 +26,7 @@ import (
"strconv"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
......@@ -162,9 +164,31 @@ type faucetInfos struct {
captchaSecret string
}
// String implements the stringer interface.
func (info *faucetInfos) String() string {
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)
// Report converts the typed struct into a plain string->string map, cotnaining
// most - but not all - fields for reporting to the user.
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
......
......@@ -22,6 +22,7 @@ import (
"html/template"
"math/rand"
"path/filepath"
"strconv"
"github.com/ethereum/go-ethereum/log"
)
......@@ -88,9 +89,12 @@ type nginxInfos struct {
port int
}
// String implements the stringer interface.
func (info *nginxInfos) String() string {
return fmt.Sprintf("port=%d", info.port)
// Report converts the typed struct into a plain string->string map, cotnaining
// most - but not all - fields for reporting to the user.
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
......
......@@ -18,6 +18,7 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"path/filepath"
......@@ -25,6 +26,7 @@ import (
"strings"
"text/template"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
......@@ -164,14 +166,37 @@ type nodeInfos struct {
gasPrice float64
}
// String implements the stringer interface.
func (info *nodeInfos) String() string {
discv5 := ""
// Report converts the typed struct into a plain string->string map, cotnaining
// most - but not all - fields for reporting to the user.
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 {
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",
info.portFull, discv5, info.datadir, info.peersTotal, info.peersLight, info.ethstats, info.gasTarget, info.gasPrice)
return report
}
// checkNode does a health-check against an boot or seal node server to verify
......
......@@ -38,7 +38,7 @@ func main() {
},
cli.IntFlag{
Name: "loglevel",
Value: 4,
Value: 3,
Usage: "log level to emit to the screen",
},
}
......
......@@ -128,5 +128,5 @@ func (w *wizard) deployDashboard() {
return
}
// All ok, run a network scan to pick any changes up
w.networkStats(false)
w.networkStats()
}
......@@ -112,5 +112,5 @@ func (w *wizard) deployEthstats() {
return
}
// All ok, run a network scan to pick any changes up
w.networkStats(false)
w.networkStats()
}
......@@ -198,5 +198,5 @@ func (w *wizard) deployFaucet() {
return
}
// All ok, run a network scan to pick any changes up
w.networkStats(false)
w.networkStats()
}
......@@ -88,7 +88,7 @@ func (w *wizard) run() {
}
w.servers[server] = client
}
w.networkStats(false)
w.networkStats()
}
// Basics done, loop ad infinitum about what to do
for {
......@@ -110,12 +110,11 @@ func (w *wizard) run() {
} else {
fmt.Println(" 4. Manage network components")
}
//fmt.Println(" 5. ProTips for common usecases")
choice := w.read()
switch {
case choice == "" || choice == "1":
w.networkStats(false)
w.networkStats()
case choice == "2":
if w.conf.genesis == nil {
......@@ -126,7 +125,7 @@ func (w *wizard) run() {
case choice == "3":
if len(w.servers) == 0 {
if w.makeServer() != "" {
w.networkStats(false)
w.networkStats()
}
} else {
w.manageServers()
......@@ -138,9 +137,6 @@ func (w *wizard) run() {
w.manageComponents()
}
case choice == "5":
w.networkStats(true)
default:
log.Error("That's not something I can do")
}
......
This diff is collapsed.
......@@ -53,12 +53,12 @@ func (w *wizard) manageServers() {
w.conf.flush()
log.Info("Disconnected existing server", "server", server)
w.networkStats(false)
w.networkStats()
return
}
// If the user requested connecting a new server, do it
if w.makeServer() != "" {
w.networkStats(false)
w.networkStats()
}
}
......
......@@ -156,5 +156,5 @@ func (w *wizard) deployNode(boot bool) {
log.Info("Waiting for node to finish booting")
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