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));
}
}
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;
}
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);
}
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;
}
});
}
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));
}
Aggregations