use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.
the class LongRunEndToEndStatsAggregationTest method checkInMemoryStatsPresent.
/**
* Perform check to verify that every compute resource has stats generated for all the metric
* keys using which stats aggregation was performed on resources.
*/
private void checkInMemoryStatsPresent(ServiceDocumentQueryResult res) {
for (Map.Entry<String, Object> resourceMap : res.documents.entrySet()) {
ServiceStats resStats = this.host.getServiceState(null, ServiceStats.class, UriUtils.buildStatsUri(createServiceURI(host, null, resourceMap.getKey())));
int statCount = 0;
for (ServiceStat stat : resStats.entries.values()) {
for (String key : TestAWSSetupUtils.getMetricNames()) {
if (stat.name.startsWith(key)) {
statCount++;
break;
}
}
}
// after stats aggregation all resources should have all metrics.
assertEquals("Did not find in-memory stats", TestAWSSetupUtils.getMetricNames().size(), statCount);
}
}
use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.
the class TestAWSProvisionTask method verifyCollectedStats.
private void verifyCollectedStats(ComputeStatsResponse response, Long lastCollectionTime) {
ComputeStats computeStats = response.statsList.get(0);
assertTrue("Compute Link is empty", !computeStats.computeLink.isEmpty());
// Check that stat values are accompanied with Units.
for (String key : computeStats.statValues.keySet()) {
List<ServiceStat> stats = computeStats.statValues.get(key);
for (ServiceStat stat : stats) {
assertTrue("Unit is empty", !stat.unit.isEmpty());
// Check if burn rate values are positive.
if (key.equalsIgnoreCase(PhotonModelConstants.AVERAGE_BURN_RATE_PER_HOUR)) {
assertTrue("Average burn rate is negative", stat.latestValue >= 0);
}
if (key.equalsIgnoreCase(PhotonModelConstants.CURRENT_BURN_RATE_PER_HOUR)) {
assertTrue("Current burn rate is negative", stat.latestValue >= 0);
}
}
// from the provider.
if (lastCollectionTime != null && key.equalsIgnoreCase(PhotonModelConstants.CPU_UTILIZATION_PERCENT)) {
assertTrue("incorrect number of data points received when collection window is specified for metric ." + key, stats.size() > 1);
}
// Check if the datapoints collected are after the lastCollectionTime.
if (lastCollectionTime != null && key.equalsIgnoreCase(PhotonModelConstants.ESTIMATED_CHARGES)) {
for (ServiceStat stat : stats) {
assertTrue("The datapoint collected is older than last collection time.", stat.sourceTimeMicrosUtc >= lastCollectionTime);
}
}
}
}
use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.
the class TestAWSCostAdapterService method verifyCollectedStats.
private void verifyCollectedStats(List<ComputeStats> statsList) {
Map<String, ComputeStats> computeStatsByLink = statsList.stream().collect(Collectors.toMap(e -> e.computeLink, Function.identity(), (allStats, stats) -> {
allStats.statValues.putAll(stats.statValues);
return allStats;
}));
ComputeStats account1Stats = computeStatsByLink.get(account1SelfLink);
ComputeStats account2Stats = computeStatsByLink.get(account2SelfLink);
String normalizedStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST);
// verify account costs
assertTrue(account1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account1TotalCost);
assertTrue(account2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account2TotalCost);
// check that service level stats exist
String serviceCode = AwsServices.EC2_Instance_Usage.getName().replaceAll(" ", "");
String serviceResourceCostMetric = String.format(AWSConstants.SERVICE_RESOURCE_COST, serviceCode);
assertTrue(!account1Stats.statValues.get(serviceResourceCostMetric).isEmpty());
String serviceCode2 = AwsServices.EC2_Others.getName().replaceAll(" ", "");
String serviceOtherCostMetric = String.format(AWSConstants.SERVICE_OTHER_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceOtherCostMetric).isEmpty());
String serviceMonthlyOtherCostMetric = String.format(AWSConstants.SERVICE_MONTHLY_OTHER_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceMonthlyOtherCostMetric).isEmpty());
String serviceReservedRecurringCostMetric = String.format(AWSConstants.SERVICE_RESERVED_RECURRING_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceReservedRecurringCostMetric).isEmpty());
ComputeStats instance1Stats = computeStatsByLink.get(INSTANCE_1_SELF_LINK);
ComputeStats instance2Stats = computeStatsByLink.get(INSTANCE_2_SELF_LINK);
assertEquals(instance1TotalCost, instance1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
assertEquals(instance2TotalCost, instance2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
String normalizedReservedInstanceStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.RESERVED_INSTANCE_DURATION);
assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
// Check that stat values are accompanied with Units.
for (String key : account1Stats.statValues.keySet()) {
List<ServiceStat> stats = account1Stats.statValues.get(key);
for (ServiceStat stat : stats) {
assertTrue("Unit is empty", !stat.unit.isEmpty());
}
}
}
use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.
the class AzureComputeHostStatsGatherer method aggregateComputeStatsResponses.
/**
* Aggregates stats from all the compute VMs to make up compute Host stats.
*/
private ComputeStats aggregateComputeStatsResponses(AzureStatsDataHolder statsData, List<QueryTask> items) {
int numberOfComputeResponse = items.size();
ComputeStats computeStats = new ComputeStats();
computeStats.computeLink = statsData.computeHost.documentSelfLink;
Map<String, ServiceStat> statMap = new HashMap<>();
// Gather all the stats in a single response.
for (QueryTask queryResult : items) {
if (queryResult.results.documents != null) {
for (String key : queryResult.results.documents.keySet()) {
ResourceMetrics metric = Utils.fromJson(queryResult.results.documents.get(key), ResourceMetrics.class);
for (Map.Entry<String, Double> entry : metric.entries.entrySet()) {
String metricName = entry.getKey();
if (statMap.containsKey(metricName)) {
statMap.get(metricName).latestValue += entry.getValue();
} else {
ServiceStat stat = new ServiceStat();
stat.latestValue = entry.getValue();
statMap.put(metricName, stat);
}
}
}
}
}
computeStats.statValues = new ConcurrentSkipListMap<>();
// Divide each metric value by the number of computes to get an average value.
for (String key : statMap.keySet()) {
ServiceStat serviceStatValue = statMap.get(key);
serviceStatValue.unit = PhotonModelConstants.getUnitForMetric(key);
serviceStatValue.sourceTimeMicrosUtc = Utils.getNowMicrosUtc();
serviceStatValue.latestValue = serviceStatValue.latestValue / numberOfComputeResponse;
computeStats.statValues.put(key, Collections.singletonList(serviceStatValue));
}
return computeStats;
}
use of com.vmware.xenon.common.ServiceStats.ServiceStat in project photon-model by vmware.
the class AzureCostStatsService method createAzureSubscriptionStats.
// Create Azure account stats
private void createAzureSubscriptionStats(Context context, AzureSubscription subscription) {
// convert the subscription daily costs to cumulative
AtomicDouble cumulativeValue = new AtomicDouble(0.0);
subscription.cost = subscription.cost.entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).collect(Collectors.toMap(Entry::getKey, e -> cumulativeValue.addAndGet(e.getValue())));
Consumer<List<ComputeState>> subscriptionStatsProcessor = (subscriptionComputeStates) -> subscriptionComputeStates.forEach(subscriptionComputeState -> {
String statName = AzureStatsNormalizer.getNormalizedStatKeyValue(AzureCostConstants.COST);
String costUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
ComputeStats subscriptionStats = new ComputeStats();
subscriptionStats.computeLink = subscriptionComputeState.documentSelfLink;
subscriptionStats.statValues = new ConcurrentSkipListMap<>();
List<ServiceStat> costStats = new ArrayList<>();
for (Entry<Long, Double> cost : subscription.cost.entrySet()) {
ServiceStat azureAccountStat = AzureCostHelper.createServiceStat(statName, cost.getValue(), costUnit, cost.getKey());
costStats.add(azureAccountStat);
}
subscriptionStats.statValues.put(statName, costStats);
context.statsResponse.statsList.add(subscriptionStats);
});
processSubscriptionStats(context, subscription, subscriptionStatsProcessor);
}
Aggregations