Skip to content

Commit 312d49a

Browse files
committed
Add CloudWatchMetricPublisher, a MetricPublisher implementation that uploads metric data to CloudWatch.
1 parent 8c192e3 commit 312d49a

File tree

24 files changed

+2560
-1
lines changed

24 files changed

+2560
-1
lines changed

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/MetricCollection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.metrics;
1717

18+
import java.time.Instant;
1819
import java.util.List;
1920
import software.amazon.awssdk.annotations.SdkPublicApi;
2021

@@ -41,4 +42,9 @@ public interface MetricCollection extends Iterable<MetricRecord<?>> {
4142
* @return The child metric collections.
4243
*/
4344
List<MetricCollection> children();
45+
46+
/**
47+
* @return The time at which this collection was created.
48+
*/
49+
Instant creationTime();
4450
}

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/SdkMetric.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public interface SdkMetric<T> {
5252
*/
5353
T convertValue(Object o);
5454

55+
/**
56+
* Create a new metric under the {@link MetricCategory#DEFAULT} category.
57+
*
58+
* @param name The name of this metric.
59+
* @param clzz The class of the object containing the associated value for this metric.
60+
* @param <T> The type of the object containing the associated value for this metric.
61+
* @return The created metric.
62+
*
63+
* @throws IllegalArgumentException If a metric of the same name has already been created.
64+
*/
65+
static <T> SdkMetric<T> create(String name, Class<T> clzz) {
66+
return DefaultSdkMetric.create(name, clzz, MetricCategory.DEFAULT);
67+
}
68+
5569
/**
5670
* Create a new metric.
5771
*

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/internal/DefaultMetricCollection.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static java.util.stream.Collectors.toList;
1919

20+
import java.time.Instant;
2021
import java.util.Collections;
2122
import java.util.Iterator;
2223
import java.util.List;
@@ -32,14 +33,15 @@ public final class DefaultMetricCollection implements MetricCollection {
3233
private final String name;
3334
private final Map<SdkMetric<?>, List<MetricRecord<?>>> metrics;
3435
private final List<MetricCollection> children;
35-
36+
private final Instant creationTime;
3637

3738
public DefaultMetricCollection(String name, Map<SdkMetric<?>,
3839
List<MetricRecord<?>>> metrics,
3940
List<MetricCollection> children) {
4041
this.name = name;
4142
this.metrics = metrics;
4243
this.children = children != null ? Collections.unmodifiableList(children) : Collections.emptyList();
44+
this.creationTime = Instant.now();
4345
}
4446

4547
@Override
@@ -65,6 +67,11 @@ public List<MetricCollection> children() {
6567
return children;
6668
}
6769

70+
@Override
71+
public Instant creationTime() {
72+
return creationTime;
73+
}
74+
6875
@Override
6976
public Iterator<MetricRecord<?>> iterator() {
7077
return metrics.values().stream()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>software.amazon.awssdk</groupId>
19+
<artifactId>metric-publishers</artifactId>
20+
<version>2.13.23-SNAPSHOT</version>
21+
</parent>
22+
23+
<artifactId>cloudwatch-metric-publisher</artifactId>
24+
<name>AWS Java SDK :: Metric Publishers :: CloudWatch</name>
25+
<packaging>jar</packaging>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>software.amazon.awssdk</groupId>
30+
<artifactId>cloudwatch</artifactId>
31+
<version>${awsjavasdk.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>software.amazon.awssdk</groupId>
35+
<artifactId>annotations</artifactId>
36+
<version>${awsjavasdk.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>software.amazon.awssdk</groupId>
40+
<artifactId>sdk-core</artifactId>
41+
<version>${awsjavasdk.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>software.amazon.awssdk</groupId>
45+
<artifactId>http-client-spi</artifactId>
46+
<version>${awsjavasdk.version}</version>
47+
</dependency>
48+
</dependencies>
49+
</project>

0 commit comments

Comments
 (0)