AWS: CloudWatch — Multi source query: collecting metrics from an external Prometheus
Tags: monitoring, aws, todayilearned, devops
Published: 2023-12-16 16:00:07

---
title: AWS: CloudWatch — Multi source query: collecting metrics from an external Prometheus
published: true
date: 2023-12-16 16:00:07 UTC
tags: monitoring,aws,todayilearned,devops
canonical_url: https://rtfm.co.ua/en/aws-cloudwatch-multi-source-query-collecting-metrics-from-an-external-prometheus/
---

### AWS: CloudWatch — Multi source query: collecting metrics from an external Prometheus

![](https://cdn-images-1.medium.com/max/1024/1*JZAYCCIy6Muaxtz2FKpu0w.png)

Another interesting announcement from the last re:Invent is that CloudWatch has added the ability to collect metrics from external resources (see a very interesting report [AWS re:Invent 2023 — Cloud operations for today, tomorrow, and beyond (COP227)](https://youtu.be/3dF9cdkZ8kI?si=NIE232Vpe0pb6xgt&t=1329)).

That is, we can now create graphs and/or alerts not only from the default metrics of CloudWatch itself, but also use CloudWatch connectors to connect metrics collection from Amazon Managed Service for Prometheus, regular Prometheus, Amazon OpenSearch Service, Amazon RDS for MySQL and PostgreSQL, CSV files from S3 buckets, and even Microsoft Azure Monitor.

### Connecting metrics from a vanilla Prometheus

We have Prometheus on a bare-metal EC2 instance with port 9090 open — let’s try it here first, then look at VictoriaMetrics in EKS.

Go to CloudWatch Metrics, and here now we have a new tab — _Multi source query_:

![](https://cdn-images-1.medium.com/max/1024/0*orN_MMn1HJeXV2yO.png)

Choose Prometheus:

![](https://cdn-images-1.medium.com/max/1024/0*XN_8jD6HoIhHVF5k.png)

Set the parameters.

The login-password fields are required, so even if Prometheus does not require authentication, you should set some values here.

Below you can configure the network settings. For example, if your Prometheus is available only within a VPC, then you can select the VPC and subnets here:

![](https://cdn-images-1.medium.com/max/1024/0*phWgjoqhA7eS219T.png)

Click on the _Create data source_ — CloudWatch will start creating a CloudFormation stack in which it will create a Lambda function that will actually collect data from our data sourcing:

![](https://cdn-images-1.medium.com/max/1024/0*Mjl-CygTKGsP7Hto.png)

![](https://cdn-images-1.medium.com/max/1024/0*JOAwB65Cg2lNQ9AH.png)

Go back to the CloudWatch, where we now have a new data source:

![](https://cdn-images-1.medium.com/max/941/0*Px2cGDomz82C6Cw6.png)

And we can get metrics from it:

![](https://cdn-images-1.medium.com/max/1024/0*4veDyEKCnDztm8IY.png)

### VictoriaMetrics, EKS, and VPC

Now we have VictoriaMetrics in Kubernetes, see [VictoriaMetrics: deploying a Kubernetes monitoring stack](https://rtfm.co.ua/en/victoriametrics-deploying-a-kubernetes-monitoring-stack/).

For CloudWatch to be able to collect metrics, we need to open access to VMSingle.

Here we have two options — either regular Ingress/ALB, see [`values.yaml`](https://github.com/VictoriaMetrics/helm-charts/blob/master/charts/victoria-metrics-k8s-stack/values.yaml#L138), or via VMAuth with authentication, see [VictoriaMetrics: VMAuth - Proxy, Authentication and Authorization](https://rtfm.co.ua/en/victoriametrics-vmauth-proxy-authentication-and-authorization/).

And when adding a data source to CloudWatch, the only difference from the regular Prometheus is the URI:

- Prometheus has an URI `hostname:9090/api/v1/labels`
- VictoriaMetrics **with VMSingle** has its URI `hostname:8429/prometheus/api/v1/labels`

So in the data source, add it as [https://vmsingle.ops.example.co/prometheus/.](https://vmsingle.ops.example.co/prometheus/.)

### Editing and deleting a data source

I didn’t see where and how to change any parameters or remove data source from the CloudWatch panel.

It seems that so far, data source can only be deleted through CloudFormation by deleting a corresponding stack.

If you need to change some parameters, the only way O found is in the Lambda function itself.

For example, to edit the Prometheus URL, you can update it in the function’s environment variables:

![](https://cdn-images-1.medium.com/max/876/0*PpS9TvzOrxeY5wNg.png)

But anyway, it all looks very cool.

_Originally published at_ [_RTFM: Linux, DevOps, and system administration_](https://rtfm.co.ua/en/aws-cloudwatch-multi-source-query-collecting-metrics-from-an-external-prometheus/)_._

* * *