Skip to content
v2.277.0

PromQLAlarm L2 construct ​

A CloudWatch Alarm based on a PromQL query expression.

Example ​

ts
new cloudwatch.PromQLAlarm(this, 'HighLatencyAlarm', {
  alarmDescription: 'P99 latency exceeds 500ms for 5 minutes',
  query: 'histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5',
  evaluationInterval: Duration.seconds(60),
  pendingPeriod: Duration.seconds(300),
  recoveryPeriod: Duration.seconds(600),
});
python
cloudwatch.PromQLAlarm(self, "HighLatencyAlarm",
    alarm_description="P99 latency exceeds 500ms for 5 minutes",
    query="histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5",
    evaluation_interval=Duration.seconds(60),
    pending_period=Duration.seconds(300),
    recovery_period=Duration.seconds(600)
)
java
PromQLAlarm.Builder.create(this, "HighLatencyAlarm")
        .alarmDescription("P99 latency exceeds 500ms for 5 minutes")
        .query("histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5")
        .evaluationInterval(Duration.seconds(60))
        .pendingPeriod(Duration.seconds(300))
        .recoveryPeriod(Duration.seconds(600))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
new PromQLAlarm(this, "HighLatencyAlarm", new PromQLAlarmProps {
    AlarmDescription = "P99 latency exceeds 500ms for 5 minutes",
    Query = "histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5",
    EvaluationInterval = Duration.Seconds(60),
    PendingPeriod = Duration.Seconds(300),
    RecoveryPeriod = Duration.Seconds(600)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
cloudwatch.NewPromQLAlarm(this, jsii.String("HighLatencyAlarm"), &PromQLAlarmProps{
	AlarmDescription: jsii.String("P99 latency exceeds 500ms for 5 minutes"),
	Query: jsii.String("histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 0.5"),
	EvaluationInterval: awscdk.Duration_Seconds(jsii.Number(60)),
	PendingPeriod: awscdk.Duration_*Seconds(jsii.Number(300)),
	RecoveryPeriod: awscdk.Duration_*Seconds(jsii.Number(600)),
})

Initializer ​

ts
new PromQLAlarm(scope: Construct, id: string, props: PromQLAlarmProps)
python
PromQLAlarm(scope: Construct, id: str, props: PromQLAlarmProps)
java
new PromQLAlarm(Construct scope, String id, PromQLAlarmProps props)
csharp
new PromQLAlarm(Construct scope, string id, PromQLAlarmProps props)
go
NewPromQLAlarm(Scope Construct, Id *string, Props PromQLAlarmProps)

Construct Props ​

actionsEnabledoptionalbooleanactions_enabledoptionalboolactionsEnabledoptionalBooleanActionsEnabledoptionalboolActionsEnabledoptional*bool= true#
Whether the actions for this alarm are enabled.
alarmDescriptionoptionalstringalarm_descriptionoptionalstralarmDescriptionoptionalStringAlarmDescriptionoptionalstringAlarmDescriptionoptional*string#
Description for the alarm.

Default: No description

alarmNameoptionalstringalarm_nameoptionalstralarmNameoptionalStringAlarmNameoptionalstringAlarmNameoptional*string#
Name of the alarm.

Default: Automatically generated name

evaluationIntervalDurationevaluation_intervalDurationevaluationIntervalDurationEvaluationIntervalDurationEvaluationIntervalDurationrequired#
The frequency at which the alarm is evaluated.

Must be between 10 seconds and 3600 seconds.

pendingPeriodoptionalDurationpending_periodoptionalDurationpendingPeriodoptionalDurationPendingPeriodoptionalDurationPendingPeriodoptionalDuration#
The duration that a contributor must continuously breach before the contributor transitions to ALARM state.

Default: No pending period

querystringquerystrqueryStringQuerystringQuery*stringrequired#
The PromQL query that the alarm evaluates.
recoveryPeriodoptionalDurationrecovery_periodoptionalDurationrecoveryPeriodoptionalDurationRecoveryPeriodoptionalDurationRecoveryPeriodoptionalDuration#
The duration that a contributor must continuously not be breaching before it transitions back to the OK state.

Default: No recovery period

Properties ​

alarmArnstringalarm_arnstralarmArnStringAlarmArnstringAlarmArn*string#
ARN of this alarm.
alarmNamestringalarm_namestralarmNameStringAlarmNamestringAlarmName*string#
Name of this alarm.
A reference to a Alarm resource.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.

Methods ​

addAlarmAction(...actions: IAlarmAction[]): voiddef add_alarm_action(self, actions: IAlarmAction) -> Nonepublic void addAlarmAction(IAlarmAction actions)public void AddAlarmAction(IAlarmAction actions)func AddAlarmAction(Actions IAlarmAction)#
Trigger this action if the alarm fires.

Typically SnsAction or AutoScalingAction.

addAlarmMuteRule(id: string, options: AlarmMuteRuleOptions): AlarmMuteRuledef add_alarm_mute_rule(self, id: str, options: AlarmMuteRuleOptions) -> AlarmMuteRulepublic AlarmMuteRule addAlarmMuteRule(String id, AlarmMuteRuleOptions options)public AlarmMuteRule AddAlarmMuteRule(string id, AlarmMuteRuleOptions options)func AddAlarmMuteRule(Id *string, Options AlarmMuteRuleOptions) AlarmMuteRule#
Add an alarm mute rule.
addInsufficientDataAction(...actions: IAlarmAction[]): voiddef add_insufficient_data_action(self, actions: IAlarmAction) -> Nonepublic void addInsufficientDataAction(IAlarmAction actions)public void AddInsufficientDataAction(IAlarmAction actions)func AddInsufficientDataAction(Actions IAlarmAction)#
Trigger this action if there is insufficient data to evaluate the alarm.

Typically SnsAction or AutoScalingAction.

addOkAction(...actions: IAlarmAction[]): voiddef add_ok_action(self, actions: IAlarmAction) -> Nonepublic void addOkAction(IAlarmAction actions)public void AddOkAction(IAlarmAction actions)func AddOkAction(Actions IAlarmAction)#
Trigger this action if the alarm returns from breaching state into ok state.

Typically SnsAction or AutoScalingAction.

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

fromPromQLAlarmArn(scope: Construct, id: string, alarmArn: string): IAlarm@staticmethod def from_prom_ql_alarm_arn(scope: Construct, id: str, alarm_arn: str) -> IAlarmpublic static IAlarm fromPromQLAlarmArn(Construct scope, String id, String alarmArn)public static IAlarm FromPromQLAlarmArn(Construct scope, string id, string alarmArn)func FromPromQLAlarmArn(Scope Construct, Id *string, AlarmArn *string) IAlarmstatic#
Import an existing CloudWatch alarm provided an ARN.
fromPromQLAlarmName(scope: Construct, id: string, alarmName: string): IAlarm@staticmethod def from_prom_ql_alarm_name(scope: Construct, id: str, alarm_name: str) -> IAlarmpublic static IAlarm fromPromQLAlarmName(Construct scope, String id, String alarmName)public static IAlarm FromPromQLAlarmName(Construct scope, string id, string alarmName)func FromPromQLAlarmName(Scope Construct, Id *string, AlarmName *string) IAlarmstatic#
Import an existing CloudWatch alarm provided a Name.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
renderAlarmRule(): stringdef render_alarm_rule(self, ) -> strpublic String renderAlarmRule()public string RenderAlarmRule()func RenderAlarmRule() *string#
AlarmRule indicating ALARM state for Alarm.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.