mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
cmd, dashboard: fix after review
This commit is contained in:
parent
e5970bc940
commit
bd416effe8
4 changed files with 17 additions and 64 deletions
|
|
@ -137,8 +137,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.SetShhConfig(ctx, stack, &cfg.Shh)
|
utils.SetShhConfig(ctx, stack, &cfg.Shh)
|
||||||
|
|
||||||
utils.SetDashboardConfig(ctx, &cfg.Dashboard)
|
utils.SetDashboardConfig(ctx, &cfg.Dashboard)
|
||||||
|
|
||||||
return stack, cfg
|
return stack, cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,12 +195,12 @@ var (
|
||||||
}
|
}
|
||||||
DashboardRefreshFlag = cli.DurationFlag{
|
DashboardRefreshFlag = cli.DurationFlag{
|
||||||
Name: "dashboard.refresh",
|
Name: "dashboard.refresh",
|
||||||
Usage: "Dashboard refresh rate",
|
Usage: "Dashboard metrics collection refresh rate",
|
||||||
Value: dashboard.DefaultConfig.Refresh,
|
Value: dashboard.DefaultConfig.Refresh,
|
||||||
}
|
}
|
||||||
DashboardAssetsFlag = cli.StringFlag{
|
DashboardAssetsFlag = cli.StringFlag{
|
||||||
Name: "dashboard.assets",
|
Name: "dashboard.assets",
|
||||||
Usage: "Path of the dashboard assets, useful for debugging (default = \"\", in this case assets.go binary is used)",
|
Usage: "Developer flag to serve the dashboard from the local file system (default: \"\")",
|
||||||
Value: dashboard.DefaultConfig.Assets,
|
Value: dashboard.DefaultConfig.Assets,
|
||||||
}
|
}
|
||||||
// Ethash settings
|
// Ethash settings
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ type Config struct {
|
||||||
// for ephemeral nodes).
|
// for ephemeral nodes).
|
||||||
Port int `toml:",omitempty"`
|
Port int `toml:",omitempty"`
|
||||||
|
|
||||||
// Refresh is the refresh rate of the data updates, the data will be collected this often
|
// Refresh is the refresh rate of the data updates, the data will be collected this often.
|
||||||
Refresh time.Duration `toml:",omitempty"`
|
Refresh time.Duration `toml:",omitempty"`
|
||||||
|
|
||||||
// Assets offers a possibility to manually set the dashboard website's location on the server side
|
// Assets offers a possibility to manually set the dashboard website's location on the server side.
|
||||||
// useful for debugging - avoids the repeated generation of the binary
|
// It is useful for debugging, avoids the repeated generation of the binary.
|
||||||
Assets string `toml:",omitempty"`
|
Assets string `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/rcrowley/go-metrics"
|
"github.com/rcrowley/go-metrics"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
"html/template"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -79,10 +78,8 @@ type status struct {
|
||||||
Block int `json:"block,omitempty"`
|
Block int `json:"block,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new dashboard instance with the given configuration
|
// New creates a new dashboard instance with the given configuration.
|
||||||
func New(config *Config) (*dashboard, error) {
|
func New(config *Config) (*dashboard, error) {
|
||||||
//log.Trace("NewDashboard() called")
|
|
||||||
|
|
||||||
return &dashboard{
|
return &dashboard{
|
||||||
config: config,
|
config: config,
|
||||||
Metrics: &metricSamples{},
|
Metrics: &metricSamples{},
|
||||||
|
|
@ -90,16 +87,14 @@ func New(config *Config) (*dashboard, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protocols is a meaningless implementation of node.Service
|
// Protocols is a meaningless implementation of node.Service.
|
||||||
func (db *dashboard) Protocols() []p2p.Protocol { return nil }
|
func (db *dashboard) Protocols() []p2p.Protocol { return nil }
|
||||||
|
|
||||||
// APIs is a meaningless implementation of node.Service
|
// APIs is a meaningless implementation of node.Service.
|
||||||
func (db *dashboard) APIs() []rpc.API { return nil }
|
func (db *dashboard) APIs() []rpc.API { return nil }
|
||||||
|
|
||||||
// Start implements node.Service, starting the data collection thread and the listening server of the dashboard
|
// Start implements node.Service, starting the data collection thread and the listening server of the dashboard.
|
||||||
func (db *dashboard) Start(server *p2p.Server) error {
|
func (db *dashboard) Start(server *p2p.Server) error {
|
||||||
//log.Trace("Start() called", "config", db.config)
|
|
||||||
|
|
||||||
go db.collectData()
|
go db.collectData()
|
||||||
|
|
||||||
http.HandleFunc("/", db.webHandler)
|
http.HandleFunc("/", db.webHandler)
|
||||||
|
|
@ -112,8 +107,6 @@ func (db *dashboard) Start(server *p2p.Server) error {
|
||||||
db.listener = listener
|
db.listener = listener
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
//log.Trace("Starting server...")
|
|
||||||
|
|
||||||
if err := http.Serve(listener, nil); err != nil {
|
if err := http.Serve(listener, nil); err != nil {
|
||||||
log.Warn("Server failed", "err", err)
|
log.Warn("Server failed", "err", err)
|
||||||
}
|
}
|
||||||
|
|
@ -122,10 +115,8 @@ func (db *dashboard) Start(server *p2p.Server) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop implements node.Service, stopping the data collection thread and the connection listener of the dashboard
|
// Stop implements node.Service, stopping the data collection thread and the connection listener of the dashboard.
|
||||||
func (db *dashboard) Stop() error {
|
func (db *dashboard) Stop() error {
|
||||||
//log.Trace("Terminating dashboard...")
|
|
||||||
|
|
||||||
db.lock.Lock()
|
db.lock.Lock()
|
||||||
defer db.lock.Unlock()
|
defer db.lock.Unlock()
|
||||||
|
|
||||||
|
|
@ -149,7 +140,6 @@ func (db *dashboard) Stop() error {
|
||||||
|
|
||||||
// webHandler handles all non-api requests, simply flattening and returning the dashboard website.
|
// webHandler handles all non-api requests, simply flattening and returning the dashboard website.
|
||||||
func (db *dashboard) webHandler(w http.ResponseWriter, r *http.Request) {
|
func (db *dashboard) webHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
//log.Trace("webHandler() called", "r.URL", r.URL)
|
|
||||||
log.Info("Request", "URL", r.URL)
|
log.Info("Request", "URL", r.URL)
|
||||||
|
|
||||||
path := r.URL.String()
|
path := r.URL.String()
|
||||||
|
|
@ -185,38 +175,18 @@ func (db *dashboard) webHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(index)
|
w.Write(index)
|
||||||
case "/js/handlers.js":
|
|
||||||
tmpl, err := Asset("js/handlers.js")
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Failed to load the asset", "path", path, "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handlers := new(bytes.Buffer)
|
|
||||||
// TODO (kurkomisi): Save the generated template to avoid the repeated generation?
|
|
||||||
// set the sample limits for the client
|
|
||||||
if err = template.Must(template.New("").Parse(string(tmpl))).Execute(handlers, map[string]interface{}{
|
|
||||||
"processorSampleLimit": processorSampleLimit,
|
|
||||||
"memorySampleLimit": memorySampleLimit,
|
|
||||||
"trafficSampleLimit": trafficSampleLimit,
|
|
||||||
}); err != nil {
|
|
||||||
log.Warn("Failed to render the dashboard handlers template", "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Write(handlers.Bytes())
|
|
||||||
default:
|
default:
|
||||||
website, err := Asset(path[1:])
|
webapp, err := Asset(path[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Failed to load the asset", "path", path, "err", err)
|
log.Warn("Failed to load the asset", "path", path, "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(website)
|
w.Write(webapp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// apiHandler handles requests for dashboard
|
// apiHandler handles requests for the dashboard.
|
||||||
func (db *dashboard) apiHandler(conn *websocket.Conn) {
|
func (db *dashboard) apiHandler(conn *websocket.Conn) {
|
||||||
//log.Trace("apiHandler() called")
|
|
||||||
|
|
||||||
client := &client{
|
client := &client{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
logger: log.New("id", atomic.AddUint32(&nextId, 1)),
|
logger: log.New("id", atomic.AddUint32(&nextId, 1)),
|
||||||
|
|
@ -234,9 +204,7 @@ func (db *dashboard) apiHandler(conn *websocket.Conn) {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-db.quit:
|
case <-db.quit:
|
||||||
//client.logger.Trace("apiHandler closed")
|
|
||||||
case <-closed:
|
case <-closed:
|
||||||
//client.logger.Trace("Connection interrupted")
|
|
||||||
db.lock.Lock()
|
db.lock.Lock()
|
||||||
for i, c := range db.conns {
|
for i, c := range db.conns {
|
||||||
if c.conn == client.conn {
|
if c.conn == client.conn {
|
||||||
|
|
@ -258,26 +226,17 @@ func (db *dashboard) apiHandler(conn *websocket.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collectData collects the required data to plot on the dashboard
|
// collectData collects the required data to plot on the dashboard.
|
||||||
func (db *dashboard) collectData() {
|
func (db *dashboard) collectData() {
|
||||||
//log.Trace("collectData() called")
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-db.quit:
|
case <-db.quit:
|
||||||
//log.Trace("collectData closed")
|
|
||||||
return
|
return
|
||||||
case <-time.After(db.config.Refresh):
|
case <-time.After(db.config.Refresh):
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
traffic := metrics.DefaultRegistry.Get("p2p/InboundTraffic").(metrics.Meter).Rate1()
|
traffic := metrics.DefaultRegistry.Get("p2p/InboundTraffic").(metrics.Meter).Rate1()
|
||||||
//if traffic != 0 {
|
|
||||||
// traffic = math.Log(traffic)
|
|
||||||
//}
|
|
||||||
memoryInUse := metrics.DefaultRegistry.Get("system/memory/inuse").(metrics.Meter).Rate1()
|
memoryInUse := metrics.DefaultRegistry.Get("system/memory/inuse").(metrics.Meter).Rate1()
|
||||||
//if memoryInuse != 0 {
|
|
||||||
// memoryInuse = math.Log(memoryInuse)
|
|
||||||
//}
|
|
||||||
traff := &data{
|
traff := &data{
|
||||||
Time: now,
|
Time: now,
|
||||||
Value: traffic,
|
Value: traffic,
|
||||||
|
|
@ -294,10 +253,8 @@ func (db *dashboard) collectData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update updates the dashboards through the live websocket connections
|
// update updates the dashboards through the live websocket connections.
|
||||||
func (db *dashboard) update(processor *data, memory *data) {
|
func (db *dashboard) update(processor *data, memory *data) {
|
||||||
//log.Trace("update() called")
|
|
||||||
|
|
||||||
db.lock.Lock()
|
db.lock.Lock()
|
||||||
defer db.lock.Unlock()
|
defer db.lock.Unlock()
|
||||||
|
|
||||||
|
|
@ -314,8 +271,6 @@ func (db *dashboard) update(processor *data, memory *data) {
|
||||||
db.Metrics.Memory = append(db.Metrics.Memory[first:], memory)
|
db.Metrics.Memory = append(db.Metrics.Memory[first:], memory)
|
||||||
|
|
||||||
for _, c := range db.conns {
|
for _, c := range db.conns {
|
||||||
//c.logger.Trace("Updating dashboard...")
|
|
||||||
|
|
||||||
msg := &map[string]interface{}{
|
msg := &map[string]interface{}{
|
||||||
"processor": processor,
|
"processor": processor,
|
||||||
"memory": memory,
|
"memory": memory,
|
||||||
|
|
@ -327,10 +282,8 @@ func (db *dashboard) update(processor *data, memory *data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendHistory sends the past data through a newly registered websocket connection
|
// sendHistory sends the past data through a newly registered websocket connection.
|
||||||
func (db *dashboard) sendHistory(c *client) {
|
func (db *dashboard) sendHistory(c *client) {
|
||||||
//c.logger.Trace("Sending history...")
|
|
||||||
|
|
||||||
msg := &map[string]interface{}{
|
msg := &map[string]interface{}{
|
||||||
"metrics": db.Metrics,
|
"metrics": db.Metrics,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue