Refine search
setDimensions(new com.amazonaws.internal.SdkInternalList<Dimension>(dimensions.length)); this.dimensions.add(ele);
/** * <p> * The metric statistics, other than percentile. For percentile statistics, use <code>ExtendedStatistics</code>. * When calling <code>GetMetricStatistics</code>, you must specify either <code>Statistics</code> or * <code>ExtendedStatistics</code>, but not both. * </p> * * @param statistics * The metric statistics, other than percentile. For percentile statistics, use * <code>ExtendedStatistics</code>. When calling <code>GetMetricStatistics</code>, you must specify either * <code>Statistics</code> or <code>ExtendedStatistics</code>, but not both. * @return Returns a reference to this object so that method calls can be chained together. * @see Statistic */ public GetMetricStatisticsRequest withStatistics(Statistic... statistics) { com.amazonaws.internal.SdkInternalList<String> statisticsCopy = new com.amazonaws.internal.SdkInternalList<String>(statistics.length); for (Statistic value : statistics) { statisticsCopy.add(value.toString()); } if (getStatistics() == null) { setStatistics(statisticsCopy); } else { getStatistics().addAll(statisticsCopy); } return this; }
/** * <p> * The metric statistics, other than percentile. For percentile statistics, use <code>ExtendedStatistics</code>. * When calling <code>GetMetricStatistics</code>, you must specify either <code>Statistics</code> or * <code>ExtendedStatistics</code>, but not both. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setStatistics(java.util.Collection)} or {@link #withStatistics(java.util.Collection)} if you want to * override the existing values. * </p> * * @param statistics * The metric statistics, other than percentile. For percentile statistics, use * <code>ExtendedStatistics</code>. When calling <code>GetMetricStatistics</code>, you must specify either * <code>Statistics</code> or <code>ExtendedStatistics</code>, but not both. * @return Returns a reference to this object so that method calls can be chained together. * @see Statistic */ public GetMetricStatisticsRequest withStatistics(String... statistics) { if (this.statistics == null) { setStatistics(new com.amazonaws.internal.SdkInternalList<String>(statistics.length)); } for (String ele : statistics) { this.statistics.add(ele); } return this; }
private static GetMetricStatisticsRequest request( final String funcationValue, int hours) { final long twentyFourHrs = 1000 * 60 * 60l * hours; final int oneHour = 60 * 60 * hours; return new GetMetricStatisticsRequest() .withStartTime(new Date(new Date().getTime() - twentyFourHrs)) .withNamespace(PacmanRuleConstants.AWS_LAMBDA) .withPeriod(oneHour) .withDimensions( new Dimension().withName("FunctionName").withValue( funcationValue)) .withMetricName(PacmanRuleConstants.INVOCATIONS) .withStatistics("Sum").withEndTime(new Date()); }
initStatisticsByMetric( extractItem.getMetricStatisticNames() ); List<DimensionMetric> dimensionMetrics = new ArrayList<DimensionMetric>(); GetMetricStatisticsRequest getMetricRequest = new GetMetricStatisticsRequest(); getMetricRequest.setNamespace( extractItem.getNamespace() ); getMetricRequest.setPeriod( extractItem.getPeriodMinutes() * 60 ); getMetricRequest.setStartTime( dfYyyyMmDdHhMmSs.parse( properties.getProperty("startTime" ).trim() ) ); getMetricRequest.setEndTime( dfYyyyMmDdHhMmSs.parse( properties.getProperty("endTime").trim() ) ); getMetricRequest.setDimensions(dimensions); dimensionMetric.putDistinctMetricNameStatisticName( metricNameStatisticName ); getMetricRequest.setStatistics(statistics); getMetricRequest.setMetricName(metricName); GetMetricStatisticsResult getMetricStatisticsResult = cwClient.getMetricStatistics(getMetricRequest); List<Datapoint> datapoints = getMetricStatisticsResult.getDatapoints();
public StreamMetricManager(String streamName, List<KinesisOperationType> types, AmazonCloudWatch cloudWatchClient, AmazonKinesisClient kinesisClient) { this.streamName = streamName; this.trackedOperations.addAll(types); this.cloudWatchClient = cloudWatchClient; this.kinesisClient = kinesisClient; for (KinesisOperationType op : this.trackedOperations) { // create CloudWatch request templates for the information we have // at this point for (String metricName : op.getMetricsToFetch()) { GetMetricStatisticsRequest cwRequest = new GetMetricStatisticsRequest(); cwRequest.withNamespace(CW_NAMESPACE) .withDimensions(new Dimension().withName("StreamName").withValue(this.streamName)) .withPeriod(StreamMonitor.CLOUDWATCH_PERIOD).withStatistics(Statistic.Sum) .withMetricName(metricName); if (!this.cloudwatchRequestTemplates.containsKey(op)) { this.cloudwatchRequestTemplates.put(op, new ArrayList<GetMetricStatisticsRequest>() { { add(cwRequest); } }); } else { this.cloudwatchRequestTemplates.get(op).add(cwRequest); } } } }
double sampleMetric = 0D; req.withStartTime(metricStartTime.toDate()).withEndTime(metricEndTime.toDate()); cwSampleDuration, req.getMetricName()));
final long twoWeeks = 1000 * 60 * 60 * 24 * 15; final int twelveHours = 60 * 60 * 12; return new GetMetricStatisticsRequest() .withStartTime(new Date(new Date().getTime() - twoWeeks)) .withNamespace("AWS/Billing")
/** * <p> * The metric statistics, other than percentile. For percentile statistics, use <code>ExtendedStatistics</code>. * When calling <code>GetMetricStatistics</code>, you must specify either <code>Statistics</code> or * <code>ExtendedStatistics</code>, but not both. * </p> * * @param statistics * The metric statistics, other than percentile. For percentile statistics, use * <code>ExtendedStatistics</code>. When calling <code>GetMetricStatistics</code>, you must specify either * <code>Statistics</code> or <code>ExtendedStatistics</code>, but not both. * @return Returns a reference to this object so that method calls can be chained together. * @see Statistic */ public GetMetricStatisticsRequest withStatistics(java.util.Collection<String> statistics) { setStatistics(statistics); return this; }
/** * <p> * The dimensions. If the metric contains multiple dimensions, you must include a value for each dimension. * CloudWatch treats each unique combination of dimensions as a separate metric. If a specific combination of * dimensions was not published, you can't retrieve statistics for it. You must specify the same dimensions that * were used when the metrics were created. For an example, see <a href= * "http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#dimension-combinations" * >Dimension Combinations</a> in the <i>Amazon CloudWatch User Guide</i>. For more information about specifying * dimensions, see <a * href="http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html">Publishing * Metrics</a> in the <i>Amazon CloudWatch User Guide</i>. * </p> * * @param dimensions * The dimensions. If the metric contains multiple dimensions, you must include a value for each dimension. * CloudWatch treats each unique combination of dimensions as a separate metric. If a specific combination of * dimensions was not published, you can't retrieve statistics for it. You must specify the same dimensions * that were used when the metrics were created. For an example, see <a href= * "http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#dimension-combinations" * >Dimension Combinations</a> in the <i>Amazon CloudWatch User Guide</i>. For more information about * specifying dimensions, see <a * href="http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html">Publishing * Metrics</a> in the <i>Amazon CloudWatch User Guide</i>. * @return Returns a reference to this object so that method calls can be chained together. */ public GetMetricStatisticsRequest withDimensions(java.util.Collection<Dimension> dimensions) { setDimensions(dimensions); return this; }
private static GetMetricStatisticsRequest request( final String funcationValue) { final int fiveMin = 60 * 60 * 24; return new GetMetricStatisticsRequest() .withStartTime(new Date(new Date().getTime() - TWENTYFOURHOURS)) .withNamespace(PacmanRuleConstants.AWS_LAMBDA) .withPeriod(fiveMin) .withDimensions( new Dimension().withName( PacmanRuleConstants.FUNCTION_NAME).withValue( funcationValue)) .withMetricName(PacmanRuleConstants.THROTTLES) .withStatistics(PacmanRuleConstants.SUM) .withEndTime(new Date()); }
Date startDate = new Date(start - 1000 * rule.delaySeconds); Date endDate = new Date(start - 1000 * (rule.delaySeconds + rule.rangeSeconds)); GetMetricStatisticsRequest request = new GetMetricStatisticsRequest(); request.setNamespace(rule.awsNamespace); request.setMetricName(rule.awsMetricName); request.setStatistics(rule.awsStatistics); request.setExtendedStatistics(rule.awsExtendedStatistics); request.setEndTime(startDate); request.setStartTime(endDate); request.setPeriod(rule.periodSeconds); request.setDimensions(dimensions);
private static void findCloudWatchData() { LinkedHashMap<Date,Double> map=new HashMap<Date,Double>(); AmazonCloudWatchClient cloudWatch = new AmazonCloudWatchClient(new BasicAWSCredentials(AccessKey, SecretKey)); cloudWatch.setEndpoint("monitoring.us-east-1.amazonaws.com"); long offsetInMilliseconds = 1000 * 60 * 60 * 24; Dimension instanceDimension = new Dimension(); instanceDimension.setName("instanceid"); instanceDimension.setValue(instanceid); GetMetricStatisticsRequest request = new GetMetricStatisticsRequest() .withStartTime(new Date(new Date().getTime() - offsetInMilliseconds)) .withNamespace("AWS/EC2") .withPeriod(60 * 60) .withMetricName("CPUUtilization") .withStatistics("Average") .withDimensions(Arrays.asList(instanceDimension)) .withEndTime(new Date()); GetMetricStatisticsResult getMetricStatisticsResult = cloudWatch.getMetricStatistics(request); } //To read the Data for (Datapoint dp : result.getDatapoints()) { map.put(dp.getTimeStamp(), dp.getAverage()); //or getMaximum() or whatever Statistics you are interested in. You can also maintain a list of the statistics you are interested in. Ex: request.setStatistics(list) }
/** * <p> * The metric statistics to return. For information about specific * statistics returned by GetMetricStatistics, see <a href= * "http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Statistic" * >Statistics</a> in the <i>Amazon CloudWatch Developer Guide</i>. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param statistics <p> * The metric statistics to return. For information about * specific statistics returned by GetMetricStatistics, see <a * href= * "http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Statistic" * >Statistics</a> in the <i>Amazon CloudWatch Developer * Guide</i>. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public GetMetricStatisticsRequest withStatistics(java.util.Collection<String> statistics) { setStatistics(statistics); return this; }
/** * <p> * A list of dimensions describing qualities of the metric. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param dimensions <p> * A list of dimensions describing qualities of the metric. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public GetMetricStatisticsRequest withDimensions(java.util.Collection<Dimension> dimensions) { setDimensions(dimensions); return this; }
GetMetricStatisticsRequest createMetricStatisticsRequest( String streamName, Instant countSince, Instant countTo, Minutes period) { return new GetMetricStatisticsRequest() .withNamespace(KINESIS_NAMESPACE) .withMetricName(INCOMING_RECORDS_METRIC) .withPeriod(period.getMinutes() * PERIOD_GRANULARITY_IN_SECONDS) .withStartTime(countSince.toDate()) .withEndTime(countTo.toDate()) .withStatistics(Collections.singletonList(SUM_STATISTIC)) .withDimensions( Collections.singletonList( new Dimension().withName(STREAM_NAME_DIMENSION).withValue(streamName))); }
@Override @Cacheable(lifetime = Tv.THIRTY, unit = TimeUnit.MINUTES) public long bytesTransferred() { final Date now = new Date(); final List<Datapoint> datapoints = DefaultHost.this.cloudwatch.get().getMetricStatistics( new GetMetricStatisticsRequest() .withMetricName("BytesTransferred") .withNamespace("S3Auth") .withStatistics("Sum") .withDimensions( new Dimension() .withName("Bucket") .withValue(this.bucket) ) .withUnit(StandardUnit.Bytes) .withPeriod((int) TimeUnit.DAYS.toSeconds(Tv.SEVEN)) .withStartTime(DateUtils.addWeeks(now, -1)) .withEndTime(now) ).getDatapoints(); long sum = 0L; for (final Datapoint datapoint : datapoints) { sum += datapoint.getSum(); } return sum; } }
public GetMetricStatisticsResult getMetricStatistics(String metricName, String namespace, String statistics, String extendedStatistics, String unit) throws AmazonServiceException { AwsCloudWatchPluginExtension ext = getProject().getExtensions().getByType(AwsCloudWatchPluginExtension.class); AmazonCloudWatch cw = ext.getClient(); GetMetricStatisticsRequest request = new GetMetricStatisticsRequest() .withMetricName(metricName) .withNamespace(namespace) .withStatistics(statistics) .withExtendedStatistics(extendedStatistics) .withUnit(unit) .withEndTime(getEndTime()) .withStartTime(getStartTime()) .withPeriod(getPeriod()); if (getDimensions() != null) { request.withDimensions(getDimensions().entrySet().stream() .map(it -> new Dimension() .withName(it.getKey().toString()) .withValue(it.getValue())) .collect(Collectors.toList())); } GetMetricStatisticsResult response = cw.getMetricStatistics(request); for (Datapoint metric : response.getDatapoints()) { getLogger().debug("Retrieved metric %s", metric.getAverage()); } return response; }