Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Table of Contents

Introduction of Monitoring a web app

Info
  • 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

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

Spring Boot Actuator

Info
  • 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

Info
  • 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:
    • Code Block
      titlepom.xml
      linenumberstrue
      <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

Info
  • Code example
    • Code Block
      titleCode example
      linenumberstrue
      ...
      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";
      }