Search in sources :

Example 21 with ServiceStat

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

the class GCPStatsService method storeAndSendStats.

/**
 * Stores the stats in current GCPStatsDataHolder instance and patches back the response
 * to the caller task.
 * @param statsData The GCPStatsDataHolder instance containing statsRequest.
 * @param metricInfo Metric name and unit pair from METRIC_NAMES_UNITS array.
 * @param response The response from the monitoring API associated with metric in
 * the current metricInfo pair.
 * @param nextStage The next stage of StatsCollectionStage for the service.
 */
private void storeAndSendStats(GCPStatsDataHolder statsData, String[] metricInfo, GCPMetricResponse response, StatsCollectionStage nextStage) {
    ServiceStat stat = new ServiceStat();
    List<ServiceStat> datapoint = new ArrayList<>();
    if (response.timeSeries != null) {
        TimeSeries ts = response.timeSeries[0];
        stat.latestValue = ts.points[0].value.int64Value == null ? Double.parseDouble(ts.points[0].value.doubleValue) : Double.parseDouble(ts.points[0].value.int64Value);
        stat.unit = GCPStatsNormalizer.getNormalizedUnitValue(metricInfo[1]);
        try {
            stat.sourceTimeMicrosUtc = getTimestampInMicros(ts.points[0].interval.startTime);
        } catch (ParseException e) {
            handleError(statsData, e);
            return;
        }
        datapoint = Collections.singletonList(stat);
    }
    statsData.statsResponse.statValues.put(GCPStatsNormalizer.getNormalizedStatKeyValue(metricInfo[0]), datapoint);
    // After all the metrics are collected, send them as a response to the caller task.
    if (statsData.numResponses.incrementAndGet() == METRIC_NAMES_UNITS.length) {
        SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
        statsData.statsResponse.computeLink = statsData.computeDesc.documentSelfLink;
        respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsData.statsRequest.nextStage);
        respBody.statsList = Collections.singletonList(statsData.statsResponse);
        setOperationDurationStat(statsData.gcpStatsCollectionOperation);
        statsData.gcpStatsCollectionOperation.complete();
        respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
        this.sendRequest(Operation.createPatch(statsData.statsRequest.taskReference).setBody(respBody));
    }
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) TimeSeries(com.vmware.photon.controller.model.adapters.gcp.podo.stats.TimeSeries) ArrayList(java.util.ArrayList) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ParseException(java.text.ParseException)

Example 22 with ServiceStat

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

the class DailyAggregator method createStat.

@Override
public ServiceStat createStat(PerfCounterInfo pc, List<PerfSampleInfo> infos, List<Long> values) {
    if (infos == null || infos.isEmpty()) {
        return null;
    }
    ServiceStat res = new ServiceStat();
    res.name = this.name;
    res.unit = this.unit;
    PerfSampleInfo info = null;
    double converted = 0;
    int intervalLengthMinutes = 5;
    res.timeSeriesStats = new TimeSeriesStats(24 * 60 / intervalLengthMinutes, intervalLengthMinutes * 60 * 1000, EnumSet.allOf(AggregationType.class));
    for (int i = 0; i < infos.size(); i++) {
        info = infos.get(i);
        Long value = values.get(i);
        converted = convertValue(value);
        res.timeSeriesStats.add(getSampleTimestampMicros(info), converted, converted);
    }
    res.sourceTimeMicrosUtc = res.lastUpdateMicrosUtc = getSampleTimestampMicros(info);
    res.latestValue = converted;
    return res;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) PerfSampleInfo(com.vmware.vim25.PerfSampleInfo) TimeSeriesStats(com.vmware.xenon.common.ServiceStats.TimeSeriesStats)

Example 23 with ServiceStat

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

the class AWSMockStatsService method populateSingleMockMetric.

/**
 * Gets mock EC2 statistics.
 *
 * @param metricName The metric names to gather stats for.
 * @param latestValue The stats value of the metricName.
 * @param unit The stats unit of the metricName.
 * @param statsMap The map of metric name to ServiceStat list.
 */
private static void populateSingleMockMetric(String metricName, double latestValue, String unit, Map<String, List<ServiceStat>> statsMap) {
    ServiceStat stat = new ServiceStat();
    stat.latestValue = latestValue;
    stat.unit = AWSStatsNormalizer.getNormalizedUnitValue(unit);
    List<ServiceStat> statDatapoints = new ArrayList<>();
    statDatapoints.add(stat);
    statsMap.put(metricName, statDatapoints);
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ArrayList(java.util.ArrayList)

Example 24 with ServiceStat

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

the class VSphereAdapterStatsService method collectStats.

private void collectStats(ProvisionContext ctx, ComputeStatsRequest statsRequest) {
    ctx.pool.submit(ctx.getAdapterManagementReference(), ctx.vSphereCredentials, (conn, ce) -> {
        if (ctx.fail(ce)) {
            return;
        }
        String type = CustomProperties.of(ctx.child).getString(CustomProperties.TYPE);
        if (type == null) {
            logInfo(() -> String.format("Missing type for %s, cannot retrieve stats", ctx.child.documentSelfLink));
            return;
        }
        StatsClient client;
        try {
            client = new StatsClient(conn);
        } catch (Exception e) {
            ctx.failWithMessage("Error connecting to PerformanceManager", e);
            return;
        }
        ManagedObjectReference obj = CustomProperties.of(ctx.child).getMoRef(CustomProperties.MOREF);
        List<ServiceStat> stats;
        try {
            stats = getStats(client, type, obj);
        } catch (Exception e) {
            ctx.failWithMessage("Error retrieving stats", e);
            return;
        }
        try {
            persistStats(stats, statsRequest);
        } catch (Exception e) {
            ctx.failWithMessage("Error persisting stats", e);
            return;
        }
    });
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 25 with ServiceStat

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

the class VSphereAdapterStatsService method persistStats.

private void persistStats(List<ServiceStat> stats, ComputeStatsRequest statsRequest) {
    ComputeStats cs = new ComputeStats();
    cs.computeLink = statsRequest.resourceReference.toString();
    cs.statValues = new HashMap<>();
    if (stats != null) {
        for (ServiceStat stat : stats) {
            cs.statValues.put(stat.name, Collections.singletonList(stat));
        }
    }
    SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
    respBody.statsList = new ArrayList<>();
    respBody.statsList.add(cs);
    respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
    respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
    // Verify if this makes sense? These tasks should always be local to deployment?
    this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(respBody));
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

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