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

SpringBoot+Prometheus采集Metrics指標數(shù)據(jù)

這篇具有很好參考價值的文章主要介紹了SpringBoot+Prometheus采集Metrics指標數(shù)據(jù)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

簡介

本文介紹在springboot3.x里配置啟用系統(tǒng)指標監(jiān)控功能,來監(jiān)視系統(tǒng)各項Metrics指標,從而實時了解應(yīng)用的運行健康狀態(tài),通過promtheus服務(wù)提供數(shù)據(jù)收集與指標可視化方案;

Metrics指標

metrics指標表示應(yīng)用程序代碼運行中提供的多維度指標數(shù)據(jù),每一條指標數(shù)據(jù)通常由時間序列及一組標簽鍵值對結(jié)構(gòu)數(shù)據(jù)組成,常見的運行維度指標有:服務(wù)響應(yīng)時間,HTTP請求量,CPU利用率,內(nèi)存使用大小,磁盤讀寫大小,JVM內(nèi)存使用率等等;

Spring Boot Actuator為Micrometer提供依賴管理和自動配置,Micrometer 是一個支持眾多監(jiān)控系統(tǒng),并提供應(yīng)用程序的可觀察性度量指標數(shù)據(jù)組件;

Micrometer官方描述為計時器、計量器、計數(shù)器、分布摘要和長任務(wù)計時器提供供應(yīng)商中立的接口,并具有維度數(shù)據(jù)模型,當與維度監(jiān)控系統(tǒng)配合使用時,可以有效訪問特定的命名指標,并具有向下鉆取的能力跨越它的維度。

SpringBoot啟用metrics

在springboot生態(tài)體系spring-boot-starter-actuator組件中已集成相關(guān)Metrics指標配置與服務(wù),可以方便支持從 Spring Boot 應(yīng)用程序中獲取應(yīng)用程序可觀察性指標。

相關(guān)的配置與使用方式,在springboot官方文檔中都有進行描述;詳情參見:Production-ready Features

以一個springboot3.x項目做為示例,演示如何使用metrics指標服務(wù),并對接到prometheus中做可觀察性指標展示;

項目信息:springboot.3.1.0 + jdk17

pom.xml

創(chuàng)建任意一個springboot項目,引入以下pom配置項

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <java.version>17</java.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- prometheus依賴 -->
    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <version>1.11.0</version>
    </dependency>
</dependencies>

application.yml

# 本地服務(wù)訪問
server:
  # 服務(wù)端口
  port: 8080
  # 服務(wù)IP
  address: 0.0.0.0

spring:
  application:
    # 應(yīng)用服務(wù)名
    name: testDemo

# 是否啟用springboot的debug調(diào)試模式,會打印詳細日志信息
debug: false

# 開啟健康檢查
management:
  # 自定義管理服務(wù)地址和端口,默認和應(yīng)用程序地址端口一致
#  server:
#    port: 8081
#    address: 0.0.0.0
  endpoint:
    shutdown:
      enabled: true
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        # 開啟端點,*表示開啟所有
        include:
          - '*'
        # 某些端點除外,不做開啟
        exclude:
          - env
          - beans
      # 跨域配置
      cors:
        # 開放所有域訪問
        allowed-origins:
          - '*'
  metrics:
    # 指標采集標簽名
    tags:
      application: ${spring.application.name}
  # 啟用對接prometheus服務(wù)采集指標數(shù)據(jù)
  prometheus:
    metrics:
      export:
        enabled: true

ApplicationStart.java

@SpringBootApplication
public class ApplicationStart {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationStart.class, args);
    }
}

瀏覽器訪問

啟動springboot程序后,通過以下URL在瀏覽器中打開

http://127.0.0.1:8080/actuator

查看已開啟的端點與端點數(shù)據(jù)展示鏈接

{
    "_links": {
        "self": {
            "href": "http://127.0.0.1:8080/actuator",
            "templated": false
        },
        "caches-cache": {
            "href": "http://127.0.0.1:8080/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://127.0.0.1:8080/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://127.0.0.1:8080/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://127.0.0.1:8080/actuator/health/{*path}",
            "templated": true
        },
        "info": {
            "href": "http://127.0.0.1:8080/actuator/info",
            "templated": false
        },
        "conditions": {
            "href": "http://127.0.0.1:8080/actuator/conditions",
            "templated": false
        },
        "shutdown": {
            "href": "http://127.0.0.1:8080/actuator/shutdown",
            "templated": false
        },
        "configprops": {
            "href": "http://127.0.0.1:8080/actuator/configprops",
            "templated": false
        },
        "configprops-prefix": {
            "href": "http://127.0.0.1:8080/actuator/configprops/{prefix}",
            "templated": true
        },
        "loggers": {
            "href": "http://127.0.0.1:8080/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://127.0.0.1:8080/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://127.0.0.1:8080/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://127.0.0.1:8080/actuator/threaddump",
            "templated": false
        },
        "prometheus": {
            "href": "http://127.0.0.1:8080/actuator/prometheus",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://127.0.0.1:8080/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://127.0.0.1:8080/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://127.0.0.1:8080/actuator/scheduledtasks",
            "templated": false
        },
        "mappings": {
            "href": "http://127.0.0.1:8080/actuator/mappings",
            "templated": false
        }
    }
}

安裝prometheus

prometheus是一個開源監(jiān)控系統(tǒng),用于收集和聚合指標作為時間序列數(shù)據(jù),它前身是SoundCloud的警告工具包。

prometheus通過抓取或輪詢獲取各個應(yīng)用程序?qū)嵗闹笜?。Spring Boot 提供了一個執(zhí)行器端點/actuator/prometheus輸出數(shù)據(jù)格式,以提供prometheus服務(wù)抓取。

下載

Download | Prometheus

prometheus支持windows環(huán)境安裝與使用,本文采用prometheus-2.37.0(windows-amd64)版本做為演示使用;

prometheus.yml

解壓下載包后,進入prometheus解壓根目錄,編輯prometheus.yml配置,添加拉取的springboot應(yīng)用服務(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"]
  # 增加spring任務(wù)節(jié)點,從/actuator/prometheus拉取目標指標數(shù)據(jù)
  - job_name: "spring"
    metrics_path: "/actuator/prometheus"
    static_configs:
      - targets: ["localhost:8080"]

瀏覽器訪問

完成prometheus.yml配置后,直接雙擊prometheus.exe程序運行服務(wù);服務(wù)啟動完畢后,通過以下URL在瀏覽器中訪問:

http://127.0.0.1:9090/

點擊 “菜單欄》Status》Targets” 查看已配置并啟用的采集端點應(yīng)用

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

Metrics指標跟蹤

點擊菜單欄的“Graph”項,在搜索框中輸入jvm,則會自動聯(lián)想多個帶有jvm內(nèi)容的可觀察性指標;

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

我們以常見的java應(yīng)用程序內(nèi)存使用為例,選擇jvm_memory_used_bytes,觀察應(yīng)用服務(wù)運行過程中的jvm內(nèi)存使用情況,進行實時監(jiān)控以便及時了解應(yīng)用服務(wù)運行狀況,為應(yīng)用服務(wù)提供有效的健康跟蹤方案;

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

Grafana大盤展示

由于metrics維度指標眾多,通過prometheus服務(wù)采集后,通過數(shù)據(jù)指標轉(zhuǎn)化成可觀察性圖形,為應(yīng)用程序運維提供了合適的監(jiān)控技術(shù)與管理平臺,同時也可以將prometheus采集的指標輸出到第三方各類平臺上進行展示,比如運維中常見的Grafana,提供了許多豐富的圖標插件,高大上的的漂亮UI,以及Grafana官網(wǎng)第三方上傳的展示模板,可以非常便捷的套用開放模板后立即呈現(xiàn)出可視化監(jiān)控圖形界面;

  • 注:此處以一個已有的Grafana服務(wù)為例,不額外描述Grafana安裝過程,安裝請自行百度;

默認在explore界面查找指標展示;

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

添加SpringBoot監(jiān)控大盤,官方有很多共享的儀表盤資源可下載,從而減少自已不熟悉儀表盤的配置與腳本,避免無法操作出想要的效果,通過獲得第三方共享資源可以快速進行展示。

Dashboards | Grafana Labs

以下為共享ID:12900 (SpringBoot APM Dashboard)

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

在共享大盤頁面復(fù)制共享ID后,在Grafana》Dashboards瀏覽界面,點擊import按鈕進入導(dǎo)入共享資源界面;

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

輸入共享大盤ID:12900,點擊load后,進入大盤配置盤面,底部的Prometheus選擇已安裝的Prometheus數(shù)據(jù)源選擇(如沒有,需要先在插件庫中提前安裝);

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

導(dǎo)入共享大盤后,進入到大盤展示界面,開始加載Prometheus監(jiān)控的維度指標數(shù)據(jù),通過各種儀表盤進行詳細展示;

prometheus采集數(shù)據(jù),SpringBoot,java,spring boot,prometheus,指標監(jiān)控

到此,一個完整的springboot項目從集成metrics指標組件,到Prometheus監(jiān)控服務(wù)搭建,到最后Grafana大盤儀表展示流程結(jié)束;文章來源地址http://www.zghlxwxcb.cn/news/detail-760318.html

到了這里,關(guān)于SpringBoot+Prometheus采集Metrics指標數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(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)文章

  • K8S篇之實現(xiàn)利用Prometheus監(jiān)控pod的實時數(shù)據(jù)指標

    K8S篇之實現(xiàn)利用Prometheus監(jiān)控pod的實時數(shù)據(jù)指標

    一、監(jiān)控部署 1、將k8s集群中kube-state-metrics指標進行收集,服務(wù)進行部署 1.1 pod性能指標(k8s集群組件自動集成) k8s組件本身提供組件自身運行的監(jiān)控指標以及容器相關(guān)的監(jiān)控指標。通過cAdvisor 是一個開源的分析容器資源使用率和性能特性的代理工具,集成到 Kubelet中,當Ku

    2024年02月05日
    瀏覽(40)
  • prometheus采集服務(wù)的jmx數(shù)據(jù),grafana通過dashboard展示jmx數(shù)據(jù)

    prometheus采集服務(wù)的jmx數(shù)據(jù),grafana通過dashboard展示jmx數(shù)據(jù)

    重命名目錄 http://ip:9090 http://ip:9090/metrics 啟動grafana 查看grafana狀態(tài) 賬號和密碼都是:admin prometheus的URL是http://ip:9090 添加成功后保存數(shù)據(jù)源,成功如下所示 修改配置文件prometheus.yml 重啟prometheus 發(fā)現(xiàn)成功采集debezium服務(wù)的jmx數(shù)據(jù) grafana官網(wǎng)搜索你想監(jiān)控的服務(wù)的dashboard: https

    2024年02月16日
    瀏覽(19)
  • Kubernetes 筆記(17)— 系統(tǒng)監(jiān)控、使用Metrics Server、hpa 自動伸縮 Pod 數(shù)量、Prometheus 的使用

    Kubernetes 筆記(17)— 系統(tǒng)監(jiān)控、使用Metrics Server、hpa 自動伸縮 Pod 數(shù)量、Prometheus 的使用

    如果你對 Linux 系統(tǒng)有所了解的話,也許知道有一個命令 top 能夠?qū)崟r顯示當前系統(tǒng)的 CPU 和內(nèi)存利用率,它是性能分析和調(diào)優(yōu)的基本工具,非常有用。 Kubernetes 也提供了類似的命令,就是 kubectl top ,不過默認情況下這個命令不會生效,必須要安裝一個插件 Metrics Server 才可以。

    2024年02月01日
    瀏覽(22)
  • Prometheus監(jiān)控Elasticsearch指標

    Prometheus 可以很方便的監(jiān)控 Elasticsearch 的指標。 方式一: 通過啟動ES自帶的監(jiān)控模塊暴露指標數(shù)據(jù),主要步驟如下: 在 Elasticsearch 中啟用監(jiān)控模塊修改 Elasticsearch 的配置文件,加入監(jiān)控相關(guān)配置: 重啟 Elasticsearch 實例后,監(jiān)控相關(guān) API 會自動啟用。 配置 Prometheus 監(jiān)控 Elasticsearch 在

    2024年02月09日
    瀏覽(19)
  • 利用Prometheus做指標統(tǒng)計

    背景:目前公司需要統(tǒng)計一些數(shù)據(jù), 而這些數(shù)據(jù)有些量非常大(千萬量級的數(shù)據(jù))。 如果在mysql中做統(tǒng)計, 可能會引發(fā)慢查詢或者造成mysql集群負載過高的問題。 目前業(yè)務(wù)沒有將這些數(shù)據(jù)同步到ES等數(shù)據(jù)庫, 如果為了統(tǒng)計而調(diào)整業(yè)務(wù), 這個改造成本比較高。 目前這些指標,

    2024年02月12日
    瀏覽(20)
  • Prometheus相關(guān)的主機監(jiān)控指標

    Prometheus相關(guān)的主機監(jiān)控指標

    CPU負載指標 node_load1 node_load5 node_load15 以上三個指標為主機CPU平均負載,分別對應(yīng)一分鐘、五分鐘和十五分鐘的時間間隔。CPU負載是指某段時間內(nèi)占用CPU時間的進程和等待CPU時間的進程數(shù)之和。一般來說,cpu負載數(shù)/cpu核數(shù)如果超過0.7,應(yīng)該開始關(guān)注機器性能情況 ,如果超過

    2023年04月17日
    瀏覽(23)
  • Prometheus實現(xiàn)自定義指標監(jiān)控

    Prometheus實現(xiàn)自定義指標監(jiān)控

    前面我們已經(jīng)通過 Prometheus+Grafana 實現(xiàn)了監(jiān)控,可以在 Grafana 上看到對應(yīng)的 SpringBoot 應(yīng)用信息了, 通過這些信息我們可以對 SpringBoot 應(yīng)用有更全面的監(jiān)控。 但是如果我們需要對一些業(yè)務(wù)指標做監(jiān)控,我們應(yīng)該怎么做呢?這篇文章就帶你一步步實現(xiàn)一個模擬的訂單業(yè)務(wù)指 標監(jiān)

    2024年02月12日
    瀏覽(31)
  • Prometheus監(jiān)控指標查詢性能調(diào)優(yōu)

    Prometheus監(jiān)控指標查詢性能調(diào)優(yōu)

    一、背景 在《SRE: Google運維解密》一書中作者指出,監(jiān)控系統(tǒng)需要能夠有效的支持白盒監(jiān)控和黑盒監(jiān)控。黑盒監(jiān)控只在某個問題目前正在發(fā)生,并且造成了某個現(xiàn)象時才會發(fā)出緊急警報。“白盒監(jiān)控則大量依賴對系統(tǒng)內(nèi)部信息的檢測,如系統(tǒng)日志、抓取提供指標信息的 HTTP 節(jié)

    2024年02月13日
    瀏覽(24)
  • Prometheus之rabbitmq監(jiān)控指標詳解

    rabbitmq_channels 用于顯示RabbitMQ服務(wù)器上當前打開的通道數(shù)量。 通過監(jiān)控這個指標,您可以了解到RabbitMQ服務(wù)器打開的通道數(shù)隨時間變化的情況,以及通道數(shù)量是否很高或者非常低。 rabbitmq_connections 用于顯示與RabbitMQ服務(wù)器的連接總數(shù)。 該指標可以幫助您跟蹤RabbitMQ服務(wù)器的連

    2024年02月14日
    瀏覽(24)
  • k8s v1.27.4 部署metrics-serverv:0.6.4,kube-prometheus

    k8s v1.27.4 部署metrics-serverv:0.6.4,kube-prometheus

    只有一個問題,原來的httpGet存活、就緒檢測一直不通過,于是改為tcpSocket后pod正常。 修改后的yaml文件,鏡像修改為阿里云 部署kube-prometheus 兼容1.27的為main分支 只克隆main分支 處理: 修改prometheus-clusterRole.yaml 使用ServiceMonitor添加監(jiān)控: 以ingress-nginx為例 修改ingress-nginx.yaml的

    2024年02月12日
    瀏覽(20)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包