Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 30 章 Spring boot with Monitor

目录

30.1. Spring boot with Grafana
30.1.1. Springboot 集成 InfluxDB
30.1.2. InfluxDB
30.2. Spring Boot with Prometheus
30.2.1. Maven 依赖
30.2.2. application.properties 配置文件
30.2.3. 启动类
30.2.4. 测试
30.2.5. 控制器监控
30.2.6. 自定义埋点监控

30.1. Spring boot with Grafana

30.1.1. Springboot 集成 InfluxDB

Springboot 集成 InfluxDB 非常简单,先引入依赖即可,记得需要同时引入 actuator

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

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-influx</artifactId>
</dependency>		
		
			

配置文件 application.yaml 如下

		
spring:
  application:
    name: springboot-with-influxdb
server:
  port: 8080
management:
  metrics:
    export:
      influx:
        enabled: true
        db: springboot
        uri: http://localhost:8086
        user-name:
        password:
        connect-timeout: 1s
        read-timeout: 10s
        auto-create-db: true
        step: 1m
        num-threads: 2
        consistency: one
        compressed: true
        batch-size: 1000		
		
			

30.1.2. InfluxDB

配置好 Springboot 后,启动应用,稍后Springboot 就会将数据源源不断地写入到 InfluxDB 中。

		
> show measurements
name: measurements
name
----
jvm_buffer_count
jvm_buffer_memory_used
jvm_buffer_total_capacity
jvm_classes_loaded
jvm_classes_unloaded
jvm_gc_live_data_size
jvm_gc_max_data_size
jvm_gc_memory_allocated
jvm_gc_memory_promoted
jvm_gc_pause
jvm_memory_committed
jvm_memory_max
jvm_memory_used
jvm_threads_daemon
jvm_threads_live
jvm_threads_peak
jvm_threads_states
logback_events
process_cpu_usage
process_files_max
process_files_open
process_start_time
process_uptime
system_cpu_count
system_cpu_usage
system_load_average_1m
tomcat_sessions_active_current
tomcat_sessions_active_max
tomcat_sessions_alive_max
tomcat_sessions_created
tomcat_sessions_expired
tomcat_sessions_rejected
visits		
		
			

查看数据

		
select * from process_cpu_usage