/
metric_validation_util.go
43 lines (37 loc) · 1.79 KB
/
metric_validation_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package metric
import "log"
var CpuMetrics = []string{"cpu_time_active", "cpu_time_guest", "cpu_time_guest_nice", "cpu_time_idle", "cpu_time_iowait", "cpu_time_irq",
"cpu_time_nice", "cpu_time_softirq", "cpu_time_steal", "cpu_time_system", "cpu_time_user",
"cpu_usage_active", "cpu_usage_guest", "cpu_usage_guest_nice", "cpu_usage_idle", "cpu_usage_iowait",
"cpu_usage_irq", "cpu_usage_nice", "cpu_usage_softirq", "cpu_usage_steal", "cpu_usage_system", "cpu_usage_user"}
// IsAllValuesGreaterThanOrEqualToExpectedValue will compare if the given array is larger than 0
// and check if the average value for the array is not la
// https://github.com/aws/amazon-cloudwatch-agent-test/pull/162
func IsAllValuesGreaterThanOrEqualToExpectedValue(metricName string, values []float64, expectedValue float64) bool {
if len(values) == 0 {
log.Printf("No values found %v", metricName)
return false
}
totalSum := 0.0
for _, value := range values {
if value < 0 {
log.Printf("Values are not all greater than or equal to zero for %s", metricName)
return false
}
totalSum += value
}
metricErrorBound := 0.1
metricAverageValue := totalSum / float64(len(values))
upperBoundValue := expectedValue * (1 + metricErrorBound)
lowerBoundValue := expectedValue * (1 - metricErrorBound)
if expectedValue > 0 && (metricAverageValue > upperBoundValue || metricAverageValue < lowerBoundValue) {
log.Printf("The average value %f for metric %s are not within bound [%f, %f]",
metricAverageValue, metricName, lowerBoundValue, upperBoundValue)
return false
}
log.Printf("The average value %f for metric %s are within bound [%f, %f]",
metricAverageValue, metricName, lowerBoundValue, upperBoundValue)
return true
}