Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const funcAlarm1 = funcMetric.with({ unit: "Milliseconds", period: 600 })
.createAlarm("SlowUrlProcessing", { threshold: 1000, evaluationPeriods: 5 });
// Also create a dashboard to track this.
const dashboard = new awsx.cloudwatch.Dashboard("TopicData", {
widgets: [
new awsx.cloudwatch.SingleNumberMetricWidget({
title: "Requests in the last minute",
width: 10,
metrics: awsx.lambda.metrics.invocations({
function: subscription.func,
statistic: "Sum",
period: 60,
}),
}),
new awsx.cloudwatch.LineGraphMetricWidget({
title: "Lambda duration",
width: 14,
// Place a line on the graph to indicate where our alarm will be triggered.
annotations: new awsx.cloudwatch.HorizontalAnnotation(funcAlarm1),
// Log our different p90/p95/p99 latencies
metrics: [
funcMetric.with({ extendedStatistic: 90, label: "Duration p90" }),
funcMetric.with({ extendedStatistic: 95, label: "Duration p95" }),
funcMetric.with({ extendedStatistic: 98, label: "Duration p99" }),
],
}),
],
});
}
}
});
// Get the metric for the lambda that processing our topic requests.
const funcMetric = awsx.lambda.metrics.duration({ function: subscription.func });
// Create an alarm if this lambda takes more than 1000ms to complete in a period of 10 minutes over
// at least five periods in a row.
const funcAlarm1 = funcMetric.with({ unit: "Milliseconds", period: 600 })
.createAlarm("SlowUrlProcessing", { threshold: 1000, evaluationPeriods: 5 });
// Also create a dashboard to track this.
const dashboard = new awsx.cloudwatch.Dashboard("TopicData", {
widgets: [
new awsx.cloudwatch.SingleNumberMetricWidget({
title: "Requests in the last minute",
width: 10,
metrics: awsx.lambda.metrics.invocations({
function: subscription.func,
statistic: "Sum",
period: 60,
}),
}),
new awsx.cloudwatch.LineGraphMetricWidget({
title: "Lambda duration",
width: 14,
// Place a line on the graph to indicate where our alarm will be triggered.
annotations: new awsx.cloudwatch.HorizontalAnnotation(funcAlarm1),
// Log our different p90/p95/p99 latencies
const clusterAlarm = clusterMetric.createAlarm("alarm" + alarmIndex++, { threshold: 50, evaluationPeriods: 2 });
const userPool = new aws.cognito.UserPool("pool", {});
const userPoolMetric = awsx.cognito.metrics.compromisedCredentialsRisk({ userPool });
const userPoolAlarm = userPoolMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });
const eventRule = new aws.cloudwatch.EventRule("console", {
description: "Capture each AWS Console Sign In",
eventPattern: `{
"detail-type": [
"AWS Console Sign In via CloudTrail"
]
}
`,
});
const eventRuleMetric = awsx.cloudwatch.metrics.events.deadLetterInvocations({ eventRule });
const eventRuleAlarm = eventRuleMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });
const logGroup = new aws.cloudwatch.LogGroup("yada", {
tags: {
Application: "serviceA",
Environment: "production",
},
});
const logGroupMetric = awsx.cloudwatch.metrics.logs.incomingBytes({ logGroup, unit: "Megabytes" });
const logGroupAlarm = logGroupMetric.createAlarm("alarm" + alarmIndex++, { threshold: 512, evaluationPeriods: 2 });
"detail-type": [
"AWS Console Sign In via CloudTrail"
]
}
`,
});
const eventRuleMetric = awsx.cloudwatch.metrics.events.deadLetterInvocations({ eventRule });
const eventRuleAlarm = eventRuleMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });
const logGroup = new aws.cloudwatch.LogGroup("yada", {
tags: {
Application: "serviceA",
Environment: "production",
},
});
const logGroupMetric = awsx.cloudwatch.metrics.logs.incomingBytes({ logGroup, unit: "Megabytes" });
const logGroupAlarm = logGroupMetric.createAlarm("alarm" + alarmIndex++, { threshold: 512, evaluationPeriods: 2 });