Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 2.83 KB

10.micrometer-metrics.md

File metadata and controls

49 lines (38 loc) · 2.83 KB

Micrometer Metrics

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.

Setting Up Prometheus

  1. Download and install Prometheus.
  2. Edit the existing prometheus.yml that comes with the installation and append the following job within scrape_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.
  3. Start Prometheus and navigate to http://localhost:9090/targets to verify that the krud job is up and running.
  4. Navigate to http://localhost:9090/graph and enter ktor_http_server_requests_seconds in the Expression 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:

Prometheus

Setting Up Grafana

  1. Download and install Grafana.
  2. Start Grafana and navigate to http://localhost:3000 to log in with the default credentials (admin/admin).
  3. Add a new Prometheus data source by navigating to Connnections > Data Sources (http://localhost:3000/connections/datasources).
  4. Select Prometheus and enter http://localhost:9090 as the URL.
  5. Add the Basic Auth credentials if you set them up in the prometheus.yml file. Leave the rest of the settings as default.
  6. Click Save & Test to save the data source.
  7. Navigate to Dashboards > Create and select New > Import. Enter 4701 as the Dashboard ID to import the pre-built Ktor dashboard.
  8. Select the Prometheus data source and click Import to import the dashboard.
  9. Navigate to the Ktor dashboard to view the metrics.

Grafana is now ready. You should get something like this:

Grafana 4701

You can create your own dashboards and add any desired metrics, for example ktor_http_server_requests_seconds to monitor request latency.

Grafana Custom