In the realm of monitoring and observability, Prometheus stands tall as an open-source system designed for capturing and analyzing real-time metrics. Its journey began in 2012 at SoundCloud and has since become a cornerstone in the world of cloud-native computing. This blog post will delve into the core features and architecture that make Prometheus an indispensable tool for ensuring the health and performance of your systems.
Operating on a pull-based system, Prometheus initiates an HTTP request, commonly known as a "scrape," following the configurations outlined in the prometheus.yml file, as discussed below. The resulting response from this scrape request is then stored and parsed in the storage, alongside the metrics associated with the scrape operation.
Key Terminology:
Prometheus Server: The central server responsible for scraping and storing metrics in a time series database.
Scrape: The method employed by the Prometheus server to pull and retrieve metrics.
Target: The clients of Prometheus servers from which it fetches information.
Exporter: Libraries associated with targets, converting and exporting metrics into the Prometheus format.
Alert Manager: The component tasked with the management and handling of alerts.
Let's try it out by performing some simple commands:
Create an ec2 instance in AWS
connect to the ec2 instance via SSH protocol
Before installing anything you have to update your machine “sudo apt-get update”.
sudo apt-get update -y
sudo apt-get upgrade -y
Now let's install the docker
sudo apt-get install docker.io
Pull the Prometheus docker image
sudo docker pull prom/prometheus
Define the configuration file for Prometheus
We pulled the Prometheus image from the docker hub. Let's create the configuration file for Prometheus at “/etc/prometheus/prometheus.yml”.
There are two targets for the Prometheus server. First is your localhost and second is your Ubuntu machine public IP.
Run Prometheus as a Docker container
docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
The Prometheus server will run on port number 9090, which is binded to our Ubuntu machine port 9090.
Configure your security group of AWS EC2 instance.
Select your running Ubuntu machine go to the security group->edit inbound rules->Add Rule. Allow the following ports as shown below.
Launch the Prometheus Dashboard
Open your browser and type- http://18.212.27.132/:9090/targets
Congratulations, we have completely set up the Prometheus in our ec2 instance, and is easily accessible at port 9090.
Setting Up Grafana with Prometheus
To connect Prometheus (running on port 9090) with Grafana (running on port 3000) on the same EC2 instance, you can follow these steps:
Configure Prometheus as a Data Source in Grafana:
Open the Grafana web UI by navigating to
http://your-ec2-instance-ip:3000
in your browser.Log in to Grafana (default credentials are usually admin/admin).
In Grafana, go to the "+" icon on the left sidebar and select "Data Sources."
Click on "Add your first data source" or "Add data source."
Choose "Prometheus" from the list of available data sources.
In the HTTP section, set the URL to
http://ec2-ip:9090
since Prometheus is running on the same machine. If your Grafana and Prometheus are on different machines, replace them with the IP address or DNS name of the Prometheus server.Click "Save & Test" to verify the connection. If successful, you'll see a green "Data source is working" message.
After creating the dashboard, you have the option to incorporate various visualization tools for in-depth data analysis. In the image below, you'll notice that no data is visualized at the moment due to the absence of a query being passed.
Awesome! we did it. We did the whole setup with very easy steps. And we finally connected the Prometheus with Grafana.
In the upcoming blogs, we will try out the real implementation of Prometheus, Grafana with real time data visualization
Happy Learning!