Search in sources :

Example 36 with ServiceStat

use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.

the class AzureCostHelper method createBillProcessedTimeStat.

static ComputeStats createBillProcessedTimeStat(ComputeStateWithDescription computeHostDesc, long billProcessedTimeMillis) {
    // Create bill processed time stat: will be linked with the EA account's compute state
    // since the bill is obtained and processed at the EA account level.
    ComputeStats accountStats = new ComputeStats();
    accountStats.computeLink = computeHostDesc.documentSelfLink;
    accountStats.statValues = new ConcurrentSkipListMap<>();
    accountStats.addCustomProperty(PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
    ServiceStat billProcessedTimeStat = AzureCostHelper.createServiceStat(PhotonModelConstants.CLOUD_ACCOUNT_COST_SYNC_MARKER_MILLIS, billProcessedTimeMillis, PhotonModelConstants.UNIT_MILLISECONDS, billProcessedTimeMillis);
    accountStats.statValues.put(billProcessedTimeStat.name, Collections.singletonList(billProcessedTimeStat));
    return accountStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 37 with ServiceStat

use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.

the class SingleResourceStatsCollectionTaskService method updateAndPersistStats.

private void updateAndPersistStats(SingleResourceStatsCollectionTaskState currentState) {
    if (currentState.statsAdapterReference == null) {
        throw new IllegalStateException("stats adapter reference should not be null");
    }
    if (currentState.statsList.size() == 0) {
        // If there are no stats reported and if it's a final batch, just finish the task.
        if (currentState.isFinalBatch) {
            SingleResourceStatsCollectionTaskState nextStatePatch = new SingleResourceStatsCollectionTaskState();
            nextStatePatch.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
            TaskUtils.sendPatch(this, nextStatePatch);
        }
        return;
    }
    long expirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(EXPIRATION_INTERVAL);
    List<Operation> operations = new ArrayList<>();
    List<ResourceMetrics> metricsList = new ArrayList<>();
    List<InMemoryResourceMetric> inMemoryMetricsList = new ArrayList<>();
    // Push the last collection metric to the in memory stats available at the
    // compute-link/stats URI.
    ServiceStats.ServiceStat minuteStats = new ServiceStats.ServiceStat();
    String statsLink = getAdapterLinkFromURI(currentState.statsAdapterReference);
    minuteStats.name = getLastCollectionMetricKeyForAdapterLink(statsLink, true);
    minuteStats.latestValue = Utils.getNowMicrosUtc();
    minuteStats.sourceTimeMicrosUtc = Utils.getNowMicrosUtc();
    minuteStats.unit = PhotonModelConstants.UNIT_MICROSECONDS;
    URI inMemoryStatsUri = UriUtils.buildStatsUri(UriUtils.extendUri(UriUtils.buildUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE)), currentState.computeLink));
    operations.add(Operation.createPost(inMemoryStatsUri).setBody(minuteStats));
    populateResourceMetrics(metricsList, getLastCollectionMetricKeyForAdapterLink(statsLink, false), minuteStats, currentState.computeLink, expirationTime, null);
    for (ComputeStats stats : currentState.statsList) {
        // TODO: https://jira-hzn.eng.vmware.com/browse/VSYM-330
        InMemoryResourceMetric hourlyMemoryState = new InMemoryResourceMetric();
        if (currentState.publishInMemory) {
            String computeId = UriUtils.getLastPathSegment(stats.computeLink);
            hourlyMemoryState.timeSeriesStats = new HashMap<>();
            hourlyMemoryState.documentSelfLink = computeId + StatsConstants.HOUR_SUFFIX;
            inMemoryMetricsList.add(hourlyMemoryState);
        }
        for (Entry<String, List<ServiceStat>> entries : stats.statValues.entrySet()) {
            // sort stats by source time
            entries.getValue().sort(Comparator.comparing(o -> o.sourceTimeMicrosUtc));
            // Persist every data point
            for (ServiceStat serviceStat : entries.getValue()) {
                String computeLink = stats.computeLink;
                if (computeLink == null) {
                    computeLink = currentState.computeLink;
                }
                if (currentState.publishInMemory) {
                    // update in-memory stats
                    updateInMemoryStats(hourlyMemoryState, entries.getKey(), serviceStat, StatsConstants.BUCKET_SIZE_HOURS_IN_MILLIS);
                }
                populateResourceMetrics(metricsList, entries.getKey(), serviceStat, computeLink, expirationTime, stats.getCustomProperties());
            }
        }
    }
    for (ResourceMetrics metrics : metricsList) {
        operations.add(Operation.createPost(UriUtils.buildUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.METRIC_SERVICE), ResourceMetricsService.FACTORY_LINK)).setBodyNoCloning(metrics));
    }
    if (currentState.publishInMemory) {
        for (InMemoryResourceMetric metric : inMemoryMetricsList) {
            operations.add(Operation.createPost(getHost(), InMemoryResourceMetricService.FACTORY_LINK).setBodyNoCloning(metric));
        }
    }
    // Save each data point sequentially to create time based monotonically increasing sequence.
    batchPersistStats(operations, 0, currentState.isFinalBatch);
}
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) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) URI(java.net.URI) EnumSet(java.util.EnumSet) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) 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) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) FactoryService(com.vmware.xenon.common.FactoryService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) TaskService(com.vmware.xenon.services.common.TaskService) 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) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) 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) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) InMemoryResourceMetricService(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) InMemoryResourceMetric(com.vmware.photon.controller.model.monitoring.InMemoryResourceMetricService.InMemoryResourceMetric) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ServiceStats(com.vmware.xenon.common.ServiceStats) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)37 ArrayList (java.util.ArrayList)21 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)16 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)15 List (java.util.List)11 Map (java.util.Map)11 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)10 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 Operation (com.vmware.xenon.common.Operation)9 QueryTask (com.vmware.xenon.services.common.QueryTask)9 HashMap (java.util.HashMap)9 ServiceStats (com.vmware.xenon.common.ServiceStats)8 UriUtils (com.vmware.xenon.common.UriUtils)8 URI (java.net.URI)8 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)7 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)7 ServiceDocument (com.vmware.xenon.common.ServiceDocument)7 StatelessService (com.vmware.xenon.common.StatelessService)7 Utils (com.vmware.xenon.common.Utils)7