@@ -28,9 +28,7 @@ If you're new to Amazon CloudWatch, there are two terminologies you must be awar
28
28
29
29
## Install
30
30
31
- Depending on your version of Java (either Java 1.8 or 11+), the configuration slightly changes.
32
-
33
- === "Maven Java 11+"
31
+ === "Maven"
34
32
35
33
```xml hl_lines="3-7 16 18 24-27"
36
34
<dependencies>
@@ -75,52 +73,7 @@ If you're new to Amazon CloudWatch, there are two terminologies you must be awar
75
73
</build>
76
74
```
77
75
78
- === "Maven Java 1.8"
79
-
80
- ```xml hl_lines="3-7 16 18 24-27"
81
- <dependencies>
82
- ...
83
- <dependency>
84
- <groupId>software.amazon.lambda</groupId>
85
- <artifactId>powertools-metrics</artifactId>
86
- <version>{{ powertools.version }}</version>
87
- </dependency>
88
- ...
89
- </dependencies>
90
- ...
91
- <!-- configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project -->
92
- <build>
93
- <plugins>
94
- ...
95
- <plugin>
96
- <groupId>org.codehaus.mojo</groupId>
97
- <artifactId>aspectj-maven-plugin</artifactId>
98
- <version>1.14.0</version>
99
- <configuration>
100
- <source>1.8</source>
101
- <target>1.8</target>
102
- <complianceLevel>1.8</complianceLevel>
103
- <aspectLibraries>
104
- <aspectLibrary>
105
- <groupId>software.amazon.lambda</groupId>
106
- <artifactId>powertools-metrics</artifactId>
107
- </aspectLibrary>
108
- </aspectLibraries>
109
- </configuration>
110
- <executions>
111
- <execution>
112
- <goals>
113
- <goal>compile</goal>
114
- </goals>
115
- </execution>
116
- </executions>
117
- </plugin>
118
- ...
119
- </plugins>
120
- </build>
121
- ```
122
-
123
- === "Gradle Java 11+"
76
+ === "Gradle"
124
77
125
78
```groovy hl_lines="3 11"
126
79
plugins {
@@ -140,34 +93,14 @@ If you're new to Amazon CloudWatch, there are two terminologies you must be awar
140
93
targetCompatibility = 11
141
94
```
142
95
143
- === "Gradle Java 1.8"
144
-
145
- ```groovy hl_lines="3 11"
146
- plugins {
147
- id 'java'
148
- id 'io.freefair.aspectj.post-compile-weaving' version '6.6.3'
149
- }
150
-
151
- repositories {
152
- mavenCentral()
153
- }
154
-
155
- dependencies {
156
- aspect 'software.amazon.lambda:powertools-metrics:{{ powertools.version }}'
157
- }
158
-
159
- sourceCompatibility = 1.8
160
- targetCompatibility = 1.8
161
- ```
162
-
163
96
## Getting started
164
97
165
98
Metric has two global settings that will be used across all metrics emitted:
166
99
167
- Setting | Description | Environment variable | Constructor parameter
168
- ------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | -------------------------------------------------
169
- ** Metric namespace** | Logical container where all metrics will be placed e.g. ` ServerlessAirline ` | ` POWERTOOLS_METRICS_NAMESPACE ` | ` namespace `
170
- ** Service** | Optionally, sets ** service** metric dimension across all metrics e.g. ` payment ` | ` POWERTOOLS_SERVICE_NAME ` | ` service `
100
+ | Setting | Description | Environment variable | Constructor parameter |
101
+ | ----------------------| ---------------------------------------------------------------------------------| --------------------------------| -----------------------|
102
+ | ** Metric namespace** | Logical container where all metrics will be placed e.g. ` ServerlessAirline ` | ` POWERTOOLS_METRICS_NAMESPACE ` | ` namespace ` |
103
+ | ** Service** | Optionally, sets ** service** metric dimension across all metrics e.g. ` payment ` | ` POWERTOOLS_SERVICE_NAME ` | ` service ` |
171
104
172
105
!!! tip "Use your application or main service as the metric namespace to easily group all metrics"
173
106
@@ -198,7 +131,7 @@ Setting | Description | Environment variable | Constructor parameter
198
131
@Override
199
132
@Metrics(namespace = "ExampleApplication", service = "booking")
200
133
public Object handleRequest(Object input, Context context) {
201
- ...
134
+ // ...
202
135
}
203
136
}
204
137
```
@@ -224,7 +157,7 @@ You can create metrics using `putMetric`, and manually create dimensions for all
224
157
public Object handleRequest(Object input, Context context) {
225
158
metricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
226
159
metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
227
- ...
160
+ // ...
228
161
}
229
162
}
230
163
```
@@ -234,6 +167,35 @@ You can create metrics using `putMetric`, and manually create dimensions for all
234
167
!!! note "Metrics overflow"
235
168
CloudWatch EMF supports a max of 100 metrics. Metrics utility will flush all metrics when adding the 100th metric while subsequent metrics will be aggregated into a new EMF object, for your convenience.
236
169
170
+
171
+ ### Adding high-resolution metrics
172
+
173
+ You can create [ high-resolution metrics] ( https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics )
174
+ passing a ` storageResolution ` to the ` putMetric ` method:
175
+
176
+ === "HigResMetricsHandler.java"
177
+
178
+ ```java hl_lines="3 13"
179
+ import software.amazon.lambda.powertools.metrics.Metrics;
180
+ import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
181
+ import software.amazon.cloudwatchlogs.emf.model.StorageResolution;
182
+
183
+ public class MetricsEnabledHandler implements RequestHandler<Object, Object> {
184
+
185
+ MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
186
+
187
+ @Override
188
+ @Metrics(namespace = "ExampleApplication", service = "booking")
189
+ public Object handleRequest(Object input, Context context) {
190
+ // ...
191
+ metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT, StorageResolution.HIGH);
192
+ }
193
+ }
194
+ ```
195
+
196
+ !!! info "When is it useful?"
197
+ High-resolution metrics are data with a granularity of one second and are very useful in several situations such as telemetry, time series, real-time incident management, and others.
198
+
237
199
### Flushing metrics
238
200
239
201
The ` @Metrics ` annotation ** validates** , ** serializes** , and ** flushes** all your metrics. During metrics validation,
0 commit comments