Skip to content

Commit 70a67db

Browse files
authored
feat(cw): update bedrock cloudwatch dashboard (#829)
* feat(bedrockcw): add missing metrics
1 parent bd3634d commit 70a67db

File tree

4 files changed

+302
-56
lines changed

4 files changed

+302
-56
lines changed

apidocs/classes/BedrockCwDashboard.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ represents the scope for all the resources.
3030

3131
this is a a scope-unique id.
3232

33-
**props**: [`BedrockCwDashboardProps`](../interfaces/BedrockCwDashboardProps.md)
33+
**props**: [`BedrockCwDashboardProps`](../interfaces/BedrockCwDashboardProps.md) = `{}`
3434

3535
user provided props for the construct.
3636

@@ -74,7 +74,7 @@ The tree node.
7474
7575
#### Parameters
7676

77-
**props**: [`ModelMonitoringProps`](../interfaces/ModelMonitoringProps.md)
77+
**props**: [`ModelMonitoringProps`](../interfaces/ModelMonitoringProps.md) = `{}`
7878

7979
#### Returns
8080

@@ -92,7 +92,7 @@ The tree node.
9292

9393
**modelId**: `string`
9494

95-
**props**: [`ModelMonitoringProps`](../interfaces/ModelMonitoringProps.md)
95+
**props**: [`ModelMonitoringProps`](../interfaces/ModelMonitoringProps.md) = `{}`
9696

9797
#### Returns
9898

apidocs/interfaces/ModelMonitoringProps.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ The properties for the ModelMonitoringProps class.
1010

1111
## Properties
1212

13+
### bucketedStepSize?
14+
15+
> `readonly` `optional` **bucketedStepSize**: `string`
16+
17+
***
18+
19+
### imageSize?
20+
21+
> `readonly` `optional` **imageSize**: `string`
22+
23+
***
24+
25+
### inputTokenPrice?
26+
27+
> `readonly` `optional` **inputTokenPrice**: `number`
28+
29+
***
30+
31+
### outputTokenPrice?
32+
33+
> `readonly` `optional` **outputTokenPrice**: `number`
34+
35+
***
36+
1337
### period?
1438

1539
> `readonly` `optional` **period**: `Duration`

src/patterns/gen-ai/aws-bedrock-cw-dashboard/README.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ Thanks to @jimini55, @scoropeza, @PaulVincent707, @Ishanrpatel, @lowelljehu and
4444

4545
This construct provides an Amazon CloudWatch dashboard to monitor metrics on Amazon Bedrock models usage. The specific list of metrics created by this construct is available [here](#default-properties).
4646

47-
> **Note:** Native metrics for Amazon Bedrock don't support dimensions beyond model ID. If a single account is hosting multiple workloads in the same region, the Bedrock metrics would be aggregated across all workloads.
47+
These metrics can be used for a variety of use cases including:
48+
49+
- Comparing latency between different models using the InvocationLatency metric with ModelId dimension
50+
- Measuring token count (input & output) to assist in purchasing provisioned throughput by analyzing the InputTokenCount and OutputTokenCount
51+
- Detecting and alerting on throttling with an CloudWatch Alarm with the InvocationThrottles metric
52+
53+
For a specific model, if input/output tokens cost is specified, a widget with on-demand input and total tokens cost will be added. Please refer to the [Amazon Bedrock Pricing page](https://aws.amazon.com/bedrock/pricing/) for details about pricing.
54+
55+
> **Note:** Native runtime metrics for Amazon Bedrock don't support dimensions beyond model ID. If a single account is hosting multiple workloads in the same region, the Bedrock metrics would be aggregated across all workloads.
4856
4957
Here is a minimal deployable pattern definition:
5058

@@ -55,13 +63,20 @@ import { Construct } from 'constructs';
5563
import { Stack, StackProps, Aws } from 'aws-cdk-lib';
5664
import { BedrockCwDashboard } from '@cdklabs/generative-ai-cdk-constructs';
5765

58-
const bddashboard = new BedrockCwDashboard(this, 'BedrockDashboardConstruct', {});
66+
const bddashboard = new BedrockCwDashboard(this, 'BedrockDashboardConstruct');
5967

6068
// provides monitoring for a specific model
61-
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0', {});
69+
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0');
70+
71+
// provides monitoring for a specific model with on-demand pricing calculation
72+
// pricing details are available here: https://aws.amazon.com/bedrock/pricing/
73+
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0', {
74+
inputTokenPrice: 0.00025,
75+
outputTokenPrice: 0.00125
76+
});
6277

6378
// provides monitoring of all models
64-
bddashboard.addAllModelsMonitoring({});
79+
bddashboard.addAllModelsMonitoring();
6580
```
6681

6782
Optionally, you can also use the [Bedrock models](../../../cdk-lib/bedrock/models.ts) to access the modelId:
@@ -75,8 +90,7 @@ import { bedrock, BedrockCwDashboard } from '@cdklabs/generative-ai-cdk-construc
7590
// provides monitoring for a specific model
7691
bddashboard.addModelMonitoring(
7792
'claude3haiku',
78-
bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0.modelId,
79-
{}
93+
bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0.modelId
8094
);
8195

8296
...
@@ -97,6 +111,15 @@ bddashboard.add_model_monitoring(
97111
model_id: 'anthropic.claude-3-haiku-20240307-v1:0'
98112
)
99113

114+
# provides monitoring for a specific model with on-demand pricing calculation
115+
# pricing details are available here: https://aws.amazon.com/bedrock/pricing/
116+
bddashboard.add_model_monitoring(
117+
model_name: 'claude3haiku',
118+
model_id: 'anthropic.claude-3-haiku-20240307-v1:0',
119+
input_token_price: 0.00025,
120+
output_token_price: 0.00125
121+
)
122+
100123
# provides monitoring of all models
101124
bddashboard.add_all_models_monitoring()
102125
```
@@ -132,7 +155,7 @@ Parameters
132155

133156
### addModelMonitoring()
134157

135-
Provide metrics for a specific model id in Bedrock
158+
Provide runtime metrics for a specific model id in Bedrock. If input/output tokens cost is specified, a widget with on-demand input and total tokens cost will be added.
136159

137160
@param {string} modelName - Model name as it will appear in the dashboard row widget.
138161

@@ -142,7 +165,7 @@ Provide metrics for a specific model id in Bedrock
142165

143166
### addAllModelsMonitoring()
144167

145-
Add a new row to the dashboard providing metrics across all model ids in Bedrock
168+
Add a new row to the dashboard providing runtime metrics across all model ids in Bedrock.
146169

147170
@param {ModelMonitoringProps} props - user provided props for the monitoring.
148171

@@ -153,16 +176,27 @@ Out-of-the-box implementation of the construct without any override will set the
153176
### Dashboard
154177

155178
- Dashboard name is ```BedrockMetricsDashboard```
179+
- CfnOutput containing the created CloudWatch dashboard URL
156180

157181
### addModelMonitoring
158182

159183
- Period (the period over which the specified statistic is applied) is set to one hour
160184
- The following metrics are displayed for the model specified:
161185
- InputTokenCount
162186
- OutputTokenCount
187+
- OutputImageCount
163188
- InvocationLatency (min, max, average)
164189
- Invocations (sample count)
165190
- InvocationClientErrors
191+
- InvocationServerErrors
192+
- InvocationThrottles
193+
- LegacyModelInvocations
194+
If pricing is specified, a new widget will be added with the following metrics:
195+
- Input Token Cost
196+
- Output Token Cost
197+
- Total Token Cost
198+
199+
More details for each one of the metrics can be found in the [documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/monitoring.html#runtime-cloudwatch-metrics)
166200

167201
### addAllModelsMonitoring
168202

@@ -173,6 +207,11 @@ Out-of-the-box implementation of the construct without any override will set the
173207
- InvocationLatency (min, max, average)
174208
- Invocations (sample count)
175209
- InvocationClientErrors
210+
- InvocationServerErrors
211+
- InvocationThrottles
212+
- LegacyModelInvocations
213+
214+
More details for each one of the metrics can be found in the [documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/monitoring.html#runtime-cloudwatch-metrics)
176215

177216
## Cost
178217

@@ -181,6 +220,7 @@ You are responsible for the cost of the AWS services used while running this con
181220
We recommend creating a budget through [AWS Cost Explorer](http://aws.amazon.com/aws-cost-management/aws-cost-explorer/) to help manage costs. Prices are subject to change. For full details, refer to the pricing webpage for each AWS service used in this solution:
182221

183222
- [Amazon CloudWatch pricing](https://aws.amazon.com/cloudwatch/pricing/)
223+
- [Amazon Bedrock pricing](https://aws.amazon.com/bedrock/pricing/)
184224

185225
## Security
186226

0 commit comments

Comments
 (0)