Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-cdk/aws-cloudwatch

Package Overview
Dependencies
Maintainers
5
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-cdk/aws-cloudwatch

The CDK Construct Library for AWS::CloudWatch

  • 1.95.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
168K
increased by19.76%
Maintainers
5
Weekly downloads
 
Created

What is @aws-cdk/aws-cloudwatch?

@aws-cdk/aws-cloudwatch is an AWS CDK library that allows you to define and manage Amazon CloudWatch resources using code. It provides a high-level, object-oriented abstraction to create and manage CloudWatch Alarms, Dashboards, Metrics, and more.

What are @aws-cdk/aws-cloudwatch's main functionalities?

Creating CloudWatch Alarms

This code sample demonstrates how to create a CloudWatch Alarm that monitors the CPU utilization of an EC2 instance. The alarm triggers if the CPU utilization exceeds 80% for three consecutive evaluation periods.

const cloudwatch = require('@aws-cdk/aws-cloudwatch');
const cdk = require('@aws-cdk/core');

const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');

const alarm = new cloudwatch.Alarm(stack, 'MyAlarm', {
  metric: new cloudwatch.Metric({
    namespace: 'AWS/EC2',
    metricName: 'CPUUtilization',
    dimensions: { InstanceId: 'i-1234567890abcdef0' },
  }),
  threshold: 80,
  evaluationPeriods: 3,
  comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
});

app.synth();

Creating CloudWatch Dashboards

This code sample demonstrates how to create a CloudWatch Dashboard and add a graph widget to it. The graph widget displays the CPU utilization of an EC2 instance.

const cloudwatch = require('@aws-cdk/aws-cloudwatch');
const cdk = require('@aws-cdk/core');

const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');

const dashboard = new cloudwatch.Dashboard(stack, 'MyDashboard', {
  dashboardName: 'MyDashboard',
});

dashboard.addWidgets(new cloudwatch.GraphWidget({
  title: 'EC2 CPU Utilization',
  left: [new cloudwatch.Metric({
    namespace: 'AWS/EC2',
    metricName: 'CPUUtilization',
    dimensions: { InstanceId: 'i-1234567890abcdef0' },
  })],
}));

app.synth();

Creating Custom Metrics

This code sample demonstrates how to create a custom CloudWatch metric and set up an alarm for it. The custom metric is defined with a specific namespace and dimensions.

const cloudwatch = require('@aws-cdk/aws-cloudwatch');
const cdk = require('@aws-cdk/core');

const app = new cdk.App();
const stack = new cdk.Stack(app, 'MyStack');

const customMetric = new cloudwatch.Metric({
  namespace: 'MyNamespace',
  metricName: 'MyCustomMetric',
  dimensions: { MyDimension: 'MyValue' },
});

const alarm = new cloudwatch.Alarm(stack, 'MyCustomMetricAlarm', {
  metric: customMetric,
  threshold: 100,
  evaluationPeriods: 1,
  comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});

app.synth();

Other packages similar to @aws-cdk/aws-cloudwatch

Keywords

FAQs

Package last updated on 26 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc