Skip to main content

cdk-monitoring-constructs

Project description

CDK Monitoring Constructs

Gitpod Ready-to-Code NPM version PyPI version NuGet version Maven Central Mergify

Easy-to-use CDK constructs for monitoring your AWS infrastructure.

  • Easily add commonly-used alarms using predefined properties
  • Generate concise Cloudwatch dashboards that indicate your alarms
  • Extend the library with your own extensions or custom metrics
  • Consume the library in multiple languages (see below)

Installation

TypeScript

https://www.npmjs.com/package/cdk-monitoring-constructs

In your package.json:

{
  "dependencies": {
    "cdk-monitoring-constructs": "^1.0.0",

    // peer dependencies
    "@aws-cdk/aws-apigatewayv2-alpha": "^2.18.0-alpha.0",
    "@aws-cdk/aws-appsync-alpha": "^2.18.0-alpha.0",
    "@aws-cdk/aws-redshift-alpha": "^2.18.0-alpha.0",
    "@aws-cdk/aws-synthetics-alpha": "^2.18.0-alpha.0",
    "aws-cdk-lib": "^2.18.0",
    "constructs": "^10.0.5"

    // (your other dependencies)
  }
}
Java

See https://mvnrepository.com/artifact/io.github.cdklabs/cdkmonitoringconstructs

Python

See https://pypi.org/project/cdk-monitoring-constructs/

C#

See https://www.nuget.org/packages/Cdklabs.CdkMonitoringConstructs/

Features

See API for complete auto-generated documentation.

You can also browse the documentation at https://constructs.dev/packages/cdk-monitoring-constructs/

Item Monitoring Alarms Notes
AWS API Gateway (REST API) (.monitorApiGateway()) TPS, latency, errors Latency, error count/rate To see metrics, you have to enable Advanced Monitoring
AWS API Gateway V2 (HTTP API) (.monitorApiGatewayV2HttpApi()) TPS, latency, errors Latency, error count/rate To see route level metrics, you have to enable Advanced Monitoring
AWS AppSync (GraphQL API) (.monitorAppSyncApi()) TPS, latency, errors Latency, error count/rate, low/high TPS
AWS Billing (.monitorBilling()) AWS account cost Requires enabling the Receive Billing Alerts option in AWS Console / Billing Preferences
AWS Certificate Manager (.monitorCertificate()) Certificate expiration Days until expiration
AWS CloudFront (.monitorCloudFrontDistribution()) TPS, traffic, latency, errors Error rate, low/high TPS
AWS CloudWatch Synthetics Canary (.monitorSyntheticsCanary()) Latency, error count/rate Error count/rate, latency
AWS CodeBuild (.monitorCodeBuildProject()) Build counts (total, successful, failed), failed rate, duration Failed build count/rate, duration
AWS DynamoDB (.monitorDynamoTable()) Read and write capacity provisioned / used Consumed capacity, throttling, latency, errors
AWS DynamoDB Global Secondary Index (.monitorDynamoTableGlobalSecondaryIndex()) Read and write capacity, indexing progress, throttled events
AWS EC2 (.monitorEC2Instances()) CPU, disk operations, network
AWS EC2 Auto Scaling Groups (.monitorAutoScalingGroup()) Group size, instance status
AWS ECS (.monitorFargateService(), .monitorEc2Service(), .monitorSimpleFargateService(), monitorSimpleEc2Service(), .monitorQueueProcessingFargateService(), .monitorQueueProcessingEc2Service()) System resources and task health Unhealthy task count, running tasks count, CPU/memory usage, and bytes processed by load balancer (if any) Use for ecs-patterns load balanced ec2/fargate constructs (NetworkLoadBalancedEc2Service, NetworkLoadBalancedFargateService, ApplicationLoadBalancedEc2Service, ApplicationLoadBalancedFargateService)
AWS ElastiCache (.monitorElastiCacheCluster()) CPU/memory usage, evictions and connections
AWS Glue (.monitorGlueJob()) Traffic, job status, memory/CPU usage
AWS Kinesis Data Analytics (.monitorKinesisDataAnalytics) Up/Downtime, CPU/memory usage, KPU usage, checkpoint metrics, and garbage collection metrics Downtime
AWS Kinesis Data Stream (.monitorKinesisDataStream()) Put/Get/Incoming Record/s and Throttling Iterator max age
AWS Kinesis Firehose (.monitorKinesisFirehose()) Number of records, requests, latency
AWS Lambda (.monitorLambdaFunction()) Latency, errors, iterator max age Latency, errors, throttles, iterator max age Optional Lambda Insights metrics (opt-in) support
AWS Load Balancing (.monitorNetworkLoadBalancer(), .monitorFargateApplicationLoadBalancer(), .monitorFargateNetworkLoadBalancer(), .monitorEc2ApplicationLoadBalancer(), .monitorEc2NetworkLoadBalancer()) System resources and task health Unhealthy task count, running tasks count, (for Fargate/Ec2 apps) CPU/memory usage Use for FargateService or Ec2Service backed by a NetworkLoadBalancer or ApplicationLoadBalancer
AWS OpenSearch/Elasticsearch (.monitorOpenSearchCluster(), .monitorElasticsearchCluster()) Indexing and search latency, disk/memory/CPU usage Indexing and search latency, disk/memory/CPU usage, cluster status
AWS RDS (.monitorRdsCluster()) Query duration, connections, latency, disk/CPU usage Disk and CPU usage
AWS Redshift (.monitorRedshiftCluster()) Query duration, connections, latency, disk/CPU usage Disk and CPU usage
AWS S3 Bucket (.monitorS3Bucket()) Bucket size and number of objects
AWS SecretsManager (.monitorSecretsManagerSecret()) Days since last rotation Days since last rotation
AWS SNS Topic (.monitorSnsTopic()) Message count, size, failed notifications Failed notifications
AWS SQS Queue (.monitorSqsQueue(), .monitorSqsQueueWithDlq()) Message count, age, size Message count, age, DLQ incoming messages
AWS Step Functions (.monitorStepFunction(), .monitorStepFunctionActivity(), monitorStepFunctionLambdaIntegration(), .monitorStepFunctionServiceIntegration()) Execution count and breakdown per state Duration, failed, failed rate, aborted, throttled, timed out executions
AWS Web Application Firewall (.monitorWebApplicationFirewallAcl()) Allowed/blocked requests
CloudWatch Logs (.monitorLog()) Patterns present in the log group
Custom metrics (.monitorCustom()) Addition of custom metrics into the dashboard (each group is a widget) Supports anomaly detection

Getting started

Create monitoring stack and facade

Important note: Please, do NOT import anything from the /dist/lib package. This is unsupported and might break any time.

Create an instance of MonitoringFacade, which is the main entry point:

export interface MonitoringStackProps extends DeploymentStackProps {
  // ...
}

export class MonitoringStack extends DeploymentStack {
  constructor(parent: App, name: string, props: MonitoringStackProps) {
    super(parent, name, props);

    const monitoring = new MonitoringFacade(this, "Monitoring", {
      // Define all necessary props
    });

    // Setup your monitoring
    monitoring
      .addLargeHeader("Storage")
      .monitorDynamoTable({ /* table1 */ })
      .monitorDynamoTable({ /* table2 */ })
      .monitorDynamoTable({ /* table3 */ })
      // ...and more
  }
}

Set up your monitoring

Once the facade is created, you can use it to call methods like .monitorLambdaFunction() and chain them together to define your monitors.

You can also use facade methods to add your own widgets, headers of various sizes, and more.

Customize actions

Alarms should have an action setup, otherwise they are not very useful. Currently, we support notifying an SNS queue.

const onAlarmTopic = new Topic(this, "AlarmTopic");

const monitoring = new MonitoringFacade(this, "Monitoring", {
  // ...other props
  alarmFactoryDefaults: {
    // ....other props
    action: new SnsAlarmActionStrategy({ onAlarmTopic }),
  },
});

You can override the default topic for any alarm like this:

monitoring
  .monitorSomething(something, {
    addSomeAlarm: {
      Warning: {
        // ...other props
        threshold: 42,
        actionOverride: new SnsAlarmActionStrategy({ onAlarmTopic }),
      }
    }
  });

Custom metrics

For simply adding some custom metrics, you can use .monitorCustom() and specify your own title and metric groups. Each metric group will be rendered as a single graph widget, and all widgets will be placed next to each other. All the widgets will have the same size, which is chosen based on the number of groups to maximize dashboard space usage.

Custom metric monitoring can be created for simple metrics, simple metrics with anomaly detection and search metrics. The first two also support alarming.

Custom monitoring

If you want even more flexibility, you can create your own Dashboard Segment.

This is a general procedure on how to do it:

  1. Extend the Monitoring ckass
  2. Override the widgets() method (and/or similar ones)
  3. Leverage the metric factor and alarm factory, provided by the base class (you can create additional factories, if you will)
  4. Add all alarms to .addAlarm() so they are visible to the user and being placed on the alarm summary dashboard

Both of these monitoring base classes are dashboard segments, so you can add them to your monitoring by calling .addSegment().

Monitoring Scopes

With CDK Monitoring Constructs, you can monitor complete CDK construct scopes. It will automatically discover all monitorable resources within the scope (recursively)) and add them to your dashboard.

monitoring.monitorScope(stack);

You can also specify default alarms for any specific resource and disable automatic monitoring for it as well.

monitoring.monitorScope(stack, {
  lambda: {
    props: {
      addLatencyP50Alarm: {
        Critical: { maxLatency: Duration.seconds(10) },
      },
    },
  },
  billing: { enabled: false },
});

Contributing/Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Project details


Release history Release notifications | RSS feed

This version

1.3.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-monitoring-constructs-1.3.0.tar.gz (859.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_monitoring_constructs-1.3.0-py3-none-any.whl (861.1 kB view details)

Uploaded Python 3

File details

Details for the file cdk-monitoring-constructs-1.3.0.tar.gz.

File metadata

File hashes

Hashes for cdk-monitoring-constructs-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7b5fa424d10164d0feaa93264b8a916139ed0cc47183df2325dd70d4bd435fc7
MD5 f990d5b94a4ae9799908530e7b3d1d61
BLAKE2b-256 f526cefa0288088256e3bda3e55240110dd7f2ba5bd1bce04e566f05cd11a739

See more details on using hashes here.

File details

Details for the file cdk_monitoring_constructs-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_monitoring_constructs-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56abe3be71c99a69e9ad33fe77939f55b25a394a33d3603ef9a2f407a7563461
MD5 abeb1b801ddb021db059097d25b82d69
BLAKE2b-256 5eab8663c582be7f7cf26c815767f3d32178aee94f6cc8bf4f9fc37736f26baf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page