Prometheus is an open-source tool for monitoring and alerting. It is a data model & query language which can help the user to analyze the application and monitor the performance of the infrastructure. Over a decade, many companies and organizations have adopted Prometheus for its lightweight feature.
It is used for recording numeric time series and for monitoring dynamic service-oriented architecture. It collects the data in the form of time series, which is built through a pull model.
For starters, understanding Prometheus can be tricky. In this article, you will gather an overview about Prometheus, the architecture, the highlighted features, how to install it on ubuntu server and other references to get deeper knowledge on related topics.
What does Prometheus do?
Prometheus stores the metrics sent by multiple exporters into chunks of data and it stores for 90 days, which means the data older than 90 days is not available is Prometheus (this limit can be changed).
Every exporter has a set of queries that fetches information about a specific set of metrics, all the raw metrics fetched by the exporter, which can be used for alerting or visualization purposes.
The data metrics are being collected by different types of exporters that have different use cases. The list of exporters currently in use are:
- Node Exporter: Used to export OS and system-level metrics for the Linux server, which will allow us to measure various machine resources like memory, disk, CPU utilization, etc. By Specifying the targets of the node.
- WMI Exporter: Used to export OS and system-level metrics window server, which is used to export the metrics such as CPU, Memory, and disk I/O and also use to monitor the IIS site application and network interface.
- Blackbox Exporter: It is a tool that is used to monitor HTTP, DNS, TCP endpoints such as its status code, success/failure, etc.
Prometheus does not support the intended dashboard to view the metrics. It is used only for fetching specific queries and data for the log. Therefore, the metrics collected from different types of the exporter are stored into Prometheus.
- Prometheus is a multi-dimensional data model with a time series by name and key/value pair
- The Prometheus server scrapes and stores time-series data
- It supports multiple modes of graphs and dashboard which can be visualized with Grafana
- It supports alert manager to handle alerts and notify the team either with Slack, PagerDuty, etc.
- It uses service discovery to discovery targets
Installing Prometheus on ubuntu server:
- Login into the AWS console, choose the ubuntu server 18.04 and launch the server with the basic configuration
Note: Open port 9090 in the security group along with SSH and HTTP port.
- Login into the server with sudo privilege and update the yum package
1sudo yum update -y
- Create a Prometheus user, required directories, and make Prometheus user as the owner of those directories.
12345sudo useradd --no-create-home --shell /bin/false prometheussudo mkdir /etc/prometheussudo mkdir /var/lib/prometheussudo chown prometheus:prometheus /etc/prometheussudo chown prometheus:prometheus /var/lib/prometheus
- Download the source using curl, unzip the package, and rename the extracted folder to prometheus-files.
1234curl -LO https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gztar -xvf prometheus-2.17.1.linux-amd64.tar.gzmv prometheus-2.17.1.linux-amd64 prometheus-files
- Copy prometheus and promtool binary from prometheus-files folder to /usr/local/bin and change the ownership to prometheus user.
1234sudo cp prometheus-files/prometheus /usr/local/bin/sudo cp prometheus-files/promtool /usr/local/bin/sudo chown prometheus:prometheus /usr/local/bin/prometheussudo chown prometheus:prometheus /usr/local/bin/promtool
- Move the consoles and console_libraries directories from prometheus-files to /etc/prometheus folder and change the ownership to prometheus user.
1234sudo cp -r prometheus-files/consoles /etc/prometheussudo cp -r prometheus-files/console_libraries /etc/prometheussudo chown -R prometheus:prometheus /etc/prometheus/consolessudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
- Create the prometheus.yml file.
1sudo vi /etc/prometheus/prometheus.yml
- Copy the following contents to the prometheus.yml file.
12345678global:scrape_interval: 10sscrape_configs:- job_name: 'prometheus'scrape_interval: 5sstatic_configs:- targets: ['localhost:9090']
- Change the ownership of the file to prometheus user.
1sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
- Create a prometheus service file.
1234567891011121314151617[Unit]Description=PrometheusWants=network-online.targetAfter=network-online.target[Service]User=prometheusGroup=prometheusType=simpleExecStart=/usr/local/bin/prometheus \--config.file /etc/prometheus/prometheus.yml \--storage.tsdb.path /var/lib/prometheus/ \--web.console.templates=/etc/prometheus/consoles \--web.console.libraries=/etc/prometheus/console_libraries[Install]WantedBy=multi-user.target
- Reload the systemctl service to register the prometheus service and start the prometheus service.
12sudo systemctl daemon-reloadsudo systemctl start prometheus
- Check the prometheus service status using the following command.
1sudo systemctl status prometheus
- Let us access Prometheus portal on the web browser
As always, if you have any more queries or feedback, feel free to drop a comment and we will get back to you right away.
If you want to learn more about Prometheus go to our website and check more courses on DevOps.
We have just touched the tip of the iceberg and there is a lot more about Prometheus. Would you like to know more on Prometheus? Visit our blogsite
That is all folks!