use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats in project photon-model by vmware.
the class InMemoryResourceMetricServiceTest method buildValidStartState.
private static InMemoryResourceMetricService.InMemoryResourceMetric buildValidStartState() {
InMemoryResourceMetricService.InMemoryResourceMetric statState = new InMemoryResourceMetricService.InMemoryResourceMetric();
statState.timeSeriesStats = new HashMap<>();
TimeSeriesStats statsEntry = new TimeSeriesStats(2, HOUR_IN_MILLIS, EnumSet.of(AggregationType.AVG));
statsEntry.add(Utils.getNowMicrosUtc(), 1, 1);
statState.timeSeriesStats.put("key1", statsEntry);
return statState;
}
use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats in project photon-model by vmware.
the class InMemoryResourceMetricService method handlePut.
@Override
public void handlePut(Operation put) {
if (!put.hasBody()) {
put.fail(new IllegalArgumentException("body is required"));
}
try {
InMemoryResourceMetric currentState = getState(put);
InMemoryResourceMetric updatedState = getBody(put);
// merge the state
for (Entry<String, TimeSeriesStats> tsStats : updatedState.timeSeriesStats.entrySet()) {
TimeSeriesStats currentStats = currentState.timeSeriesStats.get(tsStats.getKey());
if (currentStats == null) {
currentState.timeSeriesStats.put(tsStats.getKey(), tsStats.getValue());
} else {
for (Entry<Long, TimeBin> bin : tsStats.getValue().bins.entrySet()) {
for (int i = 0; i < bin.getValue().count; i++) {
currentStats.add(TimeUnit.MILLISECONDS.toMicros(bin.getKey()), bin.getValue().avg, bin.getValue().avg);
}
}
}
}
setState(put, currentState);
put.setBody(currentState).complete();
} catch (Throwable t) {
put.fail(t);
}
}
use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats in project photon-model by vmware.
the class SingleResourceStatsAggregationTaskService method processInMemoryMetrics.
/**
* Process in-memory metrics.
*/
private void processInMemoryMetrics(SingleResourceStatsAggregationTaskState currentState, Map<String, Set<String>> metricsToBeQueried, Map<String, SortedMap<Long, List<TimeBin>>> inMemoryStats, InMemoryResourceMetric metric) {
String metricKey = UriUtils.getLastPathSegment(metric.documentSelfLink);
String resourceId = stripRollupKey(metricKey);
for (Entry<String, Long> metricEntry : currentState.lastRollupTimeForMetric.entrySet()) {
String rawMetricKey = stripRollupKey(metricEntry.getKey());
TimeSeriesStats timeSeriesStats = metric.timeSeriesStats.get(rawMetricKey);
// raw metrics; move on to the next metric
if (timeSeriesStats == null) {
continue;
}
// TODO VSYM-3190 - Change normalized interval boundary to beginning of the rollup period
// Currently, xenon's time interval boundary 1 hour before than photon
// model's aggregate metrics.
Long earliestBinId = TimeUnit.MILLISECONDS.toMicros(timeSeriesStats.bins.firstKey());
earliestBinId += TimeUnit.MILLISECONDS.toMicros(timeSeriesStats.binDurationMillis);
Long lastRollupTime = metricEntry.getValue();
// have in memory.
if (lastRollupTime == null || lastRollupTime < earliestBinId) {
Set<String> metricList = metricsToBeQueried.get(resourceId);
if (metricList == null) {
metricList = new HashSet<>();
metricsToBeQueried.put(resourceId, metricList);
}
metricList.add(rawMetricKey);
continue;
}
processInMemoryTimeBins(currentState, inMemoryStats, metricEntry, timeSeriesStats);
}
}
use of com.vmware.xenon.common.ServiceStats.TimeSeriesStats 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.TimeSeriesStats in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method updateInMemoryStats.
private void updateInMemoryStats(InMemoryResourceMetric inMemoryMetric, String metricKey, ServiceStat serviceStat, int bucketSize) {
// update in-memory stats
if (inMemoryMetric.timeSeriesStats.containsKey(metricKey)) {
inMemoryMetric.timeSeriesStats.get(metricKey).add(serviceStat.sourceTimeMicrosUtc, serviceStat.latestValue, serviceStat.latestValue);
} else {
TimeSeriesStats tStats = new TimeSeriesStats(2, bucketSize, EnumSet.allOf(AggregationType.class));
tStats.add(serviceStat.sourceTimeMicrosUtc, serviceStat.latestValue, serviceStat.latestValue);
inMemoryMetric.timeSeriesStats.put(metricKey, tStats);
}
}
Aggregations