Skip to content

Commit

Permalink
feat(cw): update bedrock cloudwatch dashboard (#829)
Browse files Browse the repository at this point in the history
* feat(bedrockcw): add missing metrics
  • Loading branch information
krokoko authored Nov 29, 2024
1 parent bd3634d commit 70a67db
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 56 deletions.
6 changes: 3 additions & 3 deletions apidocs/classes/BedrockCwDashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ represents the scope for all the resources.

this is a a scope-unique id.

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

user provided props for the construct.

Expand Down Expand Up @@ -74,7 +74,7 @@ The tree node.
#### Parameters

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

#### Returns

Expand All @@ -92,7 +92,7 @@ The tree node.

**modelId**: `string`

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

#### Returns

Expand Down
24 changes: 24 additions & 0 deletions apidocs/interfaces/ModelMonitoringProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ The properties for the ModelMonitoringProps class.

## Properties

### bucketedStepSize?

> `readonly` `optional` **bucketedStepSize**: `string`
***

### imageSize?

> `readonly` `optional` **imageSize**: `string`
***

### inputTokenPrice?

> `readonly` `optional` **inputTokenPrice**: `number`
***

### outputTokenPrice?

> `readonly` `optional` **outputTokenPrice**: `number`
***

### period?

> `readonly` `optional` **period**: `Duration`
56 changes: 48 additions & 8 deletions src/patterns/gen-ai/aws-bedrock-cw-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ Thanks to @jimini55, @scoropeza, @PaulVincent707, @Ishanrpatel, @lowelljehu and

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).

> **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.
These metrics can be used for a variety of use cases including:

- Comparing latency between different models using the InvocationLatency metric with ModelId dimension
- Measuring token count (input & output) to assist in purchasing provisioned throughput by analyzing the InputTokenCount and OutputTokenCount
- Detecting and alerting on throttling with an CloudWatch Alarm with the InvocationThrottles metric

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.

> **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.
Here is a minimal deployable pattern definition:

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

const bddashboard = new BedrockCwDashboard(this, 'BedrockDashboardConstruct', {});
const bddashboard = new BedrockCwDashboard(this, 'BedrockDashboardConstruct');

// provides monitoring for a specific model
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0', {});
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0');

// provides monitoring for a specific model with on-demand pricing calculation
// pricing details are available here: https://aws.amazon.com/bedrock/pricing/
bddashboard.addModelMonitoring('claude3haiku', 'anthropic.claude-3-haiku-20240307-v1:0', {
inputTokenPrice: 0.00025,
outputTokenPrice: 0.00125
});

// provides monitoring of all models
bddashboard.addAllModelsMonitoring({});
bddashboard.addAllModelsMonitoring();
```

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

...
Expand All @@ -97,6 +111,15 @@ bddashboard.add_model_monitoring(
model_id: 'anthropic.claude-3-haiku-20240307-v1:0'
)

# provides monitoring for a specific model with on-demand pricing calculation
# pricing details are available here: https://aws.amazon.com/bedrock/pricing/
bddashboard.add_model_monitoring(
model_name: 'claude3haiku',
model_id: 'anthropic.claude-3-haiku-20240307-v1:0',
input_token_price: 0.00025,
output_token_price: 0.00125
)

# provides monitoring of all models
bddashboard.add_all_models_monitoring()
```
Expand Down Expand Up @@ -132,7 +155,7 @@ Parameters

### addModelMonitoring()

Provide metrics for a specific model id in Bedrock
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.

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

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

### addAllModelsMonitoring()

Add a new row to the dashboard providing metrics across all model ids in Bedrock
Add a new row to the dashboard providing runtime metrics across all model ids in Bedrock.

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

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

- Dashboard name is ```BedrockMetricsDashboard```
- CfnOutput containing the created CloudWatch dashboard URL

### addModelMonitoring

- Period (the period over which the specified statistic is applied) is set to one hour
- The following metrics are displayed for the model specified:
- InputTokenCount
- OutputTokenCount
- OutputImageCount
- InvocationLatency (min, max, average)
- Invocations (sample count)
- InvocationClientErrors
- InvocationServerErrors
- InvocationThrottles
- LegacyModelInvocations
If pricing is specified, a new widget will be added with the following metrics:
- Input Token Cost
- Output Token Cost
- Total Token Cost

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)

### addAllModelsMonitoring

Expand All @@ -173,6 +207,11 @@ Out-of-the-box implementation of the construct without any override will set the
- InvocationLatency (min, max, average)
- Invocations (sample count)
- InvocationClientErrors
- InvocationServerErrors
- InvocationThrottles
- LegacyModelInvocations

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)

## Cost

Expand All @@ -181,6 +220,7 @@ You are responsible for the cost of the AWS services used while running this con
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:

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

## Security

Expand Down
Loading

0 comments on commit 70a67db

Please sign in to comment.