Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zambelli committed May 2, 2024
1 parent 0732971 commit cf4dd74
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 26 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Cost Monitoring Construct is a CDK library that helps monitor costs for AWS clou

With the Cost Monitoring Construct, you can share the responsibility of cost management between developers and business holders. This is achieved through the creation of meaningful reports that enable the business team to make informed decisions. Additionally, the Construct generates boilerplate code that can be used to apply these decisions in practice, making it easier to stay on top of your budget.

# How to use Cost Monitoring Construct?
## How to use Cost Monitoring Construct?

To use Cost Monitoring Construct, all you need is to have the AWS CDK installed and set up. Once you have that, you can install the package from the repository of your choice.

For more information on using this Construct in TypeScript checkout the [TypeScript documentation](docs/typescript.md). You can also check the typescript example from [sample folder](https://github.com/DataChefHQ/cost-monitoring-construct/tree/main/sample) on the GitHub repository.

# Why do you need it?
## Why do you need it?

Cloud services can get very expensive, very quickly, especially if you are not careful with your usage. Cost Monitoring Construct helps you to keep an eye on your cloud infrastructure costs so that you can stay within budget. By setting budgets and defining alert strategies, you can take proactive steps to reduce costs before they become a problem.

# How does Cost Monitoring Construct work?
## How does Cost Monitoring Construct work?

Cost Monitoring Construct uses AWS Tagging practice to track resources related to an specific application, creates proper alert with respect to the defined budget limit and provide overview dashbords. The tool is highly customizable and allows you to customize it to your budgeting strategy based on your specific needs.

Expand All @@ -24,19 +24,22 @@ Cost Monitoring Construct provides the following features:
- **Budgets:** Allows you to set budgets for each applications. It will automatically set up alerts to notify you when your actual costs exceed your budgeted costs. It also continues to track the cost and sending alert if an application continues to cost drastically.
- **Integration:** Integrates with various tools and monitoring services, such as AWS Cost Explorer and Datadog.

# What is it useful for?
> [!WARNING]
> Tags used to create and monitor budgets must first be [activated as cost allocation tags](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/activating-tags.html). Ensure your chosen one is activated, otherwise the budgets won't work!
## What is it useful for?

Cost Monitoring Construct is useful for anyone who uses AWS and wants to keep their costs under control. It is particularly useful for:

- **Startups and small businesses:** Cost Monitoring Construct can help startups and small businesses to keep their costs under control during the early stages of growth.
- **Large enterprises:** Cost Monitoring Construct can help large enterprises to optimize their cloud usage and reduce costs across multiple teams and departments.
- **Developers:** Cost Monitoring Construct can help developers to track their usage and costs across multiple projects and services.

# What is this _not_ useful for?
## What is this _not_ useful for?

The Cost Monitoring Construct is not a magical tool that can solve all of your cloud cost problems. In spite of the fact that it can bring clarity and help you to identify areas where you can reduce costs, you must make the necessary decisions about your infrastructure on your own.

# Which programming languages Cost Monitoring Construct supports?
## Which programming languages Cost Monitoring Construct supports?

Cost Monitoring Construct has been developed using JSII technolgy to provide interfaces for different modern programming languages. Currently, it supports the following languages:

Expand All @@ -46,8 +49,7 @@ Cost Monitoring Construct has been developed using JSII technolgy to provide int
- [.NET](https://www.nuget.org/packages/DataChef.CostMonitoringConstruct)
- [Java](https://central.sonatype.com/artifact/co.datachef/costmonitoringconstruct/1.1.0/versions)

> **✏️ Note**
>
> [!NOTE]
> Go will be supported soon but for now you can build it from the source.
If you have any questions or need help with Cost Monitoring Construct, you can reach out to our support team at [support@datachef.co](mailto:support@datachef.co).
39 changes: 39 additions & 0 deletions docs/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Introduction

The Python version of Cost Monitoring Construct derives from the Typescript version, hence refer to [its docs](./typescript.md) for extra details.

To install the Cost Monitoring Construct package, run the following command to download it from PyPI:

```bash
pip install cost-monitoring-construct
```

## Usage

Getting started is very simple: just add the following snippet to your code and adapt it to the situation.

Remember to enable the [cost allocation tags](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/activating-tags.html), otherwise the budgets won't work!

```python
import aws_cdk as cdk
from cost_monitoring_construct import (
ApplicationCostMonitoring,
ApplicationCostMonitoringProps,
)

app = cdk.App()
monitoring_stack = MonitoringStack(app, "MyMonitoringStack")
first_stack = FirstStack(app, "FirstStack")

cost_monitoring = ApplicationCostMonitoring(
applications_stack,
props=ApplicationCostMonitoringProps(
application_name="my-application",
monthly_limit_in_dollars=200,
other_stacks_included_in_budget=[first_stack],
subscribers=["alert@example.com"],
cost_allocation_tag="MyTag"
)
)
cost_monitoring.monitor()
```
17 changes: 9 additions & 8 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ To install the Cost Monitoring Construct package, run the following command to d
npm i cost-monitoring-construct
```

# Usage
## Usage

The easiest way to apply cost monitoring is by using predefined default budget strategies. The `ApplicationCostMonitoring` has default strategy implementation for monitoring budgets per CDK applications, while the `AccountCostMonitoring` has default strategy implementation for monitoring budgets per account. You can also create your own strategy by creating a class that applies to the `IBudgetStrategy` or directly inherits from the `ApplicationCostMonitoring` or `AccountCostMonitoring` class to customize them to your needs.

## `ApplicationCostMonitoring` Class
### `ApplicationCostMonitoring` Class

This is the default strategy for monitoring CDK applications. You have to provide at least one stack by the first parameter of the initializer. If you wish to monitor more stacks, you can pass them as a list to the `otherStacksIncludedInBudget` prop.

The `ApplicationCostMonitoring` will always use the first stack (the first parameter of the initializer) to inject its resources into it. You can create a separate stack and pass it as the first stack if you wish to keep cost monitoring separate from your stacks. The cost monitoring class will monitor both the first stack and stacks from `otherStacksIncludedInBudget`.

⚠️ **Important Note**: ApplicationCostMonitoring uses AWS Tags to track resources' usages. You must activate the `cm:application` tag key under Cost Allocation Tags. The tag key will appear in the AWS console up to 24 hours after at least one AWS resource has been created with that tag.
> [!WARNING] ApplicationCostMonitoring uses AWS Tags to track resources' usages. You must [activate](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/activating-tags.html) your chosen tag key (`cm:application` by default) under Cost Allocation Tags. The tag key will appear in the AWS console up to 24 hours after at least one AWS resource has been created with that tag.
The example below shows how to use `ApplicationCostMonitoring` to track your application in CDK code:

Expand All @@ -29,17 +29,18 @@ const monitoringStack = new MonitoringStack(app, "MyAppMonitoringStack", {});
const firstStack = new FirstStack(app, "FirstStack", {});
const secondStack = new SecondStack(app, "SecondStack", {});
const costMonitoring = new ApplicationCostMonitoring(monitoringStack, {
// the fitst stack ~~~~~~~^~~~~~~
// the first stack ~~~~~~~👆~~~~~~
applicationName: "my-application",
monthlyBudget: 200, // Optional (you can add as many stack as you want)
otherStacksIncludedInBudget: [secondStack, firstStack],
subscribers: ["alert@example.com"],
monthlyLimitInDollars: 200,
otherStacksIncludedInBudget: [secondStack, firstStack], // Optional (you can add as many stacks as you want)
subscribers: ["alert@example.com"], // Optional
costAllocationTag: "MyTag" // Optional, defaults to `cm:application`
});

costMonitoring.monitor();
```

## `IBudgetStrategy` Abstract Class
### `IBudgetStrategy` Abstract Class

This is the abstract base class that all budget strategies must apply to. This Abstract class enforces the implementation for `createDailyBudgets` and `createMonthlyBudgets`. Plus, it provides the `createQuarterlyBudgets` and `createYearlyBudgets` optional to implement.

Expand Down
26 changes: 16 additions & 10 deletions src/application-cost-monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export interface IApplicationCostMonitoringProps extends IBudgetStrategyProps {
}

export class ApplicationCostMonitoringProps implements IApplicationCostMonitoringProps {
/**
* @param applicationName - the name of application to label resources with it.
* @param monthlyLimitInDollars - montly limit in US Dollors.
* @param otherStacksIncludedInBudget - optional other stack to track their resources alog with the default stack.
* @param defaultTopic - default SNS topic name. Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it.
* @param subscribers - list of email address that the CostMonitoring will use to send alerts to.
* @param costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources. Defaults to `cm:application`
*/
constructor(
public applicationName: string,
public monthlyLimitInDollars: number,
Expand All @@ -34,26 +42,24 @@ export class ApplicationCostMonitoring extends IBudgetStrategy {
* @param props.monthlyLimitInDollars - montly limit in US Dollors.
* @param props.defaultTopic - default SNS topic name. Only if provided, the BudgetStratgy creates an SNS topic and send notifications to it.
* @param props.subscribers - list of email address that the CostMonitoring will use to send alerts to.
* @param props.costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources.
* @param props.costAllocationTag - Tag key used to track resources' expenditure. Only if provided, it will be used to tag the application resources. Defaults to `cm:application`
*
* @example tracking budget for an application called `my-application`:
* @example
* Tracking budget for an application called `my-application`
*
* ```ts
* const app = new cdk.App();
* const firstStack = new FirstStack(app, 'FirstStack', {});
* const secondStack = new SecondStack(app, 'SecondStack', {});
* const costMonitoring = new ApplicationCostMonitoring(firstStack, {
* applicationName: 'my-application',
* monthlyLimitInDollars : 200,
*  // Optional (you can add as many stack as you want)
* otherStacksToMonitor: [
* secondStack
* ],
* subscribers: [
* 'alert@example.com'
* ]
* otherStacksToMonitor: [secondStack], // Optional (you can add as many stacks as you want)
* subscribers: ['alert@example.com']
* });
*
* budgetStratgy.monitor();
*
* ```
*/
constructor(stack: Stack, props: ApplicationCostMonitoringProps) {
super(stack, props);
Expand Down

0 comments on commit cf4dd74

Please sign in to comment.