国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【經(jīng)驗案例】Springboot微服務(wù)搭建JVM監(jiān)控(Springboot + Prometheus + Grafana)

這篇具有很好參考價值的文章主要介紹了【經(jīng)驗案例】Springboot微服務(wù)搭建JVM監(jiān)控(Springboot + Prometheus + Grafana)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

背景

由于項目之前在生產(chǎn)環(huán)境出現(xiàn)過OOM的問題,并且沒有及時發(fā)現(xiàn),導(dǎo)致生產(chǎn)環(huán)境出現(xiàn)了在一定時間內(nèi)不可用的情況,故決定搭建JVM監(jiān)控對微服務(wù)24小時監(jiān)聽,以便于出現(xiàn)問題能夠及時通知相關(guān)人員進行服務(wù)降級或解決問題。

監(jiān)控平臺的選擇

經(jīng)過可行性分析,得到目前較為適合的微服務(wù)監(jiān)控為Springboot Admin或者Prometheus,兩者的主要區(qū)別如下:

框架 可監(jiān)控對象 是否支持集群
Springboot Admin Springboot微服務(wù)
Prometheus 開源監(jiān)控,不僅僅能夠監(jiān)控微服務(wù)

考慮到未來還會有慢SQL、Git等其他類型監(jiān)控,并且Grafana能夠提供優(yōu)秀的監(jiān)控數(shù)據(jù)統(tǒng)計與展示,因此最終選擇了以Prometheus + Grafana的方式搭建監(jiān)控。

搭建微服務(wù)監(jiān)控

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

Prometheus下載與安裝

下載地址:Prometheus下載
選擇對應(yīng)的操作系統(tǒng)下載壓縮包即可(因目前為調(diào)研階段,本文以windows舉例,未來正式部署會補充linux的)。
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

安裝包解壓后的目錄如下圖所示,其中,prometheus.yml是Prometheus啟動時讀取的配置文件,有關(guān)監(jiān)聽配置(scrape_configs)全部寫在此文件中,關(guān)于監(jiān)聽配置本文將在微服務(wù)監(jiān)控配置時一起講述。

注:關(guān)于配置文件的解讀可以參考另外一位大神的文章:prometheus.yml解讀

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

# 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"]
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "eunomia"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ["localhost:8000"]
  - job_name: "apollo-monitor"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ["localhost:8001"]

Springboot微服務(wù)添加監(jiān)控配置

Prometheus對于Springboot微服務(wù)的監(jiān)聽數(shù)據(jù)源來自于Springboot的actuator,但是1.X版本和2.X版本的監(jiān)聽配置還是有一些區(qū)別的,本文將分別以Springboot 1.4.0Springboot 2.3.7為例,闡述監(jiān)聽配置過程

Springboot 1.4.0監(jiān)聽配置

pom文件添加如下依賴:

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.0.9</version>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-spring-legacy</artifactId>
            <version>1.0.9</version>
        </dependency>

因為版本緣故,經(jīng)過多次嘗試發(fā)現(xiàn),Springboot1.4.0可使用Prometheus最高版本為1.0.9,再高版本服務(wù)無法啟動。spring-legacy版本與Prometheus版本對應(yīng)即可,yml文件新增配置如下:

server:
  port: 8001 #服務(wù)端口,若management沒有配置監(jiān)聽端口,則默認采用服務(wù)端口作為監(jiān)聽端口

spring:
  application:
    name: apollo-monitor
management:
  context-path: /actuator #監(jiān)聽服務(wù)上下文配置
  endpoint:
    metrics:
      enabled: true #支持metrics
    prometheus:
      enabled: true #支持Prometheus
  metrics:
    export:
      prometheus:
        enabled: true
    tags:
      application: apollo-monitor #可自定義tag,這里目前只配了實例名
  endpoints:
    web:
      exposure:
        include: '*' #開放所有端口

Springboot1.X版本需要將實例名以metrics的形式發(fā)出,才能被Prometheus獲取(2.X可直接讀yml文件),故需要添加如下配置:

	@Value("${spring.application.name}")
    private String applicationName;

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {

        return registry -> registry.config().commonTags("application", applicationName);
    }

Springboot 2.3.7 監(jiān)聽配置

對于Springboot2.X版本來說,Prometheus的接入可友好太多了,Metrics可以直接配置在yml文件中,并且無需單獨引入spring-legency即可完成數(shù)據(jù)采集。

pom文件添加如下依賴:

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <scope>runtime</scope>
        </dependency>

Springboot2.3.7默認對應(yīng)Prometheus版本為1.5.9,pom依賴無需指定版本。yml文件新增配置如下,其中,實例名采集必須配置,否則JVM監(jiān)控數(shù)據(jù)抓取不到實例名,Grafana提供的JVM監(jiān)控模板中有些Metric Query是需要以實例名作為條件的。

management:
  endpoint:
    metrics:
      enabled: true #支持metrics
    prometheus:
      enabled: true #支持Prometheus
  metrics:
    export:
      prometheus:
        enabled: true
    tags:
      application: eunomia #實例名采集
  endpoints:
    web:
      exposure:
        include: '*' #開放所有端口

Prometheus配置微服務(wù)注冊

完成Springboot的監(jiān)聽基本配置后,需要將其以Job的形式注冊到Prometheus,讓我們再回到Prometheus的配置文件中:

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"]
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "eunomia"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ["localhost:8000"]
  - job_name: "apollo-monitor"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ["localhost:8001"]

其中,job_name為apollo-monitor的即為上文的Springboot1.4.0服務(wù),將其以配置的形式引入,主要屬性如下表所示:

屬性 作用
job_name 服務(wù)注冊名
metrics_path 服務(wù)監(jiān)聽路徑,一般為 “/actuator/實例名”的形式
static_configs 靜態(tài)配置目錄
targets 監(jiān)聽目標地址

完成Prometheus的配置后,便可以啟動Springboot服務(wù)和Prometheus,驗證以上配置是否正確。
Prometheus啟動器在{Prometheus}/bin目錄下,prometheus.exe,啟動后的界面如下圖所示:

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

兩者均啟動后,可訪問Prometheus平臺頁面查看服務(wù)的注冊情況。
默認地址為:http://127.0.0.1:9090/
進入頁面后,Status -> Target,結(jié)果如下圖所示,可以看到服務(wù)名為apollo-monitor的服務(wù)已經(jīng)注冊在Prometheus上,說明Prometheus已經(jīng)在對其進行實時監(jiān)聽。

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

確認服務(wù)注冊成功后,可訪問127.0.0.1:serverport/actuator/prometheus頁面,查看服務(wù)是否報送相關(guān)可監(jiān)控數(shù)據(jù),如下圖所示,監(jiān)控數(shù)據(jù)已經(jīng)全部報送,只是可讀性非常差,無法在短時間內(nèi)獲取到有效的監(jiān)控信息,這時便需要Grafana將監(jiān)控數(shù)據(jù)進行統(tǒng)計、分類與可視化。

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

Prometheus接入Grafana

Grafana

Grafana 是一跨平臺的開源的可視化分析工具。目前網(wǎng)絡(luò)架構(gòu)和應(yīng)用分析中最流行的時序數(shù)據(jù)展示工具,主要用于大規(guī)模指標數(shù)據(jù)的可視化展示。其主要作用如下:

1. 將監(jiān)控數(shù)據(jù)以不同維度、不同效果進行展示與統(tǒng)計。
2. 關(guān)聯(lián)Alert Management以實現(xiàn)閾值告警功能。

3. 支持多種數(shù)據(jù)源的監(jiān)控數(shù)據(jù)收集,如:Prometheus,Mysql,Oracle,ES,ZipKin,Git,Jira等熱門應(yīng)用。

Grafana下載與安裝

官網(wǎng)下載:Grafana官網(wǎng)

如下圖所示,進入下載頁面后,選擇對應(yīng)的操作系統(tǒng),本文以windows舉例,點擊下載按鈕即可下載安裝包,下載后本地直接安裝即可。

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

安裝后Grafana是默認啟動的,端口是3000,我們可直接訪問頁面:http://127.0.0.1:3000/login,默認用戶名密碼為admin/admin,首次登錄會強制修改密碼,登錄后進入Home界面,因為本文的最終目的是實現(xiàn)微服務(wù)的JVM監(jiān)控,而Grafana官網(wǎng)有較為全面的JVM監(jiān)控數(shù)據(jù)面板,故直接選擇import的方式導(dǎo)入即可,模板ID可去官方倉庫查詢,可先訪問Grafana官方倉庫:Grafana模板倉庫地址,搜索欄輸入“JVM”,結(jié)果中第一個就是我們想要的模板,如下圖所示:

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

點擊后進入模板詳情頁面,如下圖所示,兩種方式都可以,分別對應(yīng)Grafana兩種導(dǎo)入方式即可,本文以ID舉例。

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

獲取到ID后,回到Grafana主頁面,點擊DataSource新建數(shù)據(jù)源,選擇Prometheus,填入之前搭好的Prometheus監(jiān)控地址,Save即可。接下來是最后一步,導(dǎo)入監(jiān)控面板,Home頁面選擇Import Dashboard,其中A方式為Json導(dǎo)入方式,B方式為ID導(dǎo)入方式,分別對應(yīng)Grafana倉庫的兩種模板下載方式,本文選擇ID導(dǎo)入方式,輸入4701,點擊Load,完成導(dǎo)入并進入數(shù)據(jù)源選擇界面,JVM監(jiān)控模板固定數(shù)據(jù)源類型是Prometheus,因此只需選擇之前添加的Prometheus數(shù)據(jù)源即可完成JVM監(jiān)控面板的搭建,成品如最后所示。

關(guān)于JVM面板各項監(jiān)控指標的解讀,可參考文章:Grafana-JVM監(jiān)控面板-4701指標詳細解讀

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)
grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

grafana jvm,prometheus,grafana,jvm,spring boot,微服務(wù)

總結(jié)

本文講述以Prometheus+Grafana搭建微服務(wù)JVM監(jiān)控的主要流程,其實這僅僅是Prometheus和Grafana的冰山一角,不僅是JVM監(jiān)控,還可以做服務(wù)數(shù)據(jù)采集進行運營(如ip、登錄端、API調(diào)用與耗時等多維度、多方面監(jiān)控)、運維相關(guān)(服務(wù)器監(jiān)控、慢SQL監(jiān)控)的統(tǒng)計,并且,微服務(wù)接入方式也值得深入研究,盡可能地使得業(yè)務(wù)無感知去完成Metric數(shù)據(jù)捕捉。文章來源地址http://www.zghlxwxcb.cn/news/detail-737890.html

到了這里,關(guān)于【經(jīng)驗案例】Springboot微服務(wù)搭建JVM監(jiān)控(Springboot + Prometheus + Grafana)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 實戰(zhàn):Prometheus+Grafana監(jiān)控Linux服務(wù)器及Springboot項目

    實戰(zhàn):Prometheus+Grafana監(jiān)控Linux服務(wù)器及Springboot項目

    相信大家都知道一個項目交付生產(chǎn)并不意味著結(jié)束,更多的是對線上服務(wù)的運維監(jiān)控。運維監(jiān)控主要涉及到部署服務(wù)器的資源情況,各個子服務(wù)的資源情況以及垃圾收集和吞吐量等等,還有故障告警等等功能。當然,作為一個搬磚人也是需要了解全鏈路的運維監(jiān)控組件Promet

    2024年02月14日
    瀏覽(21)
  • prometheus監(jiān)控JVM(接入tomcat)

    prometheus監(jiān)控JVM(接入tomcat)

    一、整合jmx_exporter及tomcat 1、 jmx_exporter下載地址 https://github.com/prometheus/jmx_exporter/releases 2、 tomcat配置文件下載地址 https://github.com/prometheus/jmx_exporter/blob/main/example_configs/tomcat.yml 3、創(chuàng)建tomcat_exporter目錄 [root@localhost ~]# mkdir /usr/local/jmx_prometheus 將下載的jmx_exporter的jar包及tomcat.y

    2024年02月11日
    瀏覽(13)
  • actuator/prometheus使用pushgateway上傳jvm監(jiān)控數(shù)據(jù)

    actuator/prometheus使用pushgateway上傳jvm監(jiān)控數(shù)據(jù)

    ? ? ? ?? prometheus已經(jīng)部署pushgateway服務(wù),訪問{pushgateway.server:9091}可以看到面板 基于springboot引入支持組件,版本可以 開啟配置 ? ? ? ? ?在pushgateway面板中會顯示新增的服務(wù),在prometheus中也可能看到采集的數(shù)據(jù)

    2024年02月12日
    瀏覽(26)
  • SpringBoot自主監(jiān)控,獲取服務(wù)信息、JVM、CPU、內(nèi)存、磁盤、堆、線程、GC等

    SpringBoot自主監(jiān)控,獲取服務(wù)信息、JVM、CPU、內(nèi)存、磁盤、堆、線程、GC等

    1. 簡介 ??在日常開發(fā)中一些關(guān)鍵的業(yè)務(wù)服務(wù),期望在高并發(fā)狀態(tài)下可以正常工作,或在異常情況時可以記錄當時的性能信息,所以就需要進行監(jiān)控。常見的監(jiān)控例如: Prometheus 可以實現(xiàn)這個需求,如果需要更加簡單方便的自主監(jiān)控能力,可以引入本博客中的方案。 2. 相關(guān)博

    2024年02月15日
    瀏覽(26)
  • Grafana展示k8s中pod的jvm監(jiān)控面板/actuator/prometheus

    Grafana展示k8s中pod的jvm監(jiān)控面板/actuator/prometheus

    ? ? ? ? 為保障java服務(wù)正常運行,對服務(wù)的jvm進行監(jiān)控,通過使用actuator組件監(jiān)控jvm情況,使用prometheus對數(shù)據(jù)進行采集,并在Grafana展現(xiàn)。 ? ? ? ? ?基于k8s場景 配置service的lable,便于prometheus使用lable進行數(shù)據(jù)采集,本案例使用prometheus=jvm為標簽 重啟service或pod,新增標簽生效

    2024年02月13日
    瀏覽(97)
  • Prometheus服務(wù)器、Prometheus被監(jiān)控端、Grafana、Prometheus服務(wù)器、Prometheus被監(jiān)控端、Grafana

    Prometheus服務(wù)器、Prometheus被監(jiān)控端、Grafana、Prometheus服務(wù)器、Prometheus被監(jiān)控端、Grafana

    day03Prometheus概述部署Prometheus服務(wù)器環(huán)境說明:配置時間安裝Prometheus服務(wù)器添加被監(jiān)控端部署通用的監(jiān)控exporterGrafana概述部署Grafana展示node1的監(jiān)控信息監(jiān)控MySQL數(shù)據(jù)庫配置MySQL配置mysql exporter配置mysql exporter配置prometheus監(jiān)控mysql自動發(fā)現(xiàn)機制概述基于文件自動發(fā)現(xiàn)修改Prometheus使

    2024年02月14日
    瀏覽(32)
  • 監(jiān)控之星-普羅米修斯Prometheus搭建

    監(jiān)控之星-普羅米修斯Prometheus搭建

    Prometheus是一個開源系統(tǒng)監(jiān)控和警報工具包,最初在 SoundCloud構(gòu)建。自2012年成立以來,許多公司和組織都采用了Prometheus,該項目擁有非?;钴S的開發(fā)者和用戶社區(qū)。它現(xiàn)在是一個獨立的開源項目,獨立于任何公司維護。為了強調(diào)這一點,并明確項目的治理結(jié)構(gòu),Prometheus 于 2

    2024年02月08日
    瀏覽(15)
  • Prometheus + Grafana 搭建監(jiān)控儀表盤

    Prometheus + Grafana 搭建監(jiān)控儀表盤

    目標要求 1、需要展現(xiàn)的儀表盤: SpringBoot或JVM儀表盤 Centos物理機服務(wù)器(實際為物理分割的虛擬服務(wù)器)儀表盤 2、展現(xiàn)要求: 探索Prometheus + Grafana搭建起來的展示效果,盡可能展示能展示的部分。 監(jiān)控系統(tǒng)核心:prometheus-2.45.0.linux-amd64.tar 下載地址:https://github.com/prometheus

    2024年04月23日
    瀏覽(31)
  • prometheus 配置服務(wù)器監(jiān)控、服務(wù)監(jiān)控、容器中服務(wù)監(jiān)控與告警

    prometheus 配置服務(wù)器監(jiān)控、服務(wù)監(jiān)控、容器中服務(wù)監(jiān)控與告警

    ? ? ? ?最近公司有幾個服務(wù)遇到了瓶頸,也就是數(shù)據(jù)量增加了,沒有人發(fā)現(xiàn),這不是缺少一個監(jiān)控服務(wù)和告警的系統(tǒng)嗎??? ? ? ? 主要需求是監(jiān)控每個服務(wù),順帶監(jiān)控一下服務(wù)器和一些中間件,這里采集的2種,zabbix和prometheus,由于我們要監(jiān)控的是Docker容器中的服務(wù),最終

    2024年02月14日
    瀏覽(23)
  • Springboot搭建微服務(wù)案例之Eureka注冊中心

    Springboot搭建微服務(wù)案例之Eureka注冊中心

    放一些pojo類 (1)整合mybatis dao層 創(chuàng)建 dao 接口的映射文件還有 mybatis 的核心配置文件 配置 MyBatis 的類型別名,簡化 MyBatis 映射文件中的配置? (2)Service 使用 RestTemplate 這個 Java 客戶端組件來實現(xiàn)服務(wù)的遠程調(diào)用。所以我們需要將 RestTemplate 使用 Java 配置類進行注入: 這里

    2024年02月05日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包