... | ... | @@ -44,8 +44,19 @@ Api of the `backend` pod is used to collect information and manipulate system re |
|
|
|
|
|
#### Overview
|
|
|
|
|
|
[Prometheus](https://prometheus.io) is an open-source system monitoring tool. It is specifically targeted for highly dynamic container environments, such as `kubernetes`. It offers monitoring of many aspects of environment and automatic alerting. Prometheus works by collecting metrics from monitored targets by scraping the `/metrics` HTTP endpoint and stores these metrics to storage. We can use PromQL language to then query the stored metrics.
|
|
|
[Prometheus](https://prometheus.io) is an open-source system monitoring tool. It is specifically targeted for highly dynamic container environments, such as `kubernetes`. It offers monitoring of many aspects of environment and automatic alerting. Prometheus works by collecting metrics from monitored targets by scraping the `/metrics` HTTP endpoint and stores these metrics to storage. We can use PromQL language to then query the stored metrics. While Prometheus offers some basic visualization tools, we will use Grafana to visualize the collected metrics.
|
|
|
|
|
|
#### Setup
|
|
|
|
|
|
When installing Prometheus, we have two options: manually or using [helm](https://helm.sh/) package manager. Since Prometheus is stateful application(it saves the data from current session to storage), it is not recommended to set it up manually(unless we need some customizable feature), as it would be difficult. Instead, we will use `helm`, the package manager for k8s, for the initial setup. |
|
|
\ No newline at end of file |
|
|
When installing Prometheus, we have two options: manually or using [helm](https://helm.sh/) package manager. Since Prometheus is stateful application(it saves the data from current session to storage), it is not recommended to set it up manually(unless we need some customizable feature), as it would be difficult. Instead, we will use `helm`, the package manager for k8s, for the initial setup.
|
|
|
|
|
|
#### Config
|
|
|
Before we install Prometheus, we need to enable the `metrics` page on our `backend` and `frontend` pods so Prometheus can collect metrics. This could be done manually but in practice we are going to use Prometheus [exporters](https://prometheus.io/docs/instrumenting/exporters/). Exporters can be either language specific libraries or Docker images. There are plenty of officially supported exporters for the most popular services. For our `backend` pod, which runs a Flask webserver, we are going to use [prometheus-flask-exporter](https://github.com/rycus86/prometheus_flask_exporter). Enabling basic metrics scraping with this exporter is as easy as two lines of code:
|
|
|
```python
|
|
|
from flask import Flask
|
|
|
from prometheus_flask_exporter import PrometheusMetrics
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
metrics = PrometheusMetrics(app)
|
|
|
```
|
|
|
|