cmd/geth: allow branching metric patterns

release/0.9.36
Péter Szilágyi 10 years ago
parent bf99d5b33c
commit 302187ae39
  1. 43
      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 // resolveMetrics takes a single of input metric pattern, and resolves it to one
// or more canonical metric names. // or more canonical metric names.
func resolveMetric(metrics map[string]interface{}, pattern string, path string) []string { func resolveMetric(metrics map[string]interface{}, pattern string, path string) []string {
var ok bool results := []string{}
// Build up the canonical metric path // If a nested metric was requested, recurse optionally branching (via comma)
parts := strings.Split(pattern, "/") parts := strings.SplitN(pattern, "/", 2)
for len(parts) > 1 { if len(parts) > 1 {
if metrics, ok = metrics[parts[0]].(map[string]interface{}); !ok { for _, variation := range strings.Split(parts[0], ",") {
utils.Fatalf("Failed to retrieve system metrics: %s", path+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] + "/" return results
parts = parts[1:]
} }
// Depending what the last link is, return or expand // Depending what the last link is, return or expand
switch metric := metrics[parts[0]].(type) { for _, variation := range strings.Split(pattern, ",") {
case float64: switch metric := metrics[variation].(type) {
// Final metric value found, return as singleton case float64:
return []string{path + parts[0]} // Final metric value found, return as singleton
results = append(results, path+variation)
case map[string]interface{}: case map[string]interface{}:
return expandMetrics(metric, path+parts[0]+"/") results = append(results, expandMetrics(metric, path+variation+"/")...)
default: default:
utils.Fatalf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric)) utils.Fatalf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric))
return nil return nil
}
} }
return results
} }
// expandMetrics expands the entire tree of metrics into a flat list of paths. // expandMetrics expands the entire tree of metrics into a flat list of paths.

Loading…
Cancel
Save