Prometheus on Docker
In this article, we shall explore how to run Prometheus as a docker container, and also see how it captures and displays application metrics.
What is Prometheus
Prometheus is a time series database that can scrape time-series data through HTTP pull at given time intervals. It is good to store metrics about applications.
We use Prometheus in our company to store and analyze application metrics of our spring-boot micro-services.
Why on Docker
Prometheus is officially released as a docker container - and is the best way to use it for learning. It takes away the pain of installing its dependencies and Prometheus itself. Official docker documentation is available here.
Run
Prometheus is configured through yml files. Let us create a folder and put a configuration file in it first.
mkdir ~/docker/prometheus
And let us create a yml file
touch prometheus.yml
And now run docker image by providing newly created folder as a shared volume
docker run \
--detach \
--name prometheus \
--publish 9090:9090 \
--volume /Users/hsingh/docker/prometheus:/etc/prometheus \
prom/prometheus
Test
Prometheus exposes its metrics in its format. So let us use it.
First, open http://localhost:9090/metrics to understand the format and also see what data is being exposed by Prometheus as metrics.
The format is simple - multiple lines of
any_label data
Edit prometheus.yml file to read this:
global:
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
scrape_configs: --> it defines scrape jobs - usually 1 per application we wish to monitor.
rest all are self-explanatory
Note: targets is an array. So we can monitor multiple instances of the same application - useful for multi-instance micro-services.
Restart docker image after updating yml. The documentation says that Prometheus auto-reloads. It didn't happen in my case.
Now to see metrics in Prometheus, open localhost:9090.
Got to Menu:: Status > Targets
It tells the jobs that are currently running in Prometheus - i.e. applications being monitored. You should see an entry for prometheus itself.
Go to Menu:: Graph
Enter any metric in the text box. e.g. 'prometheus_target_interval_length_seconds'. And press the "Execute" button. We should see a table format of data. Change tab to "Graph" and we can see the graphical representation of the same data
Conclusion
We have explored
- running Prometheus as a docker container
- tested using Prometheus's metrics
In our company, we do not use Prometheus in isolation. Our spring boot micro-services are monitored using
- Micro-meter (middleware to expose spring boot metrics in Prometheus format)
- Prometheus (collects metric as time series)
- Grafana (for visualization)
This is a very informative blog; thanks for sharing! I would like to add that ReactJS is the best JavaScript library for front-end developers. It is best for developing user interfaces and related components. It employs the MVC architecture, with a different table of presentation and data availability.
ReplyDeleteThanks for sharing the valuable information about an RPA developer career. I also thought of investing in polishing my skills via freelancing, and I got Eiliasna.com. The experts here help me execute the big clients' tasks and have great exposure. Visit-https://eiliana.com/technology/hire-rpa-developers