Search in sources :

Example 6 with ServiceStat

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

the class AzureCostStatsService method createStatsForAzureService.

private Map<String, List<ServiceStat>> createStatsForAzureService(Context context, AzureService service, List<ComputeStats> resourceCostStats) {
    String currencyUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
    String serviceCode = service.meterCategory.replaceAll(" ", "");
    Map<String, List<ServiceStat>> stats = new HashMap<>();
    // Create stats for daily service cost
    List<ServiceStat> serviceStats = new ArrayList<>();
    String serviceResourceCostMetric = String.format(AzureCostConstants.SERVICE_RESOURCE_COST, serviceCode);
    for (Entry<Long, Double> cost : service.directCosts.entrySet()) {
        ServiceStat resourceCostStat = AzureCostHelper.createServiceStat(serviceResourceCostMetric, cost.getValue(), currencyUnit, cost.getKey());
        serviceStats.add(resourceCostStat);
    }
    if (!serviceStats.isEmpty()) {
        stats.put(serviceResourceCostMetric, serviceStats);
    }
    // Create daily cost stats for resources
    createStatsForAzureResources(context, service, resourceCostStats);
    return stats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AtomicDouble(com.google.common.util.concurrent.AtomicDouble)

Example 7 with ServiceStat

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

the class AzureCostHelper method createMonthlyEaAccountCostStats.

static List<ComputeStats> createMonthlyEaAccountCostStats(Map<LocalDate, EaAccountCost> monthlyEaAccountCosts, Map<LocalDate, Double> monthlyTotalCosts, ComputeStateWithDescription computeHostDesc) {
    List<ComputeStats> accountStats = new ArrayList<>();
    String usageCostStatName = AzureCostConstants.USAGE_COST;
    String marketplaceCostStatName = AzureCostConstants.MARKETPLACE_COST;
    String separatelyBilledCostStatName = AzureCostConstants.SEPARATELY_BILLED_COST;
    String costUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
    for (Entry<LocalDate, Double> monthlyTotalCost : monthlyTotalCosts.entrySet()) {
        ComputeStats accountStat = new ComputeStats();
        accountStat.computeLink = computeHostDesc.documentSelfLink;
        accountStat.statValues = new ConcurrentSkipListMap<>();
        LocalDate month = monthlyTotalCost.getKey();
        long timeStamp = adaptMonthToCostTimeStamp(month);
        EaAccountCost eaAccountCost = monthlyEaAccountCosts.get(month);
        ServiceStat usageCostServiceStat = AzureCostHelper.createServiceStat(usageCostStatName, eaAccountCost.monthlyEaAccountUsageCost, costUnit, timeStamp);
        ServiceStat marketplaceCostServiceStat = AzureCostHelper.createServiceStat(marketplaceCostStatName, eaAccountCost.monthlyEaAccountMarketplaceCost, costUnit, timeStamp);
        ServiceStat separatelyBilledCostServiceStat = AzureCostHelper.createServiceStat(separatelyBilledCostStatName, eaAccountCost.monthlyEaAccountSeparatelyBilledCost, costUnit, timeStamp);
        accountStat.statValues.put(usageCostStatName, Collections.singletonList(usageCostServiceStat));
        accountStat.statValues.put(marketplaceCostStatName, Collections.singletonList(marketplaceCostServiceStat));
        accountStat.statValues.put(separatelyBilledCostStatName, Collections.singletonList(separatelyBilledCostServiceStat));
        accountStats.add(accountStat);
    }
    return accountStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ArrayList(java.util.ArrayList) EaAccountCost(com.vmware.photon.controller.model.adapters.azure.ea.stats.AzureCostStatsService.EaAccountCost) LocalDate(org.joda.time.LocalDate)

Example 8 with ServiceStat

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

the class AzureCostHelper method createOldestBillDownloadedStat.

static ComputeStats createOldestBillDownloadedStat(ComputeStateWithDescription computeHostDesc, long billParsedMillis, long currentMonthBillParsedMillis) {
    ComputeStats stats = new ComputeStats();
    stats.computeLink = computeHostDesc.documentSelfLink;
    stats.statValues = new ConcurrentSkipListMap<>();
    stats.addCustomProperty(PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
    ServiceStat oldestBillDownloadedStat = AzureCostHelper.createServiceStat(AzureCostConstants.OLDEST_BILL_PROCESSED_MILLIS, billParsedMillis, PhotonModelConstants.UNIT_MILLISECONDS, currentMonthBillParsedMillis);
    stats.statValues.put(oldestBillDownloadedStat.name, Collections.singletonList(oldestBillDownloadedStat));
    return stats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 9 with ServiceStat

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

the class AzureCostHelper method createApiKeyExpiresTimeStat.

static ComputeStats createApiKeyExpiresTimeStat(ComputeStateWithDescription computeHostDesc, long keyExpiryTime) {
    ComputeStats accountStats = new ComputeStats();
    accountStats.computeLink = computeHostDesc.documentSelfLink;
    accountStats.statValues = new ConcurrentSkipListMap<>();
    ServiceStat keyExpiryTimeMillis = AzureCostHelper.createServiceStat(AzureCostConstants.EA_ACCOUNT_USAGE_KEY_EXPIRY_TIME_MILLIS, keyExpiryTime, PhotonModelConstants.UNIT_MILLISECONDS, AzureCostHelper.getMillisNow());
    accountStats.statValues.put(keyExpiryTimeMillis.name, Collections.singletonList(keyExpiryTimeMillis));
    return accountStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 10 with ServiceStat

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

the class AzureCostHelper method createServiceStat.

static ServiceStat createServiceStat(String metricName, Number value, String currencyUnit, Long timestamp) {
    ServiceStat stat = new ServiceStat();
    stat.name = metricName;
    stat.latestValue = value != null ? value.doubleValue() : 0.0d;
    stat.sourceTimeMicrosUtc = TimeUnit.MILLISECONDS.toMicros(timestamp);
    stat.unit = currencyUnit;
    return stat;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat)

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