LikwidCollector: Filter out NaNs or set them to zero if 'nan_to_zero' option is set

This commit is contained in:
Thomas Roehl
2022-02-07 18:35:08 +01:00
parent 7182b339b9
commit a6bec61b1e
2 changed files with 17 additions and 5 deletions

View File

@@ -86,9 +86,9 @@ type LikwidCollectorEventsetConfig struct {
type LikwidCollectorConfig struct {
Eventsets []LikwidCollectorEventsetConfig `json:"eventsets"`
Metrics []LikwidCollectorMetricConfig `json:"globalmetrics"`
ExcludeMetrics []string `json:"exclude_metrics"`
ForceOverwrite bool `json:"force_overwrite"`
Metrics []LikwidCollectorMetricConfig `json:"globalmetrics,omitempty"`
ForceOverwrite bool `json:"force_overwrite,omitempty"`
NanToZero bool `json:"nan_to_zero,omitempty"`
}
type LikwidCollector struct {
@@ -434,8 +434,11 @@ func (m *LikwidCollector) calcEventsetMetrics(group int, interval time.Duration,
continue
}
m.mresults[group][tid][metric.Name] = value
if m.config.NanToZero && math.IsNaN(value) {
value = 0.0
}
// Now we have the result, send it with the proper tags
if metric.Publish {
if metric.Publish && !math.IsNaN(value) {
tags := map[string]string{"type": metric.Scope.String()}
if metric.Scope != "node" {
tags["type-id"] = fmt.Sprintf("%d", domain)
@@ -473,8 +476,11 @@ func (m *LikwidCollector) calcGlobalMetrics(interval time.Duration, output chan
continue
}
m.gmresults[tid][metric.Name] = value
if m.config.NanToZero && math.IsNaN(value) {
value = 0.0
}
// Now we have the result, send it with the proper tags
if metric.Publish {
if metric.Publish && !math.IsNaN(value) {
tags := map[string]string{"type": metric.Scope.String()}
if metric.Scope != "node" {
tags["type-id"] = fmt.Sprintf("%d", domain)