本文整理汇总了Java中com.amazonaws.services.cloudwatch.model.Dimension.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Dimension.setValue方法的具体用法?Java Dimension.setValue怎么用?Java Dimension.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.cloudwatch.model.Dimension
的用法示例。
在下文中一共展示了Dimension.setValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: monitorCPUUsage
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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());
}
}
示例2: getCpuUtilization
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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;
}
示例3: getRequestCount
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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;
}
示例4: getInstanceDimension
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的package包/类
public static Dimension getInstanceDimension(String instanceId) {
if (instanceId == null)
return null;
Dimension dim = new Dimension();
dim.setName("InstanceId");
dim.setValue(instanceId);
return dim;
}
示例5: getMemoryUtilization
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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;
}
示例6: getEC2Stats
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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);
}
}
示例7: getBillingStats
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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);
}
示例8: getRequestCount
import com.amazonaws.services.cloudwatch.model.Dimension; //导入方法依赖的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.Dimension; //导入方法依赖的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;
}