prometheus实战使用四种Metrics指标

项目中四种指标的配置,和大家详细分享:

 

配置项目基本信息参考:参考基本配置

1、springboot 配置四种指标:

package com.nandao.demo.config;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

/**
 * @author wanghuainan
 * @date 2021/9/22
 */
@Configuration
public class PrometheusMetricsConfig {

    @Autowired
    private PrometheusMeterRegistry registry;

    @Autowired
    private MeterRegistry meterRegistry;

    /**
     * 只增不减的计数器
     * @return
     */
    @Bean
    Counter getCounter(){
        return Counter.builder("pc_test_counter").tag("key", "value").register(meterRegistry);
    }

    /**
     * 只增不减的计数器
     * @return
     */
    @Bean
    Counter createCounter(){
       return Counter.builder("name")  //名称
                .baseUnit("unit") //基础单位
                .description("desc") //描述
                .tag("tagKey", "tagValue")//标签
                .tags("a","A","b","B","c","C") //标签list
                .register(new SimpleMeterRegistry());//绑定的MeterRegistry
    }

    /**
     * 可增可减的仪表盘
     * @return
     */
    @Bean
    Gauge getGauge(){
       return Gauge.builder("test_builder", new Supplier() {
            @Override
            public Number get() {
                return new Random().nextDouble();
            }
        }).register(meterRegistry);
    }

    AtomicInteger atomicInteger = new AtomicInteger();
    /**
     * 可增可减的仪表盘
     * @return
     */
    @Bean
    Gauge createGauge(){
        return Gauge
                .builder("gauge",atomicInteger, AtomicInteger::get)
                .description("a description of what this gauge does") // 可选
                .tags("region", "test") // 可选
                .register(registry);
    }

    /**
     * 柱状图
     * @return
     */
    @Bean
    Histogram getHistogram(){
        return Histogram.build().labelNames("application","uri", "accessType", "code","msg")
                .name("pc_cost_histogram").help("请求耗时histogram")
                .buckets(100,500,1000,3000).register(registry.getPrometheusRegistry());
    }

    /**
     * timmer也属于summary,默认单位sencond,并统计max值
     * @return
     */
    @Bean
    Timer getTimer(){
        return Timer
                .builder("my.timer")
                .description("a description of what this timer does") // 可选
                .tags("region", "test") // 可选
                .register(registry);
    }

    /**
     * 摘要分析
     * @return
     */
    @Bean
    Summary getSummary(){
        return  Summary.build().labelNames("application","uri", "accessType", "code","msg")
                .name("pc_cost_summary").help("请求耗时summary")
                .quantile(0.5, 0.05)
                .quantile(0.9, 0.01)
                .register(registry.getPrometheusRegistry());
    }

}

2、AOP切面部分伪代码展示:



/**
     * 定义注册器
     */
    @Autowired
    MeterRegistry registry;

   // @Autowired
  //  private PrometheusMeterRegistry registry;//也可以用

    @Autowired
    Histogram histogram;
    @Autowired
    Summary summary;

    @Value("${server.servlet.context-path}")
    private String applicationName;


    @AfterReturning(returning = "returnVal", pointcut = "pointCut()")
    public void doAftereReturning(JoinPoint joinPoint,Object returnVal){

        String classMethod = getClassMethodName(joinPoint);
        /**
         * timmer也属于summary,默认单位sencond,并统计max值
         */
        Tag tag1 = new ImmutableTag("uri", classMethod);
        Tag tag2 = null;
        Tag tag3 = null;
        R r = null;
        if(returnVal instanceof R){
             r = (R) returnVal;
             tag2 = new ImmutableTag("code", r.getCode() + "");
             tag3 = new ImmutableTag("msg", r.getMsg());
            summary.labels(applicationName,classMethod,"1",r.getCode()+"",r.getMsg()).observe(9);
            histogram.labels(applicationName,classMethod,"1",r.getCode()+"",r.getMsg()).observe(7);
        }else {
             tag2 = new ImmutableTag("code", "888");
             tag3 = new ImmutableTag("msg", "返回值不是R对象");
            summary.labels(applicationName,classMethod,"1","999","不是R").observe(9);
            histogram.labels(applicationName,classMethod,"1","999","不是R").observe(7);
        }
        registry.timer("api_cost_timer", Lists.newArrayList(tag1, tag2, tag3)).record(8, TimeUnit.MILLISECONDS);

        AtomicLong app_reponse_usedtime = null;
        app_reponse_usedtime = registry.gauge("pc_reponse_usedtime", new AtomicLong(0));
        log.info("开始时间:[{}]存的时间[{}]",startTime.get(),app_reponse_usedtime.get());
    //    app_reponse_usedtime.set((System.currentTimeMillis() - startTime.get()));
       // System.out.println("请求执行时间:" + (System.currentTimeMillis() - startTime.get()));
    }

//只增指标
private void addTsetCount(String tableName) {
        Optional opt = SecurityUtils.getCurrentUserLogin();
        String[]  tags = new String[4];
        if(opt.isPresent()){
            tags[0] = "sysKey";
            tags[1] = opt.get();
        }
        tags[2] ="tableName";
        tags[3] =tableName;
        Metrics.counter("pc_add_count",tags).increment();
 
    }
 

3、启动后调业务接口若干次:

testError/testThrow等接口。 

prometheus实战使用四种Metrics指标_第1张图片

4、 最后请求 http://127.0.0.1:8081/nandao-pc-api/actuator/prometheus/

prometheus实战使用四种Metrics指标_第2张图片

5、分析指标数据:

# HELP tomcat_global_request_max_seconds  
# TYPE tomcat_global_request_max_seconds gauge
tomcat_global_request_max_seconds{application="/nandao-pc-api",name="http-nio-8081",} 0.098
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be used for memory management
# TYPE jvm_memory_max_bytes gauge
jvm_memory_max_bytes{application="/nandao-pc-api",area="nonheap",id="Compressed Class Space",} 1.073741824E9
jvm_memory_max_bytes{application="/nandao-pc-api",area="nonheap",id="Code Cache",} 2.5165824E8
jvm_memory_max_bytes{application="/nandao-pc-api",area="nonheap",id="Metaspace",} -1.0
jvm_memory_max_bytes{application="/nandao-pc-api",area="heap",id="PS Old Gen",} 2.863661056E9
jvm_memory_max_bytes{application="/nandao-pc-api",area="heap",id="PS Eden Space",} 1.298137088E9
jvm_memory_max_bytes{application="/nandao-pc-api",area="heap",id="PS Survivor Space",} 5.8195968E7
# HELP pc_all_online_count  
# TYPE pc_all_online_count gauge
pc_all_online_count{application="/nandao-pc-api",} 0.0
# HELP tomcat_threads_busy_threads  
# TYPE tomcat_threads_busy_threads gauge
tomcat_threads_busy_threads{application="/nandao-pc-api",name="http-nio-8081",} 1.0
# HELP process_uptime_seconds The uptime of the Java virtual machine
# TYPE process_uptime_seconds gauge
process_uptime_seconds{application="/nandao-pc-api",} 93.349
# HELP tomcat_threads_current_threads  
# TYPE tomcat_threads_current_threads gauge
tomcat_threads_current_threads{application="/nandao-pc-api",name="http-nio-8081",} 10.0
# HELP tomcat_sessions_active_max_sessions  
# TYPE tomcat_sessions_active_max_sessions gauge
tomcat_sessions_active_max_sessions{application="/nandao-pc-api",} 0.0
# HELP jvm_gc_pause_seconds Time spent in GC pause
# TYPE jvm_gc_pause_seconds summary
jvm_gc_pause_seconds_count{action="end of minor GC",application="/nandao-pc-api",cause="Allocation Failure",} 7.0
jvm_gc_pause_seconds_sum{action="end of minor GC",application="/nandao-pc-api",cause="Allocation Failure",} 0.216
# HELP jvm_gc_pause_seconds_max Time spent in GC pause
# TYPE jvm_gc_pause_seconds_max gauge
jvm_gc_pause_seconds_max{action="end of minor GC",application="/nandao-pc-api",cause="Allocation Failure",} 0.055
# HELP jvm_threads_daemon_threads The current number of live daemon threads
# TYPE jvm_threads_daemon_threads gauge
jvm_threads_daemon_threads{application="/nandao-pc-api",} 23.0
# HELP pc_reponse_usedtime  
# TYPE pc_reponse_usedtime gauge
pc_reponse_usedtime{application="/nandao-pc-api",} 0.0
# HELP tomcat_sessions_active_current_sessions  
# TYPE tomcat_sessions_active_current_sessions gauge
tomcat_sessions_active_current_sessions{application="/nandao-pc-api",} 0.0
# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool
# TYPE jvm_gc_max_data_size_bytes gauge
jvm_gc_max_data_size_bytes{application="/nandao-pc-api",} 0.0
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge
system_cpu_usage{application="/nandao-pc-api",} 0.0
# HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was reset
# TYPE jvm_threads_peak_threads gauge
jvm_threads_peak_threads{application="/nandao-pc-api",} 30.0
# HELP jvm_buffer_memory_used_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
# TYPE jvm_buffer_memory_used_bytes gauge
jvm_buffer_memory_used_bytes{application="/nandao-pc-api",id="mapped",} 0.0
jvm_buffer_memory_used_bytes{application="/nandao-pc-api",id="direct",} 3424257.0
# HELP jvm_classes_loaded_classes The number of classes that are currently loaded in the Java virtual machine
# TYPE jvm_classes_loaded_classes gauge
jvm_classes_loaded_classes{application="/nandao-pc-api",} 10045.0
# HELP pc_reponse_throw_count_total  
# TYPE pc_reponse_throw_count_total counter
pc_reponse_throw_count_total{aop_method="PrometheusController.testThrow",application="/nandao-pc-api",} 2.0
# HELP tomcat_global_error_total  
# TYPE tomcat_global_error_total counter
tomcat_global_error_total{application="/nandao-pc-api",name="http-nio-8081",} 0.0
# HELP tomcat_sessions_alive_max_seconds  
# TYPE tomcat_sessions_alive_max_seconds gauge
tomcat_sessions_alive_max_seconds{application="/nandao-pc-api",} 0.0
# HELP process_files_max_files The maximum file descriptor count
# TYPE process_files_max_files gauge
process_files_max_files{application="/nandao-pc-api",} 10240.0
# HELP pc_reponse_usedtime_seconds  
# TYPE pc_reponse_usedtime_seconds summary
pc_reponse_usedtime_seconds_count{application="/nandao-pc-api",method_name="PrometheusController.testThrow",} 2.0
pc_reponse_usedtime_seconds_sum{application="/nandao-pc-api",method_name="PrometheusController.testThrow",} 0.012358552
pc_reponse_usedtime_seconds_count{application="/nandao-pc-api",method_name="PrometheusController.testError",} 2.0
pc_reponse_usedtime_seconds_sum{application="/nandao-pc-api",method_name="PrometheusController.testError",} 0.044420894
pc_reponse_usedtime_seconds_count{application="/nandao-pc-api",method_name="PrometheusController.testString",} 2.0
pc_reponse_usedtime_seconds_sum{application="/nandao-pc-api",method_name="PrometheusController.testString",} 0.003582891
pc_reponse_usedtime_seconds_count{application="/nandao-pc-api",method_name="PrometheusController.testIsUsable",} 2.0
pc_reponse_usedtime_seconds_sum{application="/nandao-pc-api",method_name="PrometheusController.testIsUsable",} 1.17525E-4
# HELP pc_reponse_usedtime_seconds_max  
# TYPE pc_reponse_usedtime_seconds_max gauge
pc_reponse_usedtime_seconds_max{application="/nandao-pc-api",method_name="PrometheusController.testThrow",} 0.010265866
pc_reponse_usedtime_seconds_max{application="/nandao-pc-api",method_name="PrometheusController.testError",} 0.044225301
pc_reponse_usedtime_seconds_max{application="/nandao-pc-api",method_name="PrometheusController.testString",} 0.003564689
pc_reponse_usedtime_seconds_max{application="/nandao-pc-api",method_name="PrometheusController.testIsUsable",} 8.5057E-5
# HELP tomcat_global_request_seconds  
# TYPE tomcat_global_request_seconds summary
tomcat_global_request_seconds_count{application="/nandao-pc-api",name="http-nio-8081",} 8.0
tomcat_global_request_seconds_sum{application="/nandao-pc-api",name="http-nio-8081",} 0.21
# HELP process_start_time_seconds Start time of the process since unix epoch.
# TYPE process_start_time_seconds gauge
process_start_time_seconds{application="/nandao-pc-api",} 1.632312533736E9
# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count_buffers gauge
jvm_buffer_count_buffers{application="/nandao-pc-api",id="mapped",} 0.0
jvm_buffer_count_buffers{application="/nandao-pc-api",id="direct",} 47.0
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{application="/nandao-pc-api",area="nonheap",id="Compressed Class Space",} 7471104.0
jvm_memory_committed_bytes{application="/nandao-pc-api",area="nonheap",id="Code Cache",} 1.0616832E7
jvm_memory_committed_bytes{application="/nandao-pc-api",area="nonheap",id="Metaspace",} 5.4657024E7
jvm_memory_committed_bytes{application="/nandao-pc-api",area="heap",id="PS Old Gen",} 1.69869312E8
jvm_memory_committed_bytes{application="/nandao-pc-api",area="heap",id="PS Eden Space",} 5.55220992E8
jvm_memory_committed_bytes{application="/nandao-pc-api",area="heap",id="PS Survivor Space",} 5.8195968E7
# HELP tomcat_threads_config_max_threads  
# TYPE tomcat_threads_config_max_threads gauge
tomcat_threads_config_max_threads{application="/nandao-pc-api",name="http-nio-8081",} 200.0
# HELP pc_reponse_error_count_total  
# TYPE pc_reponse_error_count_total counter
pc_reponse_error_count_total{aop_method="PrometheusController.testError",application="/nandao-pc-api",} 2.0
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge
jvm_memory_used_bytes{application="/nandao-pc-api",area="nonheap",id="Compressed Class Space",} 6807240.0
jvm_memory_used_bytes{application="/nandao-pc-api",area="nonheap",id="Code Cache",} 1.047808E7
jvm_memory_used_bytes{application="/nandao-pc-api",area="nonheap",id="Metaspace",} 5.1252416E7
jvm_memory_used_bytes{application="/nandao-pc-api",area="heap",id="PS Old Gen",} 6.2198432E7
jvm_memory_used_bytes{application="/nandao-pc-api",area="heap",id="PS Eden Space",} 1.69614168E8
jvm_memory_used_bytes{application="/nandao-pc-api",area="heap",id="PS Survivor Space",} 5.8176656E7
# HELP app_requests_method_count_total  
# TYPE app_requests_method_count_total counter
app_requests_method_count_total{application="/nandao-pc-api",method="PrometheusController.core",} 0.0
app_requests_method_count_total{application="/nandao-pc-api",method="PrometheusController.index",} 2.0
# HELP api_cost_timer_seconds_max  
# TYPE api_cost_timer_seconds_max gauge
api_cost_timer_seconds_max{application="/nandao-pc-api",code="100",msg="参数错误",uri="PrometheusController.testError",} 0.008
api_cost_timer_seconds_max{application="/nandao-pc-api",code="105",msg="系统错误",uri="PrometheusController.testThrow",} 0.008
api_cost_timer_seconds_max{application="/nandao-pc-api",code="1",msg="SUCCESS",uri="PrometheusController.testIsUsable",} 0.008
api_cost_timer_seconds_max{application="/nandao-pc-api",code="888",msg="返回值不是R对象",uri="PrometheusController.testString",} 0.008
# HELP api_cost_timer_seconds  
# TYPE api_cost_timer_seconds summary
api_cost_timer_seconds_count{application="/nandao-pc-api",code="100",msg="参数错误",uri="PrometheusController.testError",} 2.0
api_cost_timer_seconds_sum{application="/nandao-pc-api",code="100",msg="参数错误",uri="PrometheusController.testError",} 0.016
api_cost_timer_seconds_count{application="/nandao-pc-api",code="105",msg="系统错误",uri="PrometheusController.testThrow",} 2.0
api_cost_timer_seconds_sum{application="/nandao-pc-api",code="105",msg="系统错误",uri="PrometheusController.testThrow",} 0.016
api_cost_timer_seconds_count{application="/nandao-pc-api",code="1",msg="SUCCESS",uri="PrometheusController.testIsUsable",} 2.0
api_cost_timer_seconds_sum{application="/nandao-pc-api",code="1",msg="SUCCESS",uri="PrometheusController.testIsUsable",} 0.016
api_cost_timer_seconds_count{application="/nandao-pc-api",code="888",msg="返回值不是R对象",uri="PrometheusController.testString",} 2.0
api_cost_timer_seconds_sum{application="/nandao-pc-api",code="888",msg="返回值不是R对象",uri="PrometheusController.testString",} 0.016
# HELP jvm_threads_states_threads The current number of threads having NEW state
# TYPE jvm_threads_states_threads gauge
jvm_threads_states_threads{application="/nandao-pc-api",state="blocked",} 0.0
jvm_threads_states_threads{application="/nandao-pc-api",state="waiting",} 13.0
jvm_threads_states_threads{application="/nandao-pc-api",state="terminated",} 0.0
jvm_threads_states_threads{application="/nandao-pc-api",state="new",} 0.0
jvm_threads_states_threads{application="/nandao-pc-api",state="timed-waiting",} 4.0
jvm_threads_states_threads{application="/nandao-pc-api",state="runnable",} 10.0
# HELP tomcat_global_received_bytes_total  
# TYPE tomcat_global_received_bytes_total counter
tomcat_global_received_bytes_total{application="/nandao-pc-api",name="http-nio-8081",} 0.0
# HELP jvm_threads_live_threads The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live_threads gauge
jvm_threads_live_threads{application="/nandao-pc-api",} 27.0
# HELP system_load_average_1m The sum of the number of runnable entities queued to available processors and the number of runnable entities running on the available processors averaged over a period of time
# TYPE system_load_average_1m gauge
system_load_average_1m{application="/nandao-pc-api",} 5.7978515625
# HELP process_files_open_files The open file descriptor count
# TYPE process_files_open_files gauge
process_files_open_files{application="/nandao-pc-api",} 161.0
# HELP pc_cost_summary 请求耗时summary
# TYPE pc_cost_summary summary
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",} 18.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",quantile="0.5",} 9.0
pc_cost_summary{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",quantile="0.9",} 9.0
pc_cost_summary_count{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",} 2.0
pc_cost_summary_sum{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",} 18.0
# HELP http_server_requests_seconds  
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testThrow",} 2.0
http_server_requests_seconds_sum{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testThrow",} 0.023595696
http_server_requests_seconds_count{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testIsUsable",} 2.0
http_server_requests_seconds_sum{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testIsUsable",} 0.010581015
http_server_requests_seconds_count{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testError",} 2.0
http_server_requests_seconds_sum{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testError",} 0.065257481
http_server_requests_seconds_count{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testString",} 2.0
http_server_requests_seconds_sum{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testString",} 0.077635073
# HELP http_server_requests_seconds_max  
# TYPE http_server_requests_seconds_max gauge
http_server_requests_seconds_max{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testThrow",} 0.015634775
http_server_requests_seconds_max{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testIsUsable",} 0.006410844
http_server_requests_seconds_max{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testError",} 0.060236205
http_server_requests_seconds_max{application="/nandao-pc-api",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/promethues/testString",} 0.068526992
# HELP tomcat_sessions_expired_sessions_total  
# TYPE tomcat_sessions_expired_sessions_total counter
tomcat_sessions_expired_sessions_total{application="/nandao-pc-api",} 0.0
# HELP jvm_gc_memory_promoted_bytes_total Count of positive increases in the size of the old generation memory pool before GC to after GC
# TYPE jvm_gc_memory_promoted_bytes_total counter
jvm_gc_memory_promoted_bytes_total{application="/nandao-pc-api",} 3.8617448E7
# HELP jvm_classes_unloaded_classes_total The total number of classes unloaded since the Java virtual machine has started execution
# TYPE jvm_classes_unloaded_classes_total counter
jvm_classes_unloaded_classes_total{application="/nandao-pc-api",} 1.0
# HELP tomcat_sessions_rejected_sessions_total  
# TYPE tomcat_sessions_rejected_sessions_total counter
tomcat_sessions_rejected_sessions_total{application="/nandao-pc-api",} 0.0
# HELP logback_events_total Number of error level events that made it to the logs
# TYPE logback_events_total counter
logback_events_total{application="/nandao-pc-api",level="debug",} 0.0
logback_events_total{application="/nandao-pc-api",level="error",} 2.0
logback_events_total{application="/nandao-pc-api",level="warn",} 0.0
logback_events_total{application="/nandao-pc-api",level="info",} 69.0
logback_events_total{application="/nandao-pc-api",level="trace",} 0.0
# HELP process_cpu_usage The "recent cpu usage" for the Java Virtual Machine process
# TYPE process_cpu_usage gauge
process_cpu_usage{application="/nandao-pc-api",} 0.0
# HELP pc_aop_all_requests_count_total  
# TYPE pc_aop_all_requests_count_total counter
pc_aop_all_requests_count_total{aop_all_method="count",application="/nandao-pc-api",} 8.0
# HELP tomcat_sessions_created_sessions_total  
# TYPE tomcat_sessions_created_sessions_total counter
tomcat_sessions_created_sessions_total{application="/nandao-pc-api",} 0.0
# HELP jvm_gc_memory_allocated_bytes_total Incremented for an increase in the size of the young generation memory pool after one GC to before the next
# TYPE jvm_gc_memory_allocated_bytes_total counter
jvm_gc_memory_allocated_bytes_total{application="/nandao-pc-api",} 2.459435008E9
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge
system_cpu_count{application="/nandao-pc-api",} 12.0
# HELP app_online_count  
# TYPE app_online_count gauge
app_online_count{application="/nandao-pc-api",} 0.0
# HELP jvm_gc_live_data_size_bytes Size of old generation memory pool after a full GC
# TYPE jvm_gc_live_data_size_bytes gauge
jvm_gc_live_data_size_bytes{application="/nandao-pc-api",} 0.0
# HELP tomcat_global_sent_bytes_total  
# TYPE tomcat_global_sent_bytes_total counter
tomcat_global_sent_bytes_total{application="/nandao-pc-api",name="http-nio-8081",} 332.0
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
# TYPE jvm_buffer_total_capacity_bytes gauge
jvm_buffer_total_capacity_bytes{application="/nandao-pc-api",id="mapped",} 0.0
jvm_buffer_total_capacity_bytes{application="/nandao-pc-api",id="direct",} 3424256.0
# HELP pc_cost_histogram 请求耗时histogram
# TYPE pc_cost_histogram histogram
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="999",msg="不是R",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testString",accessType="1",code="4",msg="测先",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="4",msg="测先",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="4",msg="测先",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="105",msg="系统错误",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testError",accessType="1",code="100",msg="参数错误",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testIsUsable",accessType="1",code="1",msg="SUCCESS",} 14.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",le="100.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",le="500.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",le="1000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",le="3000.0",} 2.0
pc_cost_histogram_bucket{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",le="+Inf",} 2.0
pc_cost_histogram_count{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",} 2.0
pc_cost_histogram_sum{application="/nandao-pc-api",uri="PrometheusController.testThrow",accessType="1",code="4",msg="测先",} 14.0

部分分析:

输出指标解读:假数据伪分析

summary:请求共8次,8次总耗时82ms,中位数51ms,9分位数57ms

histogram:请求共8次,6次总耗时802ms,100ms以下5次,500ms以下5次,1000ms以下共5次,3000ms以下共8次,+Inf ms以下共8次

timer:请求共8次,8次总耗时0.402s,最大值0.893s,注意单位是s
  

看到数据后,你就会豁然开朗,数据很详细,多维度,多层次,立体展示。

你可能感兴趣的:(prometheus监控相关,java,spring,spring,boot)