spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Too Many Metrics in AWS Cloudwatch by default generate costs even with Free Tier

Open mangei opened this issue 1 year ago • 3 comments

Type: Feature / Question

Is your feature request related to a problem? Please describe. Currently I am developing an web application with spring boot and I wanted to integrate AWS to collect logs and metrics in AWS Cloudwatch, so that I get informed, if there is e.g. an ERROR-alarm or resources run short. I found this project and in general it worked very well [1]. There is just one (big) thing that concerns me:

I setup a fresh AWS account for this new project and I am using the Free Tier offer from AWS. My guess was, that for simple testing purposes, it will be a good fit. After setting up the dev and production environment a lot of metrics got published (> 200 per instance) to be viewed in Cloudwatch. grafik

On the next day, I got an budget alert notification, that I actually generated real costs. I was wondering and alarmed! grafik

Looking closely at the Free Tier offer it states, that just 10 Metrics are free per month, and every addition metrics costs 0.30 $ per month [2]. A quick calculation let to 60.00 $ per month just for the default metrics per environment. So in my case for dev+prod, 120.00 $.

I immediately disabled the Cloudwatch metrics integration, but I further read [3], that deletion of metrics is not possible and will stay at least 15 months in AWS.

Q: What is the retention period of all metrics? You can publish and store custom metrics down to one-second resolution. Extended retention of metrics was launched on November 1, 2016, and enabled storage of all metrics for customers from the previous 14 days to 15 months.

Q: Can I delete any metrics? CloudWatch does not support metric deletion. Metrics expire based on the retention schedules described above.

This results in total cost of of 900.00 $, or in my case 1,800.00, for just "enabling the default metrics integration" and to see what I can get. This is a shocking information for a pet project with no income. :(

Describe alternatives you've considered If this is really the case, AWS Cloudwatch can not be used as a playground for metrics and alternatives like Prometheus with Grafana have to be used.

Describe the solution you'd like Maybe my understaning is not correct (please tell me), or the default settings for publishing metrics are way to wild, so that it way to easy to generate actual high expenses for the simplest test-/side-/pet-project that wants to use the AWS Metrics integration. In such a case, a big warning should be placed in the documentation and it shoud be easily configurable, which metrics get published (maybe this is already possible).

I would be curious what you think about this, or if I did something "wrong", or if I am mistaken with some of my assumptions, or if this is how it is currently.

Thanks a lot.

Best regards, Manuel

Additional context [1] https://docs.awspring.io/spring-cloud-aws/docs/3.0.0/reference/html/index.html#cloudwatch-metrics [2] https://aws.amazon.com/cloudwatch/pricing/ [3] https://aws.amazon.com/cloudwatch/faqs/

Cross reference to StackOverflow question: https://stackoverflow.com/questions/76984906/spring-cloud-aws-creates-too-many-metrics-in-aws-cloudwatch-by-default-and-there

mangei avatar Aug 26 '23 13:08 mangei

Hi @mangei, re: the cost / bill - don't fret as your bill won't be as high as you have estimated. You only get charged for CloudWatch metrics for the duration you are publishing data to them. Specifically, AWS' quoted monthly charge is pro-rated by the hour for each metric you publish/send data for. This is mentioned in the AWS docs, though it could be made clearer - e.g. see https://aws.amazon.com/cloudwatch/pricing/ - "All CloudWatch metrics are prorated on an hourly basis...".

So, if you've disabled publishing of the metrics you won't be charged any extra for your previously created but unused metrics. Your bill will depend on how long you had your sample app running with the CloudWatch metrics integration enabled, but hopefully it should only be a few cents, or a few dollars at most.

Neil.

neiljbrown avatar Aug 28 '23 11:08 neiljbrown

@neiljbrown Thank you for your response and for highlighting the hourly charging. As you mentioned, the bill stopped increasing and remained within a very low cost range.

AWS will charge 1/720 of the monthly costs for the custom metrics for every hour in which you push at least one data point to the custom metric (counting 30 * 24 = 720 hours in a month)

Source: https://stackoverflow.com/questions/48115239/aws-cloudwatch-unused-custom-metrics-retention-and-pricing-2018#comment118806959_55481797

In addition to my initial all-or-nothing approach, I have included a MetricFilter to only publish individual metrics that are important to me right now:

@Configuration
@Profile("production")
public class MeterConfig {

    private static final List<String> acceptedMetrics = List.of(
            "system.cpu.usage",
            "jvm.memory.committed",
            "jvm.memory.used",
            "disk.free",
            "disk.total"
    );

    @Bean
    public MeterFilter meterFilter() {
        return MeterFilter.denyUnless(id -> acceptedMetrics.contains(id.getName()));
    }
    
}

See 57.5 Customizing individual metrics:
https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/production-ready-metrics.html

However, a warning in the documentation would be appreciated, so that nobody will be as surprised as I was. :)

mangei avatar Aug 28 '23 21:08 mangei

@mangei docs update does make sense. Would you like to contribute it?

maciejwalkowiak avatar Jan 14 '24 11:01 maciejwalkowiak