# Prometheus

什么是APM (opens new window)

# 安装

官网 (opens new window) 下载地址 (opens new window) 官方文档 (opens new window)

最好下载 lts 版本 tar.gz 解压或者 wget 都 ok

# 配置

官方配置 (opens new window)

默认情况下,promethues 会监控本身 配置 prometheus.yml

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'test-application'
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['localhost:9527']

后台启动

./prometheus --config.file=prometheus.yml  &

查看网页 http://xxx.xx.xx.xxx:9090/

查看 targets

# 集成 Grafana

下载地址 (opens new window)

配置文件默认/etc/grafana/grafana.ini

默认 3030 端口

默认用户名密码 admin/admin

接入 promethues 数据

https://prometheus.io/docs/visualization/grafana/ (opens new window)

  1. 添加 prometheus 数据源
  2. 设置相关信息
  3. 导入想要的 dashboards 如常用的 4701 6756

# Springboot 整合

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!--prometheus-->
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <version>1.0.3</version>
    </dependency>
/**
     * 上报application 到 Prometheus
     */
    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> registry.config().commonTags("application", "yourappName");
    }
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
    prometheus:
      enabled: true

参考文章1 (opens new window) 参考文章2 (opens new window) 参考文章3 (opens new window) 参考文章4 (opens new window)

P95、P99线的概念 (opens new window)