Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push metrics to Prometheus Pushgateway from AWS lambda function

I have an application that I have to monitor every 5 mins. However, that application does not have a /metrics port for Prometheus to directly scrape from and I don't have any control over that application.

As a workaround, I wrote a python program to manually scrape the data, and transforms those data to my own metrics such as gauge and counters. Then I pushed those metrics to pushgateway for Prometheus to scrape from.

Everything worked fine at local. Now, I want to take a step further by using the AWS Lambda function to pull data and generate metrics for me every 5 mins(so I don't have to keep the python program running on my laptop).

My question would be, instead of using:

push_to_gateway(gateway='localhost:9091', job="Monitor", registry=registry)

to push my metrics to pushgateway, what would this be in the lambda function? Also, I believe the pushgateway should be hosted somewhere for AWS to access. How do we achieve that?

like image 208
Ron Zhang Avatar asked Oct 10 '18 16:10

Ron Zhang


1 Answers

You can create the lambda and run it every 5 minutes with a cloudwatch rule. Inside the lambda, instead of calling push_to_gateway, you can just curl the pushgateway. see and example here. Make sure that the gateway is accessible from the lambda - either behind a public ELB or have them both in the same vpc.

like image 115
bazron Avatar answered Nov 03 '22 05:11

bazron