Pepper Metrics - 运行时性能收集工具


Apache
跨平台
Java

软件简介

Architecture

Pepper Metrics项目从核心概念上来说,基于Tom
Wilkie的RED理论,即对每个服务
(这里的服务特指进程中的某种调用,比如调用一次数据库查询)进行RED指标收集,并持久化到数据库,并通过dashboard进行展示,辅助进行性能趋势分析。

Concept

Arch

各个组件说明

  • Profiler,
    核心部分,用于启动定期调度任务,并通过ExtensionLoad加载所有的ScheduledRun扩展,按照指定周期发起调度。同时内部维护Stats的构造器Profiler.Builder
  • Scheduler, 虚拟概念,在Profiler作为一个定时任务存在
  • ExtensionLoader, 非常重要的组件,通过Java SPI机制加载插件,使项目的各个模块可以灵活插拔,也是项目架构的基石
  • ScheduledRun, 扩展点:pepper metrics
    core会定时调度,传递所有的Stats,实现插件可以使用Stats当中收集到的性能数据,目前已实现的为scheduled printer组件
  • Pepper Metrics X,
    具体的集成,我们的目标是度量一切,目前计划实现的为:jedis,motan,dubbo,servlet,mybatis等最常用组件

Getting started

以Mybatis集成为例,更多其他请参考:User Guide

  • 增加maven依赖




    top.zrbcool
    pepper-metrics-mybatis
    1.0.11



    top.zrbcool
    pepper-metrics-ds-prometheus
    1.0.11

  • 配置Pepper Metrics定制的Mybatis插件使集成生效












  • 日志输出效果:

    18:27:28 [perf-mybatis:20190822182728] ---------------------------------------------------------------------------------------------------------------------------------------------------------
    18:27:28 [perf-mybatis:20190822182728] | Metrics Concurrent Count(Err/Sum) P90(ms) P99(ms) P999(ms) Max(ms) Qps |
    18:27:28 [perf-mybatis:20190822182728] | com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId 0 0/1950 0.6 1.4 2.5 3.5 32.5 |
    18:27:28 [perf-mybatis:20190822182728] | sample.mybatis.mapper.CityMapper.selectCityById 0 0/1950 0.8 2.4 56.6 56.6 32.5 |
    18:27:28 [perf-mybatis:20190822182728] ---------------------------------------------------------------------------------------------------------------------------------------------------------

  • Prometheus指标输出效果(默认的实现,可以修改为其他数据库)

    ✗ curl localhost:9146/metrics

    HELP app_mapper_summary_seconds_max

    TYPE app_mapper_summary_seconds_max gauge

    app_mapper_summary_seconds_max{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,} 0.051129036
    app_mapper_summary_seconds_max{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,} 0.011559611

    HELP app_mapper_summary_seconds

    TYPE app_mapper_summary_seconds summary

    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,quantile=”0.9”,} 5.5296E-4
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,quantile=”0.99”,} 0.001765376
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,quantile=”0.999”,} 0.052424704
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,quantile=”0.99999”,} 0.052424704
    app_mapper_summary_seconds_count{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,} 3040.0
    app_mapper_summary_seconds_sum{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,} 1.45711331
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,quantile=”0.9”,} 4.4032E-4
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,quantile=”0.99”,} 0.001308672
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,quantile=”0.999”,} 0.002881536
    app_mapper_summary_seconds{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,quantile=”0.99999”,} 0.012056576
    app_mapper_summary_seconds_count{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,} 3040.0
    app_mapper_summary_seconds_sum{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,} 0.772147736

    HELP app_mapper_concurrent_gauge

    TYPE app_mapper_concurrent_gauge gauge

    app_mapper_concurrent_gauge{class=”com/pepper/metrics/sample/mybatis/mapper/CityMapper.xml”,operation=”sample.mybatis.mapper.CityMapper.selectCityById”,} 0.0
    app_mapper_concurrent_gauge{class=”com/pepper/metrics/sample/mybatis/mapper/HotelMapper.xml”,operation=”com.pepper.metrics.sample.mybatis.mapper.HotelMapper.selectByCityId”,} 0.0

Maven dependency

以Mybatis为例,更多其他请参考:User Guide

<dependencies>
    <!-- pepper metrics dependencies -->
    <dependency>
        <groupId>top.zrbcool</groupId>
        <artifactId>pepper-metrics-mybatis</artifactId>
        <version>1.0.11</version>
    </dependency>
    <!-- pepper-metrics datasource use prometheus by default -->
    <dependency>
        <groupId>top.zrbcool</groupId>
        <artifactId>pepper-metrics-ds-prometheus</artifactId>
        <version>1.0.11</version>
    </dependency>
</dependencies>

Next steps

Theory

Building

mvn clean package install