use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType in project photon-model by vmware.
the class SingleResourceStatsAggregationTaskService method aggregateInMemoryMetrics.
private void aggregateInMemoryMetrics(SingleResourceStatsAggregationTaskState currentState, Map<String, SortedMap<Long, List<TimeBin>>> inMemoryStats) {
Map<String, Map<Long, TimeBin>> aggregatedTimeBinMap = currentState.aggregatedTimeBinMap;
for (Entry<String, SortedMap<Long, List<TimeBin>>> inMemoryStatEntry : inMemoryStats.entrySet()) {
String metricName = inMemoryStatEntry.getKey();
SortedMap<Long, List<TimeBin>> timeSeriesStats = inMemoryStatEntry.getValue();
if (aggregatedTimeBinMap == null) {
aggregatedTimeBinMap = new HashMap<>();
currentState.aggregatedTimeBinMap = aggregatedTimeBinMap;
}
Map<Long, TimeBin> timeBinMap = aggregatedTimeBinMap.get(metricName);
if (timeBinMap == null) {
timeBinMap = new HashMap<>();
aggregatedTimeBinMap.put(metricName, timeBinMap);
}
Set<AggregationType> aggregationTypes;
for (Entry<Long, List<TimeBin>> bins : timeSeriesStats.entrySet()) {
Long binId = bins.getKey();
TimeBin bin = timeBinMap.get(binId);
if (bin == null) {
bin = new TimeBin();
}
// Figure out the aggregation for the given metric
aggregationTypes = currentState.aggregations.get(stripRollupKey(metricName));
if (aggregationTypes == null) {
aggregationTypes = EnumSet.allOf(AggregationType.class);
}
for (TimeBin timeBin : bins.getValue()) {
updateBin(bin, timeBin, aggregationTypes);
}
timeBinMap.put(binId, bin);
}
}
}
use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType in project photon-model by vmware.
the class SingleResourceStatsAggregationTaskService method aggregateRawMetrics.
private void aggregateRawMetrics(SingleResourceStatsAggregationTaskState currentState, Map<String, List<ResourceMetrics>> rawMetricsForKey) {
Map<String, Map<Long, TimeBin>> aggregatedTimeBinMap = currentState.aggregatedTimeBinMap;
// comparator used to sort resource metric PODOs based on document timestamp
Comparator<ResourceMetrics> comparator = (o1, o2) -> {
if (o1.timestampMicrosUtc < o2.timestampMicrosUtc) {
return -1;
} else if (o1.timestampMicrosUtc > o2.timestampMicrosUtc) {
return 1;
}
return 0;
};
for (Entry<String, List<ResourceMetrics>> rawMetricListEntry : rawMetricsForKey.entrySet()) {
List<ResourceMetrics> rawMetricList = rawMetricListEntry.getValue();
if (rawMetricList.isEmpty()) {
continue;
}
String metricKeyWithRpllupSuffix = rawMetricListEntry.getKey();
rawMetricList.sort(comparator);
if (aggregatedTimeBinMap == null) {
aggregatedTimeBinMap = new HashMap<>();
currentState.aggregatedTimeBinMap = aggregatedTimeBinMap;
}
Map<Long, TimeBin> timeBinMap = aggregatedTimeBinMap.get(metricKeyWithRpllupSuffix);
if (timeBinMap == null) {
timeBinMap = new HashMap<>();
aggregatedTimeBinMap.put(metricKeyWithRpllupSuffix, timeBinMap);
}
String rawMetricKey = stripRollupKey(metricKeyWithRpllupSuffix);
Collection<ResourceMetrics> metrics = rawMetricList;
if (currentState.latestValueOnly.contains(rawMetricKey)) {
metrics = getLatestMetrics(rawMetricList, metricKeyWithRpllupSuffix);
}
Set<AggregationType> aggregationTypes;
// iterate over the raw metric values and place it in the right time bin
for (ResourceMetrics metric : metrics) {
Double value = metric.entries.get(rawMetricKey);
if (value == null) {
continue;
}
// TODO VSYM-3190 - Change normalized interval boundary to beginning of the rollup period
long binId = StatsUtil.computeIntervalEndMicros(metric.timestampMicrosUtc, lookupBinSize(metricKeyWithRpllupSuffix));
TimeBin bin = timeBinMap.get(binId);
if (bin == null) {
bin = new TimeBin();
}
// Figure out the aggregation for the given metric
aggregationTypes = currentState.aggregations.get(rawMetricKey);
if (aggregationTypes == null) {
aggregationTypes = EnumSet.allOf(AggregationType.class);
}
updateBin(bin, value, aggregationTypes);
timeBinMap.put(binId, bin);
}
}
}
Aggregations