Java Code Examples for com.amazonaws.services.cloudwatch.model.Dimension#setValue()
The following examples show how to use
com.amazonaws.services.cloudwatch.model.Dimension#setValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudWatchCollector.java From cloudwatch_exporter with Apache License 2.0 | 6 votes |
private List<List<Dimension>> permuteDimensions(List<String> dimensions, Map<String, List<String>> dimensionValues) { ArrayList<List<Dimension>> result = new ArrayList<List<Dimension>>(); if (dimensions.size() == 0) { result.add(new ArrayList<Dimension>()); } else { List<String> dimensionsCopy = new ArrayList<String>(dimensions); String dimensionName = dimensionsCopy.remove(dimensionsCopy.size() - 1); for (List<Dimension> permutation : permuteDimensions(dimensionsCopy, dimensionValues)) { for (String dimensionValue : dimensionValues.get(dimensionName)) { Dimension dimension = new Dimension(); dimension.setValue(dimensionValue); dimension.setName(dimensionName); ArrayList<Dimension> permutationCopy = new ArrayList<Dimension>(permutation); permutationCopy.add(dimension); result.add(permutationCopy); } } } return result; }
Example 2
Source File: CloudWatchCollector.java From cloudwatch_exporter with Apache License 2.0 | 6 votes |
private List<List<Dimension>> permuteDimensions(List<String> dimensions, Map<String, List<String>> dimensionValues) { ArrayList<List<Dimension>> result = new ArrayList<List<Dimension>>(); if (dimensions.size() == 0) { result.add(new ArrayList<Dimension>()); } else { List<String> dimensionsCopy = new ArrayList<String>(dimensions); String dimensionName = dimensionsCopy.remove(dimensionsCopy.size() - 1); for (List<Dimension> permutation : permuteDimensions(dimensionsCopy, dimensionValues)) { for (String dimensionValue : dimensionValues.get(dimensionName)) { Dimension dimension = new Dimension(); dimension.setValue(dimensionValue); dimension.setName(dimensionName); ArrayList<Dimension> permutationCopy = new ArrayList<Dimension>(permutation); permutationCopy.add(dimension); result.add(permutationCopy); } } } return result; }
Example 3
Source File: CloudWatchClient.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Override public Observable<String> createOrUpdateAlarm(String policyRefId, String jobId, AlarmConfiguration alarmConfiguration, String autoScalingGroup, List<String> actions) { Dimension dimension = new Dimension(); dimension.setName(AUTO_SCALING_GROUP_NAME); dimension.setValue(autoScalingGroup); String cloudWatchName = buildCloudWatchName(policyRefId, jobId); PutMetricAlarmRequest putMetricAlarmRequest = new PutMetricAlarmRequest(); if (alarmConfiguration.getActionsEnabled().isPresent()) { putMetricAlarmRequest.setActionsEnabled(alarmConfiguration.getActionsEnabled().get()); } putMetricAlarmRequest.setAlarmActions(actions); putMetricAlarmRequest.setAlarmName(cloudWatchName); putMetricAlarmRequest.setDimensions(Arrays.asList(dimension)); putMetricAlarmRequest.setNamespace(alarmConfiguration.getMetricNamespace()); putMetricAlarmRequest.setComparisonOperator(alarmConfiguration.getComparisonOperator().name()); putMetricAlarmRequest.setStatistic(alarmConfiguration.getStatistic().name()); putMetricAlarmRequest.setEvaluationPeriods(alarmConfiguration.getEvaluationPeriods()); putMetricAlarmRequest.setPeriod(alarmConfiguration.getPeriodSec()); putMetricAlarmRequest.setThreshold(alarmConfiguration.getThreshold()); putMetricAlarmRequest.setMetricName(alarmConfiguration.getMetricName()); return wrapWithExponentialRetry(String.format("createOrUpdateAlarm in policy %s for job %s", policyRefId, jobId), Observable.create(emitter -> awsCloudWatch.putMetricAlarmAsync(putMetricAlarmRequest, new AsyncHandler<PutMetricAlarmRequest, PutMetricAlarmResult>() { @Override public void onError(Exception exception) { createErrorCounter.increment(); emitter.onError(AutoScalePolicyException.errorCreatingAlarm(policyRefId, exception.getMessage())); } @Override public void onSuccess(PutMetricAlarmRequest request, PutMetricAlarmResult putMetricAlarmResult) { int httpStatusCode = putMetricAlarmResult.getSdkHttpMetadata().getHttpStatusCode(); log.info("Created Cloud Watch Alarm {} for {} - status {}", request, jobId, httpStatusCode); // TODO : how to get ARN created by AWS for this resource ? returning cloudWatchName for now createAlarmCounter.increment(); emitter.onNext(cloudWatchName); emitter.onCompleted(); } }), Emitter.BackpressureMode.NONE)); }
Example 4
Source File: AWSHelper.java From attic-stratos with Apache License 2.0 | 4 votes |
/** * 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; }
Example 5
Source File: AWSHelper.java From attic-stratos with Apache License 2.0 | 4 votes |
/** * 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; }