func()

in validator/validators/performance/performance_validator.go [114:145]


func (s *PerformanceValidator) CalculateMetricStatsAndPackMetrics(metrics []types.MetricDataResult) (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 metrics {
		metricLabel := strings.Split(*metric.Label, " ")
		metricName := metricLabel[len(metricLabel)-1]
		metricValues := metric.Values
		//Convert every bytes to MB
		if slices.Contains(metricsConvertToMB, metricName) {
			for i, val := range metricValues {
				metricValues[i] = val / (1024 * 1024)
			}
		}
		log.Printf("Start calculate metric statictics for metric %s %v \n", metricName, metricValues)
		if !isAllValuesGreaterThanOrEqualToZero(metricValues) {
			return nil, fmt.Errorf("\n values are not all greater than or equal to zero for metric %s with values: %v", metricName, metricValues)
		}
		metricStats := CalculateMetricStatisticsBasedOnDataAndPeriod(metricValues, 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
}