diff --git a/internal/metricRouter/README.md b/internal/metricRouter/README.md index 9cd0d6c..b0318db 100644 --- a/internal/metricRouter/README.md +++ b/internal/metricRouter/README.md @@ -8,6 +8,7 @@ The CCMetric router sits in between the collectors and the sinks and can be used { "num_cache_intervals" : 1, "interval_timestamp" : true, + "normalize_units": true, "add_tags" : [ { "key" : "cluster", diff --git a/internal/metricRouter/metricRouter.go b/internal/metricRouter/metricRouter.go index 7ad1e7f..22d7d4d 100644 --- a/internal/metricRouter/metricRouter.go +++ b/internal/metricRouter/metricRouter.go @@ -12,6 +12,7 @@ import ( lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric" agg "github.com/ClusterCockpit/cc-metric-collector/internal/metricAggregator" mct "github.com/ClusterCockpit/cc-metric-collector/internal/multiChanTicker" + units "github.com/ClusterCockpit/cc-units" ) const ROUTER_MAX_FORWARD = 50 @@ -35,6 +36,7 @@ type metricRouterConfig struct { IntervalStamp bool `json:"interval_timestamp"` // Update timestamp periodically by ticker each interval? 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 + NormalizeUnits bool `json:"normalize_units"` // Check unit meta flag and normalize it using cc-units dropMetrics map[string]bool // Internal map for O(1) lookup } @@ -253,6 +255,14 @@ func (r *metricRouter) Start() { point.SetName(new) point.AddMeta("oldname", name) } + if r.config.NormalizeUnits { + if in_unit, ok := point.GetMeta("unit"); ok { + u := units.NewUnit(in_unit) + if u.Valid() { + point.AddMeta("unit", u.Short()) + } + } + } r.DoAddTags(point) r.DoDelTags(point)