Prometheus+Grafana JVM & Tomcat & Windows Server

explain:

Prometheus:

It is a service monitoring system. It can collect monitoring indicators from configured targets at a given time interval and trigger alarms when specified conditions are observed;

Grafana:

A tool for visualizing the monitored indicators, in which there are many dashbord s, i.e. instrument dials, which are used to display the monitored indicator data;

Download address:

Prometheus: https://prometheus.io/download/

Grafana: https://grafana.com/grafana/download

Main implementation: (all tested)

1: SpringBoot integrates Prometheus to monitor the operation of Java projects;

2: Prometheus monitors Tomcat;

3: Prometheus monitoring Windows Server (development environment monitoring Windows10; generation environment monitoring Windows Server)  

      2008 (all tested);

I:

SpringBoot integrates Prometheus to monitor Java projects:

preparation:

Download Prometheus and Grafana by yourself;

Steps:

1: Download Prometheus and Grafana;

2: SpringBoot project integration monitoring

Dependency:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
    </parent>

    <dependencies>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
          </dependency>

        <!--Monitoring alarm-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
    </dependencies>

application.yml configuration:

server:
  port: 80
# JVM monitoring
management:
  endpoints:
    web:
      exposure:
        include: '*'
      base-path: /actuator # Default actor
  metrics:
    tags:
      application: App # Startup class name

Profile:

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MicrometerConfiguration {
    @Bean
    MeterRegistryCustomizer meterRegistryCustomizer(MeterRegistry meterRegistry) {
        return meterRegistry1 -> {
          meterRegistry.config() // register
          .commonTags("application", "App"); // App: name of the startup class
        };
    }
}

3: Modify the prometheus.yml file in Prometheus and specify the monitoring object:

# Only the configuration part is pasted here, and other parts of the configuration file do not need to be moved
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
      
  - job_name: 'manager-api'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus' # Index acquisition path
    static_configs:
      - targets: ["IP address:80"] # 80 is the startup port of your Java project

4: Start the Prometheus & grafana & java project

        Prometheus (the prometheus.yml file is read by default at startup, and the default port is 9090)

                 Installation directory - > prometheus.exe

        Grafana (default port 3000)

                Installation directory - > Bin - > grafana-server.exe  

5: To view the startup status of the monitoring node:

  Address:   http://IP:9090/targets

6: Go to Grafana to configure the data source and select the appropriate dashboard

Address: http://IP:3000/

For the first visit, you need to enter the account / password. The default account / password is admin / Admin

  ① : add data source

② : select and configure a data source

  ③ : select dashboard after passing the test

 

Completion:

  More dashboard addresses:

 https://grafana.com/grafana/dashboards/

II:

Prometheus monitoring Tomcat

get ready:

        1: tomcat

        2: jmx_ prometheus_ Javaagent-0.3.1.jar (self download)

        3: Tomcat.yml (self created)

Steps:

1: Contents of tomcat.yml: (different dashboard s may be slightly different. Please refer to the official website for details)

---   
lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames: ["java.lang:type=OperatingSystem", "Catalina:*"]
blacklistObjectNames: []
rules:
  - pattern: 'Catalina<type=Server><>serverInfo: (.+)'
    name: tomcat_serverinfo
    value: 1
    labels:
      serverInfo: "$1"
    type: COUNTER
  - pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
    name: tomcat_$3_total
    labels:
      port: "$2"
      protocol: "$1"
    help: Tomcat global $3
    type: COUNTER
  - pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|processingTime|errorCount):'
    name: tomcat_servlet_$3_total
    labels:
      module: "$1"
      servlet: "$2"
    help: Tomcat servlet $3 total
    type: COUNTER
  - pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|connectionCount|acceptCount|acceptorThreadCount|pollerThreadCount|maxThreads|minSpareThreads):'
    name: tomcat_threadpool_$3
    labels:
      port: "$2"
      protocol: "$1"
    help: Tomcat threadpool $3
    type: GAUGE
  - pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
    name: tomcat_session_$3_total
    labels:
      context: "$2"
      host: "$1"
    help: Tomcat session $3 total
    type: COUNTER   

2: tomcat.yml and jmx_prometheus_javaagent-0.3.1.jar is placed in the bin directory of tomcat (no hard requirements, only    

      (it is more convenient to configure catalina.bat)

3: Modify the catalina.bat file of tomcat

set "JAVA_OPTS=%JAVA_OPTS% -javaagent:.\jmx_prometheus_javaagent-0.3.1.jar=9000:.\tomcat.yml"

4: Add additional tomcat.yml in the installation directory of Prometheus and modify the prometheus.yml file:

  Add tomcat.yml file:

- targets:
  - localhost:9000 # Indicator collector port configured in catalina.bat
  labels:
    idc: js_company
    service: tomcat

Modify the prometheus.yml file:

Add the configuration of tomcat for monitoring in prometheus.yml;

  - job_name: 'tomcat'
    file_sd_configs:
    - files: ['./tomcat.yml']
      refresh_interval: 180s

5: Start Tomcat & view the Tomcat node in Prometheus & configure the data source in Grafana and select Tomcat

      dashboard;

 6:tomcat(dashboard ID: 8704)

7: Completion:

III:

Prometheus monitors Windows Servers

get ready:

windows_ Exporter-0.16.0-amd64.exe (self installation, default port 9182)  
 

Steps:

1: Start windows_exporter-0.16.0-amd64.exe

  Check startup:

http://IP:9182/metrics

2: Configure the prometheus.yml file to increase listening to Windows

  - job_name: 'windows'
    scrape_interval: 10s
    scrape_timeout: 10s
    static_configs:
      - targets: ['localhost:9182']

3: To view the status of this node:

  4: Configure the data source in Grafana & select the appropriate dashboard: (Windows dashboard ID: 10467)

  5: Complete

 

Although the road is endless and faraway, I still want to pursue the truth in the world.

Posted on Sun, 21 Nov 2021 03:19:55 -0500 by inrealtime