@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getLabel() == null) ? 0 : getLabel().hashCode()); hashCode = prime * hashCode + ((getDatapoints() == null) ? 0 : getDatapoints().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getLabel() != null) sb.append("Label: ").append(getLabel()).append(","); if (getDatapoints() != null) sb.append("Datapoints: ").append(getDatapoints()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetMetricStatisticsResult == false) return false; GetMetricStatisticsResult other = (GetMetricStatisticsResult) obj; if (other.getLabel() == null ^ this.getLabel() == null) return false; if (other.getLabel() != null && other.getLabel().equals(this.getLabel()) == false) return false; if (other.getDatapoints() == null ^ this.getDatapoints() == null) return false; if (other.getDatapoints() != null && other.getDatapoints().equals(this.getDatapoints()) == false) return false; return true; }
/** * <p> * The datapoints for the specified metric. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param datapoints <p> * The datapoints for the specified metric. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public GetMetricStatisticsResult withDatapoints(Datapoint... datapoints) { if (getDatapoints() == null) { this.datapoints = new java.util.ArrayList<Datapoint>(datapoints.length); } for (Datapoint value : datapoints) { this.datapoints.add(value); } return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getLabel() == null) ? 0 : getLabel().hashCode()); hashCode = prime * hashCode + ((getDatapoints() == null) ? 0 : getDatapoints().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getLabel() != null) sb.append("Label: " + getLabel() + ","); if (getDatapoints() != null) sb.append("Datapoints: " + getDatapoints()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetMetricStatisticsResult == false) return false; GetMetricStatisticsResult other = (GetMetricStatisticsResult) obj; if (other.getLabel() == null ^ this.getLabel() == null) return false; if (other.getLabel() != null && other.getLabel().equals(this.getLabel()) == false) return false; if (other.getDatapoints() == null ^ this.getDatapoints() == null) return false; if (other.getDatapoints() != null && other.getDatapoints().equals(this.getDatapoints()) == false) return false; return true; } }
for (Datapoint d : cloudWatchMetrics.getDatapoints()) { StreamMetric metric = StreamMetric.fromUnit(d.getUnit());
@TaskAction public void getMetricStatistics() { // NOPMD try { GetMetricStatisticsResult result = getMetricStatistics(getMetricName(), getNamespace(), getStatistics(), getExtendedStatistics(), getUnit()); datapoints = result.getDatapoints(); label = result.getLabel(); } catch (AmazonServiceException e) { throw new GradleException("Fail to describe metric: " + getMetricName(), e); } } }
.getMetricStatistics(request); for (final Datapoint dataPoint : result.getDatapoints()) {
.getMetricStatistics(request); for (final Datapoint dataPoint : result.getDatapoints()) {
getMetricRequest.setMetricName(metricName); GetMetricStatisticsResult getMetricStatisticsResult = cwClient.getMetricStatistics(getMetricRequest); List<Datapoint> datapoints = getMetricStatisticsResult.getDatapoints(); for (Datapoint datapoint : datapoints) {
/** * Gets total size in bytes of all events that remain in Kinesis stream between specified * instants. * * @return total size in bytes of all Kinesis events after specified instant */ public long getBacklogBytes( final String streamName, final Instant countSince, final Instant countTo) throws TransientKinesisException { return wrapExceptions( () -> { Minutes period = Minutes.minutesBetween(countSince, countTo); if (period.isLessThan(Minutes.ONE)) { return 0L; } GetMetricStatisticsRequest request = createMetricStatisticsRequest(streamName, countSince, countTo, period); long totalSizeInBytes = 0; GetMetricStatisticsResult result = cloudWatch.getMetricStatistics(request); for (Datapoint point : result.getDatapoints()) { totalSizeInBytes += point.getSum().longValue(); } return totalSizeInBytes; }); }
Datapoint dp = getNewestDatapoint(result.getDatapoints()); if (dp == null) { continue;
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; }
@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; } }