use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostStatsService method createStatsForAzureResources.
private void createStatsForAzureResources(Context context, AzureService service, List<ComputeStats> resourceCostStats) {
// Now creating cost stats for VMs only
if (service.meterCategory.equals(AzureCostConstants.METER_CATEGORY_VIRTUAL_MACHINES)) {
// Check if there are resources under this subscription
Map<String, List<String>> instanceIdToComputeLinks = context.subscriptionGuidToResources.getOrDefault(service.getSubscriptionId(), new ConcurrentHashMap<>());
// Create compute stats for resources present
service.resourceDetailsMap.keySet().forEach(instanceId -> {
List<String> computeLinks = instanceIdToComputeLinks.getOrDefault(instanceId.toLowerCase(), new ArrayList<>());
AzureResource azureResource = service.resourceDetailsMap.get(instanceId);
// Create stats for each of the compute links
computeLinks.forEach(computeLink -> {
ComputeStats resourceComputeStat = createComputeStatsForResource(computeLink, azureResource);
if (!resourceComputeStat.statValues.isEmpty()) {
resourceCostStats.add(resourceComputeStat);
}
});
});
}
}
Aggregations