aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-24 22:12:38 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-24 23:34:05 +0800
commit302187ae397c5e06a9f086183d55f591f5daf588 (patch)
treebadb014f70927ae3118c193a44a894d312c6427e /cmd
parentbf99d5b33c716ecb8b7dac8234df07b0ea82c48f (diff)
downloadgo-tangerine-302187ae397c5e06a9f086183d55f591f5daf588.tar.gz
go-tangerine-302187ae397c5e06a9f086183d55f591f5daf588.tar.zst
go-tangerine-302187ae397c5e06a9f086183d55f591f5daf588.zip
cmd/geth: allow branching metric patterns
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/monitorcmd.go43
1 files changed, 25 insertions, 18 deletions
diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go
index 06ccf90be..ec0dfb8f2 100644
--- a/cmd/geth/monitorcmd.go
+++ b/cmd/geth/monitorcmd.go
@@ -149,30 +149,37 @@ func resolveMetrics(metrics map[string]interface{}, patterns []string) []string
// resolveMetrics takes a single of input metric pattern, and resolves it to one
// or more canonical metric names.
func resolveMetric(metrics map[string]interface{}, pattern string, path string) []string {
- var ok bool
-
- // Build up the canonical metric path
- parts := strings.Split(pattern, "/")
- for len(parts) > 1 {
- if metrics, ok = metrics[parts[0]].(map[string]interface{}); !ok {
- utils.Fatalf("Failed to retrieve system metrics: %s", path+parts[0])
+ results := []string{}
+
+ // If a nested metric was requested, recurse optionally branching (via comma)
+ parts := strings.SplitN(pattern, "/", 2)
+ if len(parts) > 1 {
+ for _, variation := range strings.Split(parts[0], ",") {
+ if submetrics, ok := metrics[variation].(map[string]interface{}); !ok {
+ utils.Fatalf("Failed to retrieve system metrics: %s", path+variation)
+ return nil
+ } else {
+ results = append(results, resolveMetric(submetrics, parts[1], path+variation+"/")...)
+ }
}
- path += parts[0] + "/"
- parts = parts[1:]
+ return results
}
// Depending what the last link is, return or expand
- switch metric := metrics[parts[0]].(type) {
- case float64:
- // Final metric value found, return as singleton
- return []string{path + parts[0]}
+ for _, variation := range strings.Split(pattern, ",") {
+ switch metric := metrics[variation].(type) {
+ case float64:
+ // Final metric value found, return as singleton
+ results = append(results, path+variation)
- case map[string]interface{}:
- return expandMetrics(metric, path+parts[0]+"/")
+ case map[string]interface{}:
+ results = append(results, expandMetrics(metric, path+variation+"/")...)
- default:
- utils.Fatalf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric))
- return nil
+ default:
+ utils.Fatalf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric))
+ return nil
+ }
}
+ return results
}
// expandMetrics expands the entire tree of metrics into a flat list of paths.