in validator/validators/performance/performance_validator.go [147:185]
func (s *PerformanceValidator) CalculateWindowsMetricStatsAndPackMetrics(statistic []*cloudwatch.GetMetricStatisticsOutput) (PerformanceInformation, error) {
var (
receiver = s.vConfig.GetPluginsConfig()[0] //Assuming one plugin at a time
commitHash, commitDate = s.vConfig.GetCommitInformation()
dataType = s.vConfig.GetDataType()
dataRate = fmt.Sprint(s.vConfig.GetDataRate())
uniqueID = s.vConfig.GetUniqueID()
agentCollectionPeriod = s.vConfig.GetAgentCollectionPeriod().Seconds()
)
performanceMetricResults := make(map[string]Stats)
for _, metric := range statistic {
metricLabel := strings.Split(*metric.Label, " ")
metricName := metricLabel[len(metricLabel)-1]
metricValues := metric.Datapoints
//Convert every bytes to MB
if slices.Contains(metricsConvertToMB, metricName) {
for i, val := range metricValues {
*metricValues[i].Average = *val.Average / (1024 * 1024)
}
}
log.Printf("Start calculate metric statictics for metric %s \n", metricName)
if !isAllStatisticsGreaterThanOrEqualToZero(metricValues) {
return nil, fmt.Errorf("\n values are not all greater than or equal to zero for metric %s with values: %v", metricName, metricValues)
}
// GetMetricStatistics provides these statistics, however this will require maintaining multiple data arrays
// and can be difficult for code readability. This way follows the same calculation pattern as Linux
// and simplify the logics.
var data []float64
for _, datapoint := range metric.Datapoints {
data = append(data, *datapoint.Average)
}
metricStats := CalculateMetricStatisticsBasedOnDataAndPeriod(data, agentCollectionPeriod)
log.Printf("Finished calculate metric statictics for metric %s: %+v \n", metricName, metricStats)
performanceMetricResults[metricName] = metricStats
}
return packIntoPerformanceInformation(uniqueID, receiver, dataType, fmt.Sprint(agentCollectionPeriod), commitHash, commitDate, map[string]interface{}{dataRate: performanceMetricResults}), nil
}