Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus metrics scraping of docker tasks in ECS

I have multiple clusters in ECS, each cluster has multiple services, each service runs more than 1 task. Each task exposes /metrics with different values, on random port. I'd like to do some kind of dynamic discovery and scrape those metrics (each task has different port and different IP, because they run on multiple container instances), group together tasks' metrics from same service and scrape them using prometheus. How should I do that?

like image 409
a_z Avatar asked Jan 09 '19 00:01

a_z


People also ask

How does Prometheus scraping work?

Prometheus gathers metrics from different systems by scraping data from HTTP endpoints. It uses this information to identify issues, such as when an endpoint is missing or should not exist or when a time-series pattern indicates a problem.

What is Prometheus scraper?

The Application Performance Monitoring Prometheus Scraper is a plug-in that allows you to scrape metrics in the Prometheus exposition text format from HTTP target endpoints and view the metrics using the Metrics Explorer from the Oracle Cloud Infrastructure Monitoring service.

How do I enable container insights for ECS?

You can enable Container Insights on all new clusters by default, or on an individual cluster as you create it. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/ . In the navigation pane, choose Account Settings. Select the check box at the bottom of the page to enable the Container Insights default.

Can Prometheus monitor AWS?

Monitor and alert on containers running on AWS and on-premises. You can quickly set up Amazon Managed Service for Prometheus to collect and query metrics from AWS container services including Amazon EKS, Amazon ECS, and AWS Fargate.


1 Answers

We had the same challenge, and there were two approaches:

  1. Tag EC2 instance based on running tasks, then find EC2 instances in Prometheus based on tags. This worked well when we have one task per instance because the metrics port is known. There are possibly ways to extend this and support mukltiple tasks.
  2. Run a task per EC2 instance that is used as the exporter for all the tasks running on that instance. It interrogates ECS, finds that tasks and the listening ports per task and scrapes all tasks. In Prometheus, you can then find all EC2 instances in the cluster and scrape this exporter in each one. Obviously you will need to label the metrics based on the task they were read from.

if I had to do it again, I would consider using Consul to register the tasks and discover them in Prometheus. if you are already using Consul, this direction could be a good one to try.

Hope this helps.

like image 70
Moshe B. Avatar answered Sep 30 '22 05:09

Moshe B.