当前位置: 首页>>代码示例>>Java>>正文


Java GetMetricStatisticsRequest.setMetricName方法代码示例

本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest.setMetricName方法的典型用法代码示例。如果您正苦于以下问题:Java GetMetricStatisticsRequest.setMetricName方法的具体用法?Java GetMetricStatisticsRequest.setMetricName怎么用?Java GetMetricStatisticsRequest.setMetricName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest的用法示例。


在下文中一共展示了GetMetricStatisticsRequest.setMetricName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: monitorCPUUsage

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
public void monitorCPUUsage() {
	AmazonCloudWatchClient cloudClient = new AmazonCloudWatchClient(
			getAwsCredentials());
	GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
	Calendar cal = Calendar.getInstance();
	request.setEndTime(cal.getTime());
	cal.add(Calendar.MINUTE, -5);
	request.setStartTime(cal.getTime());
	request.setNamespace("AWS/EC2");
	List<String> statistics = new ArrayList<String>();
	statistics.add("Maximium");
	statistics.add("Average");
	request.setStatistics(statistics);
	request.setMetricName("CPUUtilization");
	request.setPeriod(300);
	Dimension dimension = new Dimension();
	dimension.setName("InstanceId");
	dimension.setValue("i-d93fa2a4");
	List<Dimension> dimensions = new ArrayList<Dimension>();
	dimensions.add(dimension);
	request.setDimensions(dimensions);
	GetMetricStatisticsResult result = cloudClient
			.getMetricStatistics(request);
	List<Datapoint> dataPoints = result.getDatapoints();
	for (Datapoint dataPoint : dataPoints) {
		System.out.println(dataPoint.getAverage());
	}

}
 
开发者ID:JulianEberius,项目名称:dwtc-extractor,代码行数:30,代码来源:Master.java

示例2: getMetric

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
public static List<Datum> getMetric(String metricName, Dimension dim, String namespace, Date startTime, int period, Statistic statistic, StandardUnit unit) {
	connect();
	
	GetMetricStatisticsRequest req = new GetMetricStatisticsRequest();
	
	req.setMetricName(metricName);
	
	List<Dimension> dimensions = new ArrayList<Dimension>();
	dimensions.add(dim);
	req.setDimensions(dimensions);
	
	req.setNamespace(namespace);
	
	req.setStartTime(startTime);
	req.setEndTime(new Date());
	
	if (period % 60 != 0)
		period = (period / 60) * 60;
	req.setPeriod(period);
	
	if (unit != null)
		req.setUnit(unit);
	
	if (statistic == null)
		statistic = Statistic.Average;
	List<String> statistics = new ArrayList<String>();
	statistics.add(statistic.name());
	req.setStatistics(statistics);
	
	GetMetricStatisticsResult res = client.getMetricStatistics(req);
	return Datum.getAllData(res.getDatapoints(), metricName, statistic);
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:33,代码来源:CloudWatch.java

示例3: getEC2Stats

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
/**
 * Gets EC2 statistics.
 *
 * @param statsData The context object for stats.
 * @param metricNames The metrics names to gather stats for.
 * @param isAggregateStats Indicates where we are interested in aggregate stats or not.
 */
private void getEC2Stats(AWSStatsDataHolder statsData, String[] metricNames,
        boolean isAggregateStats) {
    if (getAWSAsyncStatsClient(statsData) == null) {
        return;
    }
    Long collectionPeriod = Long.getLong(AWS_COLLECTION_PERIOD_SECONDS, DEFAULT_AWS_COLLECTION_PERIOD_SECONDS);
    for (String metricName : metricNames) {
        GetMetricStatisticsRequest metricRequest = new GetMetricStatisticsRequest();
        // get datapoint for the for the passed in time window.
        try {
            setRequestCollectionWindow(
                    TimeUnit.MINUTES.toMicros(MAX_METRIC_COLLECTION_WINDOW_IN_MINUTES),
                    statsData.statsRequest.lastCollectionTimeMicrosUtc,
                    collectionPeriod,
                    metricRequest);
        } catch (IllegalStateException e) {
            // no data to process. notify parent
            statsData.taskManager.finishTask();
            return;
        }
        metricRequest.setPeriod(collectionPeriod.intValue());
        metricRequest.setStatistics(Arrays.asList(STATISTICS));
        metricRequest.setNamespace(NAMESPACE);

        // Provide instance id dimension only if it is not aggregate stats.
        if (!isAggregateStats) {
            List<Dimension> dimensions = new ArrayList<>();
            Dimension dimension = new Dimension();
            dimension.setName(DIMENSION_INSTANCE_ID);
            String instanceId = statsData.computeDesc.id;
            dimension.setValue(instanceId);
            dimensions.add(dimension);
            metricRequest.setDimensions(dimensions);
        }

        metricRequest.setMetricName(metricName);

        logFine(() -> String.format("Retrieving %s metric from AWS", metricName));
        AsyncHandler<GetMetricStatisticsRequest, GetMetricStatisticsResult> resultHandler = new AWSStatsHandler(
                statsData, metricNames.length, isAggregateStats);
        statsData.statsClient.getMetricStatisticsAsync(metricRequest, resultHandler);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:51,代码来源:AWSStatsService.java

示例4: getBillingStats

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
private void getBillingStats(AWSStatsDataHolder statsData) {
    if (getAWSAsyncBillingClient(statsData) == null) {
        return;
    }
    Dimension dimension = new Dimension();
    dimension.setName(DIMENSION_CURRENCY);
    dimension.setValue(DIMENSION_CURRENCY_VALUE);
    GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
    // AWS pushes billing metrics every 4 hours. However the timeseries returned does not have
    // static time stamps associated with the data points. The timestamps range from
    // (currentTime - 4 hrs) and are spaced at 4 hrs.
    // Get all 14 days worth of estimated charges data by default when last collection time is not set.
    // Otherwise set the window to lastCollectionTime - 4 hrs.
    Long lastCollectionTimeForEstimatedCharges = null;
    Long collectionPeriod = Long.getLong(AWS_COLLECTION_PERIOD_SECONDS, DEFAULT_AWS_COLLECTION_PERIOD_SECONDS);
    if (statsData.statsRequest.lastCollectionTimeMicrosUtc != null) {
        lastCollectionTimeForEstimatedCharges =
                statsData.statsRequest.lastCollectionTimeMicrosUtc
                        - TimeUnit.HOURS.toMicros(COST_COLLECTION_PERIOD_IN_HOURS);

    }

    // defaulting to fetch 14 days of estimated charges data
    try {
        setRequestCollectionWindow(
                TimeUnit.DAYS.toMicros(COST_COLLECTION_WINDOW_IN_DAYS),
                lastCollectionTimeForEstimatedCharges,
                collectionPeriod,
                request);
    } catch (IllegalStateException e) {
        // no data to process. notify parent
        statsData.taskManager.finishTask();
        return;
    }

    request.setPeriod(COST_COLLECTION_PERIOD_IN_SECONDS);
    request.setStatistics(Arrays.asList(STATISTICS));
    request.setNamespace(BILLING_NAMESPACE);
    request.setDimensions(Collections.singletonList(dimension));
    request.setMetricName(AWSConstants.ESTIMATED_CHARGES);

    logFine(() -> String.format("Retrieving %s metric from AWS",
            AWSConstants.ESTIMATED_CHARGES));
    AsyncHandler<GetMetricStatisticsRequest, GetMetricStatisticsResult> resultHandler = new AWSBillingStatsHandler(
            statsData, lastCollectionTimeForEstimatedCharges);
    statsData.billingClient.getMetricStatisticsAsync(request, resultHandler);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:48,代码来源:AWSStatsService.java

示例5: getRequestCount

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
/**
 * Retrieves the total number of requests that were made to the load
 * balancer during the given time interval in the past
 *
 * @param loadBalancerName
 * @param region
 * @param timeInterval     in seconds which must be multiple of 60
 * @return number of requests made
 */
public int getRequestCount(String loadBalancerName, String region,
                           int timeInterval) {
    int count = 0;

    try {
        GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
        request.setMetricName(Constants.REQUEST_COUNT_METRIC_NAME);
        request.setNamespace(Constants.CLOUD_WATCH_NAMESPACE_NAME);

        Date currentTime = new DateTime(DateTimeZone.UTC).toDate();
        Date pastTime = new DateTime(DateTimeZone.UTC).minusSeconds(
                timeInterval).toDate();

        request.setStartTime(pastTime);
        request.setEndTime(currentTime);

        request.setPeriod(timeInterval);

        HashSet<String> statistics = new HashSet<String>();
        statistics.add(Constants.SUM_STATISTICS_NAME);
        request.setStatistics(statistics);

        HashSet<Dimension> dimensions = new HashSet<Dimension>();
        Dimension loadBalancerDimension = new Dimension();
        loadBalancerDimension
                .setName(Constants.LOAD_BALANCER_DIMENTION_NAME);
        loadBalancerDimension.setValue(loadBalancerName);
        dimensions.add(loadBalancerDimension);
        request.setDimensions(dimensions);

        cloudWatchClient.setEndpoint(String.format(
                Constants.CLOUD_WATCH_ENDPOINT_URL_FORMAT, region));

        GetMetricStatisticsResult result = cloudWatchClient
                .getMetricStatistics(request);

        List<Datapoint> dataPoints = result.getDatapoints();

        if (dataPoints != null && dataPoints.size() > 0) {
            count = dataPoints.get(0).getSum().intValue();
        }

    } catch (AmazonClientException e) {
        log.error(
                "Could not get request count statistics of load balancer "
                        + loadBalancerName, e);
    }

    return count;
}
 
开发者ID:apache,项目名称:stratos,代码行数:60,代码来源:AWSHelper.java

示例6: getResponseCountForMetric

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
/**
 * Retrieves the number of responses generated for a particular response
 * code like 2XX, 3XX, 4XX, 5XX
 *
 * @param loadBalancerName
 * @param region
 * @param metricName       which is one among HTTPCode_Backend_2XX or
 *                         HTTPCode_Backend_3XX or HTTPCode_Backend_4XX or
 *                         HTTPCode_Backend_5XX
 * @param startTime        of the window to be scanned
 * @param endTime          of the window to be scanned
 * @param timeInterval     in seconds
 * @return number for response for this metric
 */
public int getResponseCountForMetric(String loadBalancerName,
                                     String region, String metricName, Date startTime, Date endTime,
                                     int timeInterval) {
    int count = 0;

    try {
        GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
        request.setMetricName(metricName);
        request.setNamespace(Constants.CLOUD_WATCH_NAMESPACE_NAME);

        request.setStartTime(startTime);
        request.setEndTime(endTime);

        request.setPeriod(timeInterval);

        HashSet<String> statistics = new HashSet<String>();
        statistics.add(Constants.SUM_STATISTICS_NAME);
        request.setStatistics(statistics);

        HashSet<Dimension> dimensions = new HashSet<Dimension>();
        Dimension loadBalancerDimension = new Dimension();
        loadBalancerDimension
                .setName(Constants.LOAD_BALANCER_DIMENTION_NAME);
        loadBalancerDimension.setValue(loadBalancerName);
        dimensions.add(loadBalancerDimension);
        request.setDimensions(dimensions);

        cloudWatchClient.setEndpoint(String.format(
                Constants.CLOUD_WATCH_ENDPOINT_URL_FORMAT, region));

        GetMetricStatisticsResult result = cloudWatchClient
                .getMetricStatistics(request);

        List<Datapoint> dataPoints = result.getDatapoints();

        if (dataPoints != null && dataPoints.size() > 0) {
            count = dataPoints.get(0).getSum().intValue();
        }

    } catch (AmazonClientException e) {
        log.error("Could not get the statistics for metric " + metricName
                + " of load balancer " + loadBalancerName, e);
    }

    return count;
}
 
开发者ID:apache,项目名称:stratos,代码行数:61,代码来源:AWSHelper.java


注:本文中的com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest.setMetricName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。