本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult.getDatapoints方法的典型用法代码示例。如果您正苦于以下问题:Java GetMetricStatisticsResult.getDatapoints方法的具体用法?Java GetMetricStatisticsResult.getDatapoints怎么用?Java GetMetricStatisticsResult.getDatapoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult
的用法示例。
在下文中一共展示了GetMetricStatisticsResult.getDatapoints方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstanceAverageLoad
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
private double getInstanceAverageLoad(AmazonCloudWatchClient cloudWatchClient, String instanceId) {
long offsetInMilliseconds = 1000 * 60 * 60;
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(new Date(new Date().getTime() - offsetInMilliseconds))
.withNamespace("AWS/EC2")
.withPeriod(60 * 60)
.withDimensions(new Dimension().withName("InstanceId").withValue(instanceId))
.withMetricName("CPUUtilization")
.withStatistics("Average", "Maximum")
.withEndTime(new Date());
GetMetricStatisticsResult getMetricStatisticsResult = cloudWatchClient.getMetricStatistics(request);
double avgCPUUtilization = 0;
List dataPoint = getMetricStatisticsResult.getDatapoints();
for (Object aDataPoint : dataPoint) {
Datapoint dp = (Datapoint) aDataPoint;
avgCPUUtilization = dp.getAverage();
}
return avgCPUUtilization;
}
示例2: monitorCPUUsage
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的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());
}
}
示例3: getCpuUtilization
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
public GetMetricStatisticsResult getCpuUtilization(String name) {
Dimension instanceDimension = new Dimension();
if (namespace.endsWith("EC2")) {
instanceDimension.setName("InstanceId");
} else {
instanceDimension.setName("DBInstanceIdentifier");
}
instanceDimension.setValue(name);
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.add(Calendar.MINUTE, -10);
startCal.set(Calendar.SECOND, 0);
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(startCal.getTime())
.withEndTime(endCal.getTime())
.withNamespace(namespace)
.withPeriod(60)
.withMetricName("CPUUtilization")
.withStatistics("Average")
.withStatistics("Maximum")
.withDimensions(Arrays.asList(instanceDimension));
GetMetricStatisticsResult result = sort(cloudWatch.getMetricStatistics(request).getDatapoints());
if (logger.isDebugEnabled()) {
if (result.getDatapoints() != null && result.getDatapoints().size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.debug("[{}:{}] {}, {} ~ {}", new Object[] {namespace, pulse.getId(), result, sdf.format(startCal.getTime()), sdf.format(endCal.getTime())});
}
}
return result;
}
示例4: getRequestCount
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
public GetMetricStatisticsResult getRequestCount(String name) {
Dimension instanceDimension = new Dimension();
String ns = null;
if (pulse.getType().equals("application")) {
ns = "AWS/ApplicationELB";
instanceDimension.setName("LoadBalancer");
} else {
ns = "AWS/ELB";
instanceDimension.setName("LoadBalancerName");
}
instanceDimension.setValue(name);
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.add(Calendar.MINUTE, -10);
startCal.set(Calendar.SECOND, 0);
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(startCal.getTime())
.withEndTime(endCal.getTime())
.withNamespace(ns)
.withPeriod(60)
.withMetricName("RequestCount")
.withStatistics("Sum")
.withDimensions(Arrays.asList(instanceDimension));
GetMetricStatisticsResult result = sort(cloudWatch.getMetricStatistics(request).getDatapoints());
if (logger.isDebugEnabled()) {
if (result.getDatapoints() != null && result.getDatapoints().size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.debug("[{}:{}] {}, {} ~ {}", new Object[] {namespace, pulse.getId(), result, sdf.format(startCal.getTime()), sdf.format(endCal.getTime())});
}
}
return result;
}
示例5: onSuccess
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
@Override
public void onSuccess(GetMetricStatisticsRequest request,
GetMetricStatisticsResult result) {
try {
OperationContext.restoreOperationContext(this.opContext);
List<ServiceStat> statDatapoints = new ArrayList<>();
List<Datapoint> dpList = result.getDatapoints();
if (dpList != null && dpList.size() != 0) {
for (Datapoint dp : dpList) {
ServiceStat stat = new ServiceStat();
stat.latestValue = dp.getAverage();
stat.unit = AWSStatsNormalizer.getNormalizedUnitValue(dp.getUnit());
stat.sourceTimeMicrosUtc = TimeUnit.MILLISECONDS
.toMicros(dp.getTimestamp().getTime());
statDatapoints.add(stat);
}
this.statsData.statsResponse.statValues
.put(AWSStatsNormalizer.getNormalizedStatKeyValue(result.getLabel()),
statDatapoints);
}
if (this.statsData.numResponses.incrementAndGet() == this.numOfMetrics) {
sendStats(this.statsData);
}
} catch (Exception e) {
this.statsData.taskManager.patchTaskToFailure(e);
}
}
示例6: lookupAndSaveMetricData
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
public void lookupAndSaveMetricData( CloudWatchMetric metric, String dimensionValue, String type ) throws CandlestackAWSException, CandlestackException {
String datapointDateMapKey = getDatapointDateMapKey( metric, dimensionValue );
// Determine the last time we fetched datapoints for this metric and dimension
Date lastDatapointDate = lastDatapointDateMap.get( datapointDateMapKey );
if ( lastDatapointDate == null ) {
lastDatapointDate = metricsReaderWriter.readMostRecentMetricDate( type, dimensionValue, metric.getName() );
}
// Build the request and execute it
GetMetricStatisticsRequest request = cloudWatchRequest( metric, dimensionValue, lastDatapointDate );
GetMetricStatisticsResult result = cloudWatchClient.getMetricStatistics( request );
// Sort the datapoints in chronological order
List<Datapoint> datapoints = result.getDatapoints();
datapoints.sort( new DatapointComparator() );
// Write the data points
for ( Datapoint datapoint : datapoints ) {
// Only care about data points that have happened after the last one
if ( lastDatapointDate == null || datapoint.getTimestamp().after( lastDatapointDate ) ) {
lastDatapointDate = datapoint.getTimestamp();
metricsReaderWriter.writeMetric( type, dimensionValue, datapoint.getTimestamp(), metric.getName(), metric.getStatistic().getValueFromDatapoint( datapoint ) );
}
}
// Update the date map
lastDatapointDateMap.put( datapointDateMapKey, lastDatapointDate );
}
示例7: getMemoryUtilization
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的package包/类
public GetMetricStatisticsResult getMemoryUtilization(String name) {
Dimension instanceDimension = new Dimension();
String ns = null;
String metric = null;
if (namespace.endsWith("EC2")) {
ns = "System/Linux";
instanceDimension.setName("InstanceId");
metric = "MemoryUtilization";
} else {
ns = namespace;
instanceDimension.setName("DBInstanceIdentifier");
metric = "FreeableMemory";
}
instanceDimension.setValue(name);
Calendar startCal = Calendar.getInstance();
Calendar endCal = Calendar.getInstance();
startCal.add(Calendar.MINUTE, -10);
startCal.set(Calendar.SECOND, 0);
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withStartTime(startCal.getTime())
.withEndTime(endCal.getTime())
.withNamespace(ns)
.withPeriod(60)
.withMetricName(metric)
.withStatistics("Average")
.withStatistics("Maximum")
.withDimensions(Arrays.asList(instanceDimension));
GetMetricStatisticsResult result = sort(cloudWatch.getMetricStatistics(request).getDatapoints());
if (logger.isDebugEnabled()) {
if (result.getDatapoints() != null && result.getDatapoints().size() > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.debug("[{}:{}] {}, {} ~ {}", new Object[] {namespace, pulse.getId(), result, sdf.format(startCal.getTime()), sdf.format(endCal.getTime())});
}
}
return result;
}
示例8: getRequestCount
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的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;
}
示例9: getResponseCountForMetric
import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult; //导入方法依赖的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;
}