Krud includes a basic example of Micrometer Metrics with Prometheus integration. Once the project starts, the console will display the endpoint exposing the metrics for monitoring. Here's how to set up Prometheus and Grafana to collect and visualize those metrics.
- Download and install Prometheus.
- Edit the existing
prometheus.yml
that comes with the installation and append the following job withinscrape_configs
:# Krud - job_name: "krud" scrape_interval: 5s # Adjust to your desired interval. static_configs: - targets: ["localhost:8080"] # Change to your server's address. metrics_path: "/metrics" scheme: "http" # Change to "https" if your server uses HTTPS. basic_auth: username: "admin" # Change to your username. password: "admin" # Change to your password.
- Start Prometheus and navigate to http://localhost:9090/targets to verify that the
krud
job is up and running. - Navigate to http://localhost:9090/graph and enter
ktor_http_server_requests_seconds
in theExpression
field to see request latency.
Prometheus is now ready. Perform a few Krud requests, for example using the infinite scroll endpoint example. You should get something like this:
- Download and install Grafana.
- Start Grafana and navigate to http://localhost:3000 to log in with the default credentials (admin/admin).
- Add a new Prometheus data source by navigating to
Connnections
>Data Sources
(http://localhost:3000/connections/datasources). - Select
Prometheus
and enter http://localhost:9090 as the URL. - Add the Basic Auth credentials if you set them up in the
prometheus.yml
file. Leave the rest of the settings as default. - Click
Save & Test
to save the data source. - Navigate to
Dashboards
>Create
and selectNew
>Import
. Enter4701
as the Dashboard ID to import the pre-built Ktor dashboard. - Select the Prometheus data source and click
Import
to import the dashboard. - Navigate to the
Ktor
dashboard to view the metrics.
Grafana is now ready. You should get something like this:
You can create your own dashboards and add any desired metrics, for example ktor_http_server_requests_seconds
to monitor request latency.