1:应用集成prometheus

    1. <!-- 应用集成prometheus -->
    2. <dependency>
    3. <groupId>io.micrometer</groupId>
    4. <artifactId>micrometer-registry-prometheus</artifactId>
    5. </dependency>
    6. #ymlproperties中暴露端点
    7. management.endpoints.web.exposure.include=prometheus

    http://10.5.2.158:8888/actuator/prometheus

    2:修改Prometheus的配置,加入要监控的应用的端点

    1. # 端点配置
    2. scrape_configs:
    3. - job_name: 'prometheus'
    4. static_configs:
    5. - targets: ['10.5.2.186:9090']
    6. - job_name: 'node01'
    7. static_configs:
    8. - targets: ['10.5.2.186:9100']
    9. - job_name: 'api-gateway'
    10. metrics_path: '/actuator/prometheus'
    11. static_configs:
    12. - targets: ['10.5.2.158:8888']

    3:访问下Prometheus控制台,看是否正常
    image.png

    4:监控系统前10 API访问数
    Create -> Add an empty panel 创建空面板
    建几个变量
    image.pngimage.png

    image.png

    备注:一些语法和用到的API

    1. grafanaprometheus查询语法
    2. label_values(label) 返回Promthues所有监控指标中,标签名为label的所有可选值
    3. label_values(metric, label) 返回Promthues所有监控指标metric中,标签名为label的所有可选值
    4. metrics(metric) 返回所有指标名称满足metric定义正则表达式的指标名称
    5. query_result(query) 返回prometheus查询语句的查询结果
    6. demo:
    7. label_values(application)
    8. label_values(up{application="$application"}, instance) 在监控指标application变量的表达式的值中,再取instance变量