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


Java GetMetricStatisticsRequest.setEndTime方法代码示例

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


在下文中一共展示了GetMetricStatisticsRequest.setEndTime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setRequestCollectionWindow

import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest; //导入方法依赖的package包/类
/**
 * Sets the window of time for the statistics collection. If the last collection time is passed in the compute stats request
 * then that value is used for getting the stats data from the provider else the default configured window for stats
 * collection is used.
 *
 * Also, if the last collection time is really a long time ago, then the maximum collection window is honored to collect
 * the stats from the provider.
 */
private void setRequestCollectionWindow(Long defaultStartWindowMicros,
        Long lastCollectionTimeMicros,
        Long collectionPeriodInSeconds,
        GetMetricStatisticsRequest request) {
    long endTimeMicros = StatsUtil.computeIntervalBeginMicros(Utils.getNowMicrosUtc(),
            TimeUnit.SECONDS.toMillis(collectionPeriodInSeconds));
    request.setEndTime(new Date(TimeUnit.MICROSECONDS.toMillis(endTimeMicros)));
    Long maxCollectionWindowStartTime = TimeUnit.MICROSECONDS.toMillis(endTimeMicros) -
            TimeUnit.MICROSECONDS.toMillis(defaultStartWindowMicros);
    // If the last collection time is available, then the stats data from the provider will be
    // fetched from that time onwards. Else, the stats collection is performed starting from the
    // default configured window.
    if (lastCollectionTimeMicros == null) {
        request.setStartTime(new Date(maxCollectionWindowStartTime));
        return;
    }
    if (lastCollectionTimeMicros != 0) {
        if (lastCollectionTimeMicros > endTimeMicros) {
            throw new IllegalStateException(
                    "The last stats collection time cannot be in the future.");
            // Check if the last collection time calls for collection to earlier than the
            // maximum defined windows size.
            // In that case default to the maximum collection window.
        } else if (TimeUnit.MICROSECONDS
                .toMillis(lastCollectionTimeMicros) < maxCollectionWindowStartTime) {
            request.setStartTime(new Date(maxCollectionWindowStartTime));
            return;
        }
        long beginMicros = StatsUtil.computeIntervalBeginMicros(lastCollectionTimeMicros,
                TimeUnit.SECONDS.toMillis(collectionPeriodInSeconds));
        request.setStartTime(new Date(
                TimeUnit.MICROSECONDS.toMillis(beginMicros)));
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:43,代码来源:AWSStatsService.java

示例3: 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

示例4: 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

示例5: 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.setEndTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。