Skip to content

Adding cloudwatch as destination for prometheus #1742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Paramadon
Copy link
Contributor

@Paramadon Paramadon commented Jun 23, 2025

Description of the issue

Currently Prometheus does not support Cloudwatch as a destination, users can only use Cloudwatch Logs or AMP in order to get Prometheus metrics. This pr adds the ability to have Cloudwatch be a destination for Prometheus metrics.

Description of changes

Adding Cloudwatch destination for Prometheus metrics.

Verified metrics pop up on cloudwatch:
Screenshot 2025-06-23 at 5 33 09 PM

Test setup:

agent config:

{
  "agent": {
    "metrics_collection_interval": 15,
    "run_as_user": "root",
    "debug": true
  },
  "metrics": {
    "metrics_destinations": {
            "cloudwatch":{}
    },
    "metrics_collected": {
      "prometheus": {
        "prometheus_config_path": "/home/ec2-user/prometheus/prometheus.yaml"
      }
    },
    "append_dimensions": {
      "ImageId": "${aws:ImageId}",
      "InstanceId": "${aws:InstanceId}",
      "InstanceType": "${aws:InstanceType}",
      "AutoScalingGroupName": "${aws:AutoScalingGroupName}"
    },
    "aggregation_dimensions": [
      [
        "InstanceId",
        "InstanceType"
      ]
    ]
  }
}

Prometheus yaml:

global:
  scrape_interval: 5s
  scrape_timeout: 5s
scrape_configs:
  - job_name: 'prometheus_test_job'
    static_configs:
      - targets: ['localhost:8101']

Prometheus metrics file:

prometheus_test_untyped{include="yes",prom_type="untyped"} 1
# TYPE prometheus_test_counter counter
prometheus_test_counter{include="yes",prom_type="counter"} 1
# TYPE prometheus_test_counter_exclude counter
prometheus_test_counter_exclude{include="no",prom_type="counter"} 1
# TYPE prometheus_test_gauge gauge
prometheus_test_gauge{include="yes",prom_type="gauge"} 500
# TYPE prometheus_test_histogram histogram
prometheus_test_histogram_sum{include="yes",prom_type="histogram"} 300
prometheus_test_histogram_count{include="yes",prom_type="histogram"} 75
prometheus_test_histogram_bucket{include="yes",le="0",prom_type="histogram"} 1
prometheus_test_histogram_bucket{include="yes",le="0.5",prom_type="histogram"} 2
prometheus_test_histogram_bucket{include="yes",le="2.5",prom_type="histogram"} 3
prometheus_test_histogram_bucket{include="yes",le="5",prom_type="histogram"} 4
prometheus_test_histogram_bucket{include="yes",le="+Inf",prom_type="histogram"} 5

Starting prometheus server:
sudo python3 -m http.server 8101 --directory /home/ec2-user/prometheus &> /dev/null &

@Paramadon Paramadon requested a review from a team as a code owner June 23, 2025 21:34
@Paramadon Paramadon force-pushed the prometheusPMDSupport branch 3 times, most recently from 338c803 to fc7f40a Compare June 23, 2025 21:42
Comment on lines 17 to 16
if conf.IsSet(LogsKey) {
destinations = append(destinations, common.CloudWatchLogsKey)
}
if conf.IsSet(MetricsKey) {
if conf.IsSet(prometheusremotewrite.AMPSectionKey) {
destinations = append(destinations, common.AMPKey)
}

if !conf.IsSet(common.ConfigKey(common.MetricsKey, common.MetricsDestinationsKey)) || conf.IsSet(common.ConfigKey(common.MetricsKey, common.MetricsDestinationsKey, common.CloudWatchKey)) {
destinations = append(destinations, common.CloudWatchKey)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a function in common that will get the destinations for you. It's currently used in the jmx pipeline.

destinations := common.GetMetricsDestinations(conf)

Comment on lines 64 to 66
// otel_prometheus - cloudwatch
// telegraf_prometheus - cloudwatch logs
// telegraf_prometheus - cloudwatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Makes it seem like the telegraf prometheus plugin can send to CW/PMD and CWL/PLE when that is not the case.

@Paramadon Paramadon force-pushed the prometheusPMDSupport branch 3 times, most recently from 06facb7 to 31c9339 Compare June 24, 2025 14:21
@Paramadon Paramadon changed the title Adding cloudwatch as destination Adding cloudwatch as destination for prometheus Jun 24, 2025
@Paramadon Paramadon force-pushed the prometheusPMDSupport branch from 31c9339 to f339746 Compare June 24, 2025 20:34
@Paramadon Paramadon force-pushed the prometheusPMDSupport branch from 933e2d9 to 7196713 Compare June 24, 2025 21:29
@Paramadon Paramadon force-pushed the prometheusPMDSupport branch from aef2b67 to e341736 Compare June 27, 2025 18:08
@Paramadon Paramadon force-pushed the prometheusPMDSupport branch from e341736 to 92af811 Compare June 27, 2025 18:22
@@ -33,7 +34,7 @@ func TestTranslators(t *testing.T) {
},
},
want: []pipeline.ID{
pipeline.MustNewIDWithName("metrics", "prometheus/amp"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intention to default to CloudWatch (PMD) if no destinations are set? If so, I think this should be prometheus/cloudwatch, right?

Comment on lines +151 to +152
log.Println(testCase.want)
log.Println(got)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over debug logs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants