Introduction to monitoring from Java Touching Prometheus

What is Prometheus?

Pull type monitoring system. OSS. A system that can monitor memory and CPU usage.

What is a pull-type monitoring system?

Normal surveillance systems (Meckerel, Sensu, etc.) Install an agent on the monitoring side and send information to the monitoring server.

On the contrary, the Pull type acquires information from the side monitored by the monitoring server.

merit and demerit

Push type

[merit] ・ Easy to install the app on the monitoring target -There are few changes in server settings even if the number of monitoring targets increases.

[Demerit] -When the amount of monitoring increases, the load on the monitoring server increases.

Pull type

[merit] ・ It is easier to see that the monitoring target is down than the Push type. -The load on the monitoring server is lower than Push

[Demerit] -You have to set the endpoint to be monitored. It's not just a simple installation. ・ When the number of monitoring targets increases, it is necessary to set each time.

This goal

In Spring application, link data to Promethus, Display nicely with Grafana.

image.png

procedure

Create Promethus endpoint in Spring

Added Spring Actuator from Spring Initializr [https://start.spring.io/]. Spring Actuator will be able to check Spring dumps and health checks.

image.png

Set Micrometer Registry Prometheus as a dependency. [ https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus ]

Maven Repository:.png

Open the endpoint from the property file.

application.properties


#Full open
management.endpoints.web.exposure.include=*

Start the application and confirm that the endpoint is created.

http://localhost:8080/actuator/prometheus

Prometheus settings

Can be set with the following YML

prometheus.yml



global:
  #Frequency of target acquisition
  scrape_interval:     10s
  evaluation_interval: 10s

#Monitoring target settings
scrape_configs:
  #Spring Boot App Exporter monitoring settings
  - job_name: 'springboot'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['web:8080']
        labels:
          group: 'docker-springboot'

Launch Prometheus / Grafana / App

Start with Docker Compose.

docker-compose.yml


version: '3.1'
services:

  web:
    build: app/
    ports:
      - "8080:8080"

  monitor:
    build: prometheus/
    ports:
      - "9090:9090"
    depends_on:
      - "web"

  grafana:
    image: grafana/grafana
    ports:
      - "3000:3000"
Check Prometheus

▼ Screen to confirm the monitoring target

http://54.238.228.193:9090/targets

image.png

▼ Graph confirmation screen

http://54.238.228.193:9090/graph

image.png

However, the UI of the graph is not good enough. So look at Grafana.

Check Grafana

URL: http://localhost:3000 ID: admin (initial) PASS: admin (initial)

▼ Select a data source

image.png

Set the URL as below

Prometheus.png

▼ Dashboard creation

Select Add Query

image.png

After that, set it to your liking

New dashboard.png

Other digressions

・ Promethuns endpoint classes set in Spring can be inherited and customized independently.

・ Notification settings may be difficult for Promethuns and Grafana

Recommended Posts

Introduction to monitoring from Java Touching Prometheus
[Java] Introduction to Java
Introduction to java
Changes from Java 8 to Java 11
Sum from Java_1 to 100
From Java to Ruby !!
Introduction to java command
New features from Java7 to Java8
Connect from Java to PostgreSQL
[Java] Introduction to lambda expressions
[Java] Introduction to Stream API
From Ineffective Java to Effective Java
[Introduction to rock-paper-scissors games] Java
[Introduction to Java] About lambda expressions
[Introduction to Java] About Stream API
Introduction to Functional Programming (Java, Javascript)
From introduction to use of ActiveHash
Java to be involved from today
Introduction to Ruby (from other languages)
Initial introduction to Mac (Java engineer)
Java, interface to start from beginner
From introduction to usage of byebug
The road from JavaScript to Java
[Java] Conversion from array to List
[Java] Introduction
Introduction to Scala from a Java perspective, decompiled and understood (basic)
Batch startup monitoring (Java x PushGateway x Prometheus)
Introduction to java for the first time # 2
Introduction to algorithms with java --Search (depth-first search)
Convert from java UTC time to JST time
[Introduction to Java] How to write a Java program
Connect from Java to MySQL using Eclipse
Deep Learning Java from scratch Chapter 1 Introduction
From installing Eclipse to executing Java (PHP)
Post to Slack from Play Framework 2.8 (Java)
Java: How to send values from Servlet to Servlet
[Java] Flow from source code to execution
Output of the book "Introduction to Java"
[Introduction to Java] Variable declarations and types
Precautions when migrating from VB6.0 to JAVA
Memo for migration from java to kotlin
Type conversion from java BigDecimal type to String type
Introduction to Java Web Apps Performance Troubleshooting
Introduction to algorithms with java --Search (breadth-first search)
[Java] Flow from introduction of STS to confirmation of dynamic page on localhost (2/3)
Introduction to Scala from a Java perspective (Class-Tuple edition) to decompile and understand
[Java] Flow from introduction of STS to confirmation of dynamic page on localhost (1/3)
Introduction to Ruby 2
[Java] From two Lists to one array list
Upsert from Java SDK to Azure Cosmos DB
Run R from Java I want to run rJava
[Introduction to Java] About type conversion (cast, promotion)
Introduction to algorithms with java --Search (bit full search)
Connect to Aurora (MySQL) from a Java application
To become a VB.net programmer from a Java shop
Introduction to SWING
Migrate from Java to Server Side Kotlin + Spring-boot
Road to Java Engineer Part1 Introduction & Environment Construction
[Monthly 2017/04] Introduction to groovy !! ~ Java grammar / specification comparison ~
How to get Class from Element in Java
Introduction to web3j