diff --git a/README.md b/README.md index 4240ffe8..23db5a71 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,41 @@ const flow = new OnDemandFlow(stack, 'OnDemandFlow', { }); ``` -## EventBridge notifications +## Monitoring + + +### Metrcis + +Each flow reports the following metrics in the `AWS/AppFlow` namespace: + +|Metric name|Description| +|---|---| +|FlowExecutionsStarted|The number of flow runs started.| +|FlowExecutionsFailed|The number of failed flow runs.| +|FlowExecutionsSucceeded|The number of successful flow runs.| +|FlowExecutionTime|The interval, in milliseconds, between the time the flow starts and the time it finishes.| +|FlowExecutionRecordsProcessed|The number of records that Amazon AppFlow attempted to transfer for the flow run. This metric counts all records that Amazon AppFlow processed internally. The processed records include those that transferred successfully and those that failed to transfer because the flow run failed.| + + +It can be consume by CloudWatch alert using as in the example below: + + +```ts +import { IFlow } from '@cdklabs/cdk-appflow'; +import { Stack } from 'aws-cdk-lib'; + +declare const flow: IFlow; +declare const stack: Stack; + +const metric = flow.metricFlowExecutionsStarted() +metric.createAlarm(stack, "FlowExecutionsStartedAlarm", { + threshold: 1000, + evaluationPeriods: 2 +}) +``` + + +### EventBridge notifications Each flow publishes events to the default EventBridge bus: diff --git a/src/core/flows/flow-base.ts b/src/core/flows/flow-base.ts index 254300cd..856da82c 100644 --- a/src/core/flows/flow-base.ts +++ b/src/core/flows/flow-base.ts @@ -36,10 +36,35 @@ export interface IFlow extends IResource { onRunCompleted(id: string, options?: OnEventOptions): Rule; + + /** + * Creates a metric to report the number of flow runs started. + * @param options + */ metricFlowExecutionsStarted(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of failed flow runs. + * @param options + */ metricFlowExecutionsFailed(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of successful flow runs. + * @param options + */ metricFlowExecutionsSucceeded(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + * @param options + */ metricFlowExecutionTime(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + * @param options + */ metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric; /**