Skip to content

Commit 23313c0

Browse files
committed
revamp cloudwatch
1 parent 676d0b3 commit 23313c0

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

src/content/docs/aws/services/cloudwatch.md

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
---
22
title: "CloudWatch"
3-
linkTitle: "CloudWatch"
43
description: Get started with AWS CloudWatch on LocalStack
54
persistence: supported
65
tags: ["Free"]
76
---
87

8+
## Introduction
9+
910
CloudWatch is a comprehensive monitoring and observability service that Amazon Web Services (AWS) provides.
1011
It allows you to collect and track metrics, collect and monitor log files, and set alarms.
1112
CloudWatch provides valuable insights into your AWS resources, applications, and services, enabling you to troubleshoot issues, optimize performance, and make informed decisions.
1213

1314
LocalStack allows you to use CloudWatch APIs on your local machine to create and manage CloudWatch resources, such as custom metrics, alarms, and log groups, for local development and testing purposes.
14-
The supported APIs are available on our [API coverage page]({{< ref "coverage_cloudwatch" >}}), which provides information on the extent of CloudWatch's integration with LocalStack.
15-
16-
{{< callout >}}
17-
We have introduced an all-new LocalStack-native [CloudWatch provider]({{< ref "/user-guide/aws/cloudwatch" >}}) and recently made this one the default.
18-
19-
With the new provider we have migrated from storing data in Python objects within the Moto backend to a more robust system.
20-
21-
Now, metrics are efficiently stored in SQLite, and alarm resources are managed using LocalStack stores.
22-
23-
- Various enhancements have been made to attain greater feature parity with AWS.
24-
- The provider is engineered to ensure thread safety, facilitating smooth concurrent operations.
25-
- There’s a significant improvement in the integrity and durability of data.
26-
- The new provider allows for more efficient data retrieval.
27-
28-
Currently, it is still possible to switch back to the old provider using `PROVIDER_OVERRIDE_CLOUDWATCH=v1` in your LocalStack configuration.
29-
{{< /callout >}}
15+
The supported APIs are available on our [API coverage page](), which provides information on the extent of CloudWatch's integration with LocalStack.
3016

3117
## Getting started
3218

@@ -38,13 +24,13 @@ You can get the name for your Lambda Functions using the [`ListFunctions`](https
3824
Fetch the Log Groups using the [`DescribeLogGroups`](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html) API.
3925
Run the following command to get the Log Group name:
4026

41-
{{< command >}}
42-
$ awslocal logs describe-log-groups
43-
{{< / command >}}
27+
```bash
28+
awslocal logs describe-log-groups
29+
```
4430

4531
The output should look similar to the following:
4632

47-
```sh
33+
```bash
4834
{
4935
"logGroups": [
5036
{
@@ -68,14 +54,14 @@ The output should look similar to the following:
6854
Get the log streams for the Log Group using the [`DescribeLogStreams`](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogStreams.html) API.
6955
Run the following command to get the Log Stream name:
7056

71-
{{< command >}}
72-
$ awslocal logs describe-log-streams \
57+
```bash
58+
awslocal logs describe-log-streams \
7359
--log-group-name /aws/lambda/serverless-local-hello
74-
{{< / command >}}
60+
```
7561

7662
The output should look similar to the following:
7763

78-
```sh
64+
```bash
7965
{
8066
"logStreams": [
8167
{
@@ -95,14 +81,14 @@ The output should look similar to the following:
9581
You can now fetch the log events using the [`GetLogEvents`](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_GetLogEvents.html) API.
9682
Run the following command to get the logs:
9783

98-
{{< command >}}
99-
$ awslocal logs get-log-events \
84+
```bash
85+
awslocal logs get-log-events \
10086
--log-group-name '/aws/lambda/serverless-local-hello' --log-stream-name '2023/05/02/[$LATEST]853a59d0767cfaf10d6b29a6790d8b03'
101-
{{< / command >}}
87+
```
10288

10389
The output should look similar to the following:
10490

105-
```sh
91+
```bash
10692
{
10793
"events": [
10894
{
@@ -126,9 +112,9 @@ The output should look similar to the following:
126112
}
127113
```
128114

129-
{{< callout "tip" >}}
115+
:::note
130116
You can use [filters](https://docs.aws.amazon.com/cli/latest/reference/logs/filter-log-events.html) or [queries](https://docs.aws.amazon.com/cli/latest/reference/logs/get-query-results.html) with a licensed LocalStack edition to refine your results.
131-
{{< /callout >}}
117+
:::
132118

133119
## Metric Alarms
134120

@@ -145,8 +131,8 @@ With metric alarms, you can create customized thresholds and define actions base
145131

146132
To get started with creating an alarm in LocalStack using the `awslocal` integration, use the following command:
147133

148-
{{< command >}}
149-
$ awslocal cloudwatch put-metric-alarm \
134+
```bash
135+
awslocal cloudwatch put-metric-alarm \
150136
--alarm-name my-alarm \
151137
--metric-name Orders \
152138
--namespace test \
@@ -156,21 +142,21 @@ $ awslocal cloudwatch put-metric-alarm \
156142
--period 30 \
157143
--statistic Minimum \
158144
--treat-missing notBreaching
159-
{{< / command >}}
145+
```
160146

161147
To monitor the status of the alarm, open a separate terminal and execute the following command:
162148

163-
{{< command >}}
164-
$ watch "awslocal cloudwatch describe-alarms --alarm-names my-alarm | jq '.MetricAlarms[0].StateValue'"
165-
{{< / command >}}
149+
```bash
150+
watch "awslocal cloudwatch describe-alarms --alarm-names my-alarm | jq '.MetricAlarms[0].StateValue'"
151+
```
166152

167153
Afterward, you can add some data that will cause a breach and set the `metric-alarm` state to **ALARM** using the following command:
168154

169-
{{< command >}}
170-
$ awslocal cloudwatch put-metric-data \
155+
```bash
156+
awslocal cloudwatch put-metric-data \
171157
--namespace test \
172158
--metric-data '[{"MetricName": "Orders", "Value": -1}]'
173-
{{< / command >}}
159+
```
174160

175161
Within a few seconds, the alarm state should change to **ALARM**, and eventually, it will go back to **OK** as we configured it to treat missing data points as `not breaching`.
176162
This allows you to observe how the alarm behaves in response to the provided data.
@@ -184,8 +170,8 @@ Currently, only SNS Topics are supported as the target for these actions, and it
184170
Here's an example demonstrating how to set up an alarm that sends a message to the specified topic when entering the **ALARM** state.
185171
Make sure to replace `<topic-arn>` with the valid ARN of an existing SNS topic.
186172

187-
{{< command >}}
188-
$ awslocal cloudwatch put-metric-alarm \
173+
```bash
174+
awslocal cloudwatch put-metric-alarm \
189175
--alarm-name my-alarm \
190176
--metric-name Orders \
191177
--namespace test \
@@ -196,20 +182,30 @@ $ awslocal cloudwatch put-metric-alarm \
196182
--statistic Maximum \
197183
--treat-missing notBreaching \
198184
--alarm-actions <topic-arn>
199-
{{< / command >}}
185+
```
200186

201187
By executing this command, you'll create an alarm named `my-alarm` that monitors the `Orders` metric in the `test` namespace.
202188
If the metric value exceeds the threshold of 50 (using the `GreaterThanThreshold` operator) during a single evaluation period of 300 seconds, the alarm will trigger the specified action on the provided SNS topic.
203189

204-
{{< callout "warning" >}}
190+
:::danger
205191
Please be aware of the following known limitations in LocalStack:
206192
- Anomaly detection and extended statistics are not supported.
207193
- The `unit` values specified in the alarm are ignored.
208194
- Composite alarms are not evaluated.
209195
- Metric streams are not supported.
210-
{{< /callout >}}
196+
:::
197+
198+
## Current Limitations
199+
200+
The following CloudWatch Metrics are not supported:
201+
202+
- Anomaly detection
203+
- Metric streams
204+
- Extended statistics
205+
206+
In addition, the `unit` values specified in the alarm are ignored, and Composite alarms are not evaluated.
211207

212-
## Supported Service Integrations with CloudWatch Metrics
208+
## Supported Service Integrations
213209

214210
LocalStack supports the following AWS services for integration with CloudWatch metrics:
215211

@@ -223,9 +219,9 @@ You can access the Resource Browser by opening the LocalStack Web Application in
223219

224220
The Resource Browser allows you to perform the following actions:
225221

226-
<img src="cloudwatch-log-groups-resource-browser.png" alt="CloudWatch Logs Resource Browser" title="CloudWatch Logs Resource Browser" width="900" />
222+
![CloudWatch Logs Resource Browser](/images/aws/cloudwatch-log-groups-resource-browser.png)
227223

228-
<img src="cloudwatch-metrics-resource-browser.png" alt="CloudWatch Metrics Resource Browser" title="CloudWatch Metrics Resource Browser" width="900" />
224+
![CloudWatch Metrics Resource Browser](/images/aws/cloudwatch-metrics-resource-browser.png)
229225

230226
- **Create Log Group**: Create a new log group by specifying the `Log Group Name`, `KMS Key ID`, and `Tags`.
231227
- **Put metric**: Create a new metric by specifying the `Namespace` and `Metric Data`.

0 commit comments

Comments
 (0)