Skip to content

Commit fdbf8be

Browse files
committed
cmd/geth, rpc/api: fix reported metrics issues
1 parent c0343c8 commit fdbf8be

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

cmd/geth/monitorcmd.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math"
66
"reflect"
7+
"runtime"
78
"sort"
89
"strings"
910
"time"
@@ -72,15 +73,7 @@ func monitor(ctx *cli.Context) {
7273
}
7374
monitored := resolveMetrics(metrics, ctx.Args())
7475
if len(monitored) == 0 {
75-
list := []string{}
76-
for _, metric := range expandMetrics(metrics, "") {
77-
switch {
78-
case strings.HasSuffix(metric, "/0"):
79-
list = append(list, strings.Replace(metric, "/0", "/[0-100]", -1))
80-
case !strings.Contains(metric, "Percentiles"):
81-
list = append(list, metric)
82-
}
83-
}
76+
list := expandMetrics(metrics, "")
8477
sort.Strings(list)
8578
utils.Fatalf("No metrics specified.\n\nAvailable:\n - %s", strings.Join(list, "\n - "))
8679
}
@@ -116,11 +109,14 @@ func monitor(ctx *cli.Context) {
116109
}
117110
for i, metric := range monitored {
118111
charts[i] = termui.NewLineChart()
112+
if runtime.GOOS == "windows" {
113+
charts[i].Mode = "dot"
114+
}
119115
charts[i].Data = make([]float64, 512)
120116
charts[i].DataLabels = []string{""}
121117
charts[i].Height = (termui.TermHeight() - footer.Height) / rows
122118
charts[i].AxesColor = termui.ColorWhite
123-
charts[i].PaddingBottom = -1
119+
charts[i].PaddingBottom = -2
124120

125121
charts[i].Border.Label = metric
126122
charts[i].Border.LabelFgColor = charts[i].Border.FgColor | termui.AttrBold
@@ -141,7 +137,7 @@ func monitor(ctx *cli.Context) {
141137
for {
142138
select {
143139
case event := <-termui.EventCh():
144-
if event.Type == termui.EventKey && event.Ch == 'q' {
140+
if event.Type == termui.EventKey && event.Key == termui.KeyCtrlC {
145141
return
146142
}
147143
if event.Type == termui.EventResize {
@@ -302,7 +298,7 @@ func updateChart(metric string, data []float64, chart *termui.LineChart, err err
302298
func updateFooter(ctx *cli.Context, err error, footer *termui.Par) {
303299
// Generate the basic footer
304300
refresh := time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second
305-
footer.Text = fmt.Sprintf("Press q to quit. Refresh interval: %v.", refresh)
301+
footer.Text = fmt.Sprintf("Press Ctrl+C to quit. Refresh interval: %v.", refresh)
306302
footer.TextFgColor = termui.Theme().ParTextFg | termui.AttrBold
307303

308304
// Append any encountered errors

rpc/api/debug.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ func (self *debugApi) Metrics(req *shared.Request) (interface{}, error) {
193193
format := func(total float64, rate float64) string {
194194
return fmt.Sprintf("%s (%s/s)", round(total, 0), round(rate, 2))
195195
}
196-
// Create the percentile units
197-
percentiles := make([]float64, 101)
198-
for i := 0; i <= 100; i++ {
199-
percentiles[i] = float64(i) / 100
200-
}
201196
// Iterate over all the metrics, and just dump for now
202197
counters := make(map[string]interface{})
203198
metrics.DefaultRegistry.Each(func(name string, metric interface{}) {
@@ -220,21 +215,23 @@ func (self *debugApi) Metrics(req *shared.Request) (interface{}, error) {
220215
"AvgRate05Min": metric.Rate5(),
221216
"AvgRate15Min": metric.Rate15(),
222217
"MeanRate": metric.RateMean(),
223-
"Total": float64(metric.Count()),
218+
"Overall": float64(metric.Count()),
224219
}
225220

226221
case metrics.Timer:
227-
ps := make(map[string]interface{})
228-
for i, p := range metric.Percentiles(percentiles) {
229-
ps[fmt.Sprintf("%d", i)] = p
230-
}
231222
root[name] = map[string]interface{}{
232223
"AvgRate01Min": metric.Rate1(),
233224
"AvgRate05Min": metric.Rate5(),
234225
"AvgRate15Min": metric.Rate15(),
235226
"MeanRate": metric.RateMean(),
236-
"Total": float64(metric.Count()),
237-
"Percentiles": ps,
227+
"Overall": float64(metric.Count()),
228+
"Percentiles": map[string]interface{}{
229+
"5": metric.Percentile(0.05),
230+
"20": metric.Percentile(0.2),
231+
"50": metric.Percentile(0.5),
232+
"80": metric.Percentile(0.8),
233+
"95": metric.Percentile(0.95),
234+
},
238235
}
239236

240237
default:
@@ -247,23 +244,23 @@ func (self *debugApi) Metrics(req *shared.Request) (interface{}, error) {
247244
"Avg01Min": format(metric.Rate1()*60, metric.Rate1()),
248245
"Avg05Min": format(metric.Rate5()*300, metric.Rate5()),
249246
"Avg15Min": format(metric.Rate15()*900, metric.Rate15()),
250-
"Total": format(float64(metric.Count()), metric.RateMean()),
247+
"Overall": format(float64(metric.Count()), metric.RateMean()),
251248
}
252249

253250
case metrics.Timer:
254251
root[name] = map[string]interface{}{
255252
"Avg01Min": format(metric.Rate1()*60, metric.Rate1()),
256253
"Avg05Min": format(metric.Rate5()*300, metric.Rate5()),
257254
"Avg15Min": format(metric.Rate15()*900, metric.Rate15()),
258-
"Total": format(float64(metric.Count()), metric.RateMean()),
255+
"Overall": format(float64(metric.Count()), metric.RateMean()),
259256
"Maximum": time.Duration(metric.Max()).String(),
260257
"Minimum": time.Duration(metric.Min()).String(),
261258
"Percentiles": map[string]interface{}{
259+
"5": time.Duration(metric.Percentile(0.05)).String(),
262260
"20": time.Duration(metric.Percentile(0.2)).String(),
263261
"50": time.Duration(metric.Percentile(0.5)).String(),
264262
"80": time.Duration(metric.Percentile(0.8)).String(),
265263
"95": time.Duration(metric.Percentile(0.95)).String(),
266-
"99": time.Duration(metric.Percentile(0.99)).String(),
267264
},
268265
}
269266

0 commit comments

Comments
 (0)