Search in sources :

Example 1 with AggregationType

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);
        }
    }
}
Also used : AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) SortedMap(java.util.SortedMap) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) TimeBin(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.TimeBin)

Example 2 with AggregationType

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);
        }
    }
}
Also used : Service(com.vmware.xenon.common.Service) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) URI(java.net.URI) Builder(com.vmware.xenon.services.common.QueryTask.Builder) EnumSet(java.util.EnumSet) Collection(java.util.Collection) Set(java.util.Set) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) ServiceStats(com.vmware.xenon.common.ServiceStats) List(java.util.List) TimeSeriesStats(com.vmware.xenon.common.ServiceStats.TimeSeriesStats) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) FactoryService(com.vmware.xenon.common.FactoryService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) TaskService(com.vmware.xenon.services.common.TaskService) SortedMap(java.util.SortedMap) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) TaskUtils(com.vmware.photon.controller.model.tasks.TaskUtils) InMemoryResourceMetric(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric) HashMap(java.util.HashMap) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) HashSet(java.util.HashSet) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) TimeBin(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.TimeBin) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) TreeMap(java.util.TreeMap) InMemoryResourceMetricService(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AggregationType(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) TimeBin(com.vmware.xenon.common.ServiceStats.TimeSeriesStats.TimeBin)

Aggregations

AggregationType (com.vmware.xenon.common.ServiceStats.TimeSeriesStats.AggregationType)2 TimeBin (com.vmware.xenon.common.ServiceStats.TimeSeriesStats.TimeBin)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 UriPaths (com.vmware.photon.controller.model.UriPaths)1 InMemoryResourceMetricService (com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService)1 InMemoryResourceMetric (com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric)1 ResourceMetricsService (com.vmware.photon.controller.model.monitoring.ResourceMetricsService)1 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 PhotonModelUtils (com.vmware.photon.controller.model.resources.util.PhotonModelUtils)1 TaskUtils (com.vmware.photon.controller.model.tasks.TaskUtils)1 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)1 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 FactoryService (com.vmware.xenon.common.FactoryService)1