mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-08 14:35:55 +02:00
Add unit conversion to router
This commit is contained in:
parent
3b962cd0d6
commit
28764f2c7e
@ -37,6 +37,7 @@ type metricRouterConfig struct {
|
|||||||
NumCacheIntervals int `json:"num_cache_intervals"` // Number of intervals of cached metrics for evaluation
|
NumCacheIntervals int `json:"num_cache_intervals"` // Number of intervals of cached metrics for evaluation
|
||||||
MaxForward int `json:"max_forward"` // Number of maximal forwarded metrics at one select
|
MaxForward int `json:"max_forward"` // Number of maximal forwarded metrics at one select
|
||||||
NormalizeUnits bool `json:"normalize_units"` // Check unit meta flag and normalize it using cc-units
|
NormalizeUnits bool `json:"normalize_units"` // Check unit meta flag and normalize it using cc-units
|
||||||
|
ChangeUnitPrefix string `json:"change_unit_prefix"` // Add prefix that should be applied to all metrics where possible
|
||||||
dropMetrics map[string]bool // Internal map for O(1) lookup
|
dropMetrics map[string]bool // Internal map for O(1) lookup
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,6 +264,55 @@ func (r *metricRouter) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(r.config.ChangeUnitPrefix) > 0 {
|
||||||
|
prefix := units.NewPrefix(r.config.ChangeUnitPrefix)
|
||||||
|
if prefix != units.InvalidPrefix {
|
||||||
|
if in_unit, ok := point.GetMeta("unit"); ok {
|
||||||
|
u := units.NewUnit(in_unit)
|
||||||
|
if u.Valid() {
|
||||||
|
conv, out_unit := units.GetUnitPrefixFactor(u, prefix)
|
||||||
|
if conv != nil && out_unit.Valid() {
|
||||||
|
if val, ok := point.GetField("value"); ok {
|
||||||
|
newval := 0.0
|
||||||
|
skip := false
|
||||||
|
switch v := val.(type) {
|
||||||
|
case float64:
|
||||||
|
newval = v
|
||||||
|
case float32:
|
||||||
|
newval = float64(v)
|
||||||
|
case int64:
|
||||||
|
newval = float64(v)
|
||||||
|
case int32:
|
||||||
|
newval = float64(v)
|
||||||
|
case int:
|
||||||
|
newval = float64(v)
|
||||||
|
case string:
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
if !skip {
|
||||||
|
newval = conv(newval)
|
||||||
|
var x interface{}
|
||||||
|
switch val.(type) {
|
||||||
|
case float64:
|
||||||
|
x = newval
|
||||||
|
case float32:
|
||||||
|
x = float32(newval)
|
||||||
|
case int64:
|
||||||
|
x = int64(newval)
|
||||||
|
case int32:
|
||||||
|
x = int32(newval)
|
||||||
|
case int:
|
||||||
|
x = int(newval)
|
||||||
|
}
|
||||||
|
point.AddField("value", x)
|
||||||
|
point.AddMeta("unit", out_unit.Short())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
r.DoAddTags(point)
|
r.DoAddTags(point)
|
||||||
r.DoDelTags(point)
|
r.DoDelTags(point)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user