Checking the API properties
Prometheus is a popular monitoring total that can monitor and check API services in any microservice application. It can check the number of concurrent request transactions, the number of responses at a certain period, and the total incoming requests of an endpoint. To apply Prometheus to FastAPI applications, first, we need to install the following module:
pip install starlette-exporter
Then, we add PrometheusMiddleware
to the application and enable its endpoint to observe the API’s properties at runtime. The following script shows the application setup with the Prometheus monitoring module:
from starlette_exporter import PrometheusMiddleware, handle_metrics app = FastAPI() app.add_middleware(PrometheusMiddleware, app_name=”osms”) app.add_route(“/metrics”, handle_metrics)
Here, we add PrometheusMiddleware
using the add_middleware()
method of FastAPI. Then...