日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

prometheus + grafana 对 springboot 项目进行监控

發(fā)布時(shí)間:2024/1/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 prometheus + grafana 对 springboot 项目进行监控 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.prometheus接入springboot

prometheus安裝后,在安裝目錄有一個(gè)默認(rèn)的配置文件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"]

默認(rèn)配置了一個(gè)job_name,監(jiān)控prometheus本身。需要增加一個(gè)監(jiān)控springboot項(xiàng)目

-?job_name:?"custom_spring_boot"metrics_path:?'/actuator/prometheus'static_configs:-?targets:?["localhost:9595"]
  • metrics_path 默認(rèn)采集metrics的路徑是/metrics;需要改成/actuator/prometheus

  • scheme 默認(rèn)是http;如果是https需要自定義配置

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

2.訪問(wèn)prometheus

http://127.0.0.1:9090/

出現(xiàn)自定義需要監(jiān)控的springboot端點(diǎn)列表

在首頁(yè),可以查詢各種不同的指標(biāo)

比如查詢custom_http_request_time_seconds_count指標(biāo)

3.grafana接入prometheus

訪問(wèn)

http://127.0.0.1:3000/

配置數(shù)據(jù)源

添加一個(gè)數(shù)據(jù)

選擇prometheus

設(shè)置名稱和prometheus服務(wù)地址

4.配置儀表盤

點(diǎn)擊Add a new panel;新建一個(gè)Panel

平均時(shí)間查詢

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

保存,最終顯示

總結(jié)

以上是生活随笔為你收集整理的prometheus + grafana 对 springboot 项目进行监控的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。