prometheus + grafana 对 springboot 项目进行监控

1.prometheus接入springboot

prometheus安装后,在安装目录有一个默认的配置文件prometheus.yml

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

默认配置了一个job_name,监控prometheus本身。需要增加一个监控springboot项目

- job_name: "custom_spring_boot"
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ["localhost:9595"]
1f5c659520e2b7ed8bb03098cc7ab628.png
  • metrics_path 默认采集metrics的路径是/metrics;需要改成/actuator/prometheus

  • scheme 默认是http;如果是https需要自定义配置

  • targets 获取metrics的地址和端口列表

2.访问prometheus

http://127.0.0.1:9090/
beec1a161d63857e2952e6eec056734b.png

出现自定义需要监控的springboot端点列表

d57a2a2e55c3421ad3eb70983a70e1f8.png

在首页,可以查询各种不同的指标0f4a694986bdce1b5570a87180a16678.png

比如查询custom_http_request_time_seconds_count指标

b7c4d9896dac5656b1014a7bcdfd85cb.png

3.grafana接入prometheus

访问

http://127.0.0.1:3000/

配置数据源

c3db11350480b31b7f5bee1bc7a4c426.png

添加一个数据

a33ef729a9dc41c52e71425d2dd6d639.png

选择prometheus

70956234cada0903aa5118a0ce2eb018.png

设置名称和prometheus服务地址

090b85f118c47c5e627d54561b5ed669.png 258ade3c99f6ae961007ad07d29226bd.png

4.配置仪表盘

c9d1855b38b7715acf564b40fc2edec8.png

点击Add a new panel;新建一个Panel

3304c45a4d46cbedd0552eb2ad6dbf14.png

平均时间查询

sum by(api) (rate(custom_http_request_time_seconds_count{job="custom_spring_boot", api="/order"}[5m]))
c55bf5b0cc7c00b0e54085719d4c1b2a.png

保存,最终显示

0a47f121f9714e8262a206e22b1c1f68.png

a0df979142b74eb880d910c7da0cbcfb.gif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BUG弄潮儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值