forked from cerc-io/plugeth
cmd/geth: allow branching metric patterns
This commit is contained in:
parent
bf99d5b33c
commit
302187ae39
@ -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] + "/"
|
}
|
||||||
parts = parts[1:]
|
return results
|
||||||
}
|
}
|
||||||
// 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, ",") {
|
||||||
|
switch metric := metrics[variation].(type) {
|
||||||
case float64:
|
case float64:
|
||||||
// Final metric value found, return as singleton
|
// Final metric value found, return as singleton
|
||||||
return []string{path + parts[0]}
|
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…
Reference in New Issue
Block a user