Introduction of Monitoring a web app

  • Application's Health + Metrics
  • Notice unwanted behavior
  • Monoliths as well as microservices
    • Crucial in microservices architecture
  • "To measure is to know"

We are going to integrate Prometheus monitoring with a web application based on SpringBoot

  • We will use following:
    • Spring Boot
    • Spring Boot Actuator
    • Micrometer
  • We are also going to do a demo with an example.

Spring Boot Actuator

  • Sub-Project of Spring boot
  • Production ready endpoints
  • /actuator is the common prefix of these endpoints
    • Protected by default
    • Adjustable in application.properties
      • Expose all: management.endpoints.web.exposure.include=*

Micrometer

  • Vendor-Neutral application metrics facade
  • Support for Prometheus and many others:
    • AWS Cloudwatch, Datadog, InfluxDB/Telegraf, New Relic, ...
  • Transforms /actuator/metrics data into data your monitoring system understands
  • Only a vendor-specific micrometer dependency in your application is required
  • pom.xml example:
    • pom.xml
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-stater-actuator</artifactId>
      </dependency>
      
      <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-core</artifactId>
      </dependency>
      
      <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
      </dependency>

SpringBoot

  • Code example
    • Code example
      ...
      import io.micrometer.core.instrument.Metrics;
      ...
      private Counter runCounter = Mitrics.counter("runCounter");
      ...
      @GetMapping("/api/demo")
      @Timed
      public String apiUse() throws InterruptedException {
        runCounter.increment();
        log.info("Hello world app accessed on /api/demo");
      
        return "Hello world";
      }
  • No labels
Write a comment…