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

@aws-sdk/client-cloudwatch

Package Overview
Dependencies
Maintainers
5
Versions
421
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/client-cloudwatch

AWS SDK for JavaScript Cloudwatch Client for Node.js, Browser and React Native

  • 3.709.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created

What is @aws-sdk/client-cloudwatch?

@aws-sdk/client-cloudwatch is an AWS SDK for JavaScript package that allows developers to interact with Amazon CloudWatch, a monitoring and observability service. It provides functionalities to collect and track metrics, collect and monitor log files, and set alarms.

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

PutMetricData

This feature allows you to publish metric data points to Amazon CloudWatch. The code sample demonstrates how to send a custom metric 'PageViewCount' with a dimension 'PageURL' to the 'MyApp' namespace.

const { CloudWatchClient, PutMetricDataCommand } = require('@aws-sdk/client-cloudwatch');

const client = new CloudWatchClient({ region: 'us-west-2' });

const params = {
  MetricData: [
    {
      MetricName: 'PageViewCount',
      Dimensions: [
        {
          Name: 'PageURL',
          Value: 'example.com/home'
        }
      ],
      Unit: 'Count',
      Value: 1
    }
  ],
  Namespace: 'MyApp'
};

const run = async () => {
  try {
    const data = await client.send(new PutMetricDataCommand(params));
    console.log('Success', data);
  } catch (err) {
    console.error('Error', err);
  }
};

run();

GetMetricData

This feature allows you to retrieve metric data from Amazon CloudWatch. The code sample demonstrates how to get the average CPU utilization for a specific EC2 instance over the past hour.

const { CloudWatchClient, GetMetricDataCommand } = require('@aws-sdk/client-cloudwatch');

const client = new CloudWatchClient({ region: 'us-west-2' });

const params = {
  MetricDataQueries: [
    {
      Id: 'm1',
      MetricStat: {
        Metric: {
          Namespace: 'AWS/EC2',
          MetricName: 'CPUUtilization',
          Dimensions: [
            {
              Name: 'InstanceId',
              Value: 'i-1234567890abcdef0'
            }
          ]
        },
        Period: 300,
        Stat: 'Average'
      },
      ReturnData: true
    }
  ],
  StartTime: new Date(Date.now() - 3600 * 1000),
  EndTime: new Date()
};

const run = async () => {
  try {
    const data = await client.send(new GetMetricDataCommand(params));
    console.log('Success', data);
  } catch (err) {
    console.error('Error', err);
  }
};

run();

PutDashboard

This feature allows you to create or update a CloudWatch dashboard. The code sample demonstrates how to create a dashboard named 'MyDashboard' with a widget that displays the average CPU utilization of a specific EC2 instance.

const { CloudWatchClient, PutDashboardCommand } = require('@aws-sdk/client-cloudwatch');

const client = new CloudWatchClient({ region: 'us-west-2' });

const params = {
  DashboardName: 'MyDashboard',
  DashboardBody: JSON.stringify({
    widgets: [
      {
        type: 'metric',
        x: 0,
        y: 0,
        width: 24,
        height: 6,
        properties: {
          metrics: [
            ['AWS/EC2', 'CPUUtilization', 'InstanceId', 'i-1234567890abcdef0']
          ],
          period: 300,
          stat: 'Average',
          region: 'us-west-2',
          title: 'EC2 Instance CPU'
        }
      }
    ]
  })
};

const run = async () => {
  try {
    const data = await client.send(new PutDashboardCommand(params));
    console.log('Success', data);
  } catch (err) {
    console.error('Error', err);
  }
};

run();

Other packages similar to @aws-sdk/client-cloudwatch

FAQs

Package last updated on 10 Dec 2024

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