1. <nobr id="easjo"><address id="easjo"></address></nobr>

      <track id="easjo"><source id="easjo"></source></track>
      1. 
        

      2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
      3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>
          貴州做網站公司
          貴州做網站公司~專業!靠譜!
          10年網站模板開發經驗,熟悉國內外開源網站程序,包括DEDECMS,WordPress,ZBlog,Discuz! 等網站程序,可為您提供網站建設,網站克隆,仿站,網頁設計,網站制作,網站推廣優化等服務。我們專注高端營銷型網站,企業官網,集團官網,自適應網站,手機網站,網絡營銷,網站優化,網站服務器環境搭建以及托管運維等。為客戶提供一站式網站解決方案?。?!

          prometheus(springboot中Prometheus的簡介及用法)

          來源:互聯網轉載 時間:2024-05-12 15:09:56

          Prometheus 是一套開源的系統監控報警框架。它由工作在 SoundCloud 的 員工創建,并在 2015 年正式發布的開源項目。2016 年,Prometheus 正式加入 Cloud Native Computing Foundation,非常的受歡迎。

          簡介

          Prometheus 具有以下特點:

          • 一個多維數據模型,其中包含通過度量標準名稱和鍵/值對標識的時間序列數據
          • PromQL,一種靈活的查詢語言,可利用此維度
          • 不依賴分布式存儲; 單服務器節點是自治的
          • 時間序列收集通過HTTP上的拉模型進行
          • 通過中間網關支持推送時間序列
          • 通過服務發現或靜態配置發現目標
          • 多種圖形和儀表板支持模式

          Prometheus 組成及架構

          聲明:該小節參考了文章[Prometheus 入門與實踐]

          Prometheus 生態圈中包含了多個組件,其中許多組件是可選的:

          • Prometheus Server: 用于收集和存儲時間序列數據。
          • Client Library: 客戶端庫,為需要監控的服務生成相應的 metrics 并暴露給 Prometheus server。當 Prometheus server 來 pull 時,直接返回實時狀態的 metrics。
          • Push Gateway: 主要用于短期的 jobs。由于這類 jobs 存在時間較短,可能在 Prometheus 來 pull 之前就消失了。為此,這次 jobs 可以直接向 Prometheus server 端推送它們的 metrics。這種方式主要用于服務層面的 metrics,對于機器層面的 metrices,需要使用 node exporter。
          • Exporters: 用于暴露已有的第三方服務的 metrics 給 Prometheus。
          • Alertmanager: 從 Prometheus server 端接收到 alerts 后,會進行去除重復數據,分組,并路由到對收的接受方式,發出報警。常見的接收方式有:電子郵件,pagerduty,OpsGenie, webhook 等。

          一些其他的工具。

          其大概的工作流程是:

          1.Prometheus server 定期從配置好的 jobs 或者 exporters 中拉 metrics,或者接收來自 Pushgateway 發過來的 metrics,或者從其他的 Prometheus server 中拉 metrics。
          2.Prometheus server 在本地存儲收集到的 metrics,并運行已定義好的 alert.rules,記錄新的時間序列或者向 Alertmanager 推送警報。
          3.Alertmanager 根據配置文件,對接收到的警報進行處理,發出告警。
          4.在圖形界面中,可視化采集數據。

          springboot 集成prometheus

          在spring boot工程中引入actuator的起步依賴,以及micrometer-registry-prometheus的依賴。

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

          暴露prometheus的接口;暴露metrics.tags,和spring.application.name一致。

          server: port: 8081spring: application:  name: my-prometheusmanagement: endpoints:  web:   exposure:    include: 'prometheus' metrics:  tags:   application: ${spring.application.name}

          寫一個API接口,用作測試。代碼如下:

          @RestControllerpublic class TestController {  Logger logger = LoggerFactory.getLogger(TestController.class);  @GetMapping("/test")  public String test() {    logger.info("test");    return "ok";  }  @GetMapping("")  public String home() {    logger.info("home");    return "ok";  }}

          在瀏覽器上訪問http://localhost:8081/actuator/prometheus,展示的信息如下,這些信息都是actuator的一些監控信息。

          # HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool# TYPE jvm_gc_max_data_size_bytes gaugejvm_gc_max_data_size_bytes{application="my-prometheus",} 2.863661056E9# HELP http_server_requests_seconds # TYPE http_server_requests_seconds summaryhttp_server_requests_seconds_count{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 1.0http_server_requests_seconds_sum{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327# HELP http_server_requests_seconds_max # TYPE http_server_requests_seconds_max gaugehttp_server_requests_seconds_max{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 0.018082327# HELP jvm_threads_states_threads The current number of threads having NEW state# TYPE jvm_threads_states_threads gaugejvm_threads_states_threads{application="my-prometheus",state="waiting",} 12.0jvm_threads_states_threads{application="my-prometheus",state="runnable",} 8.0jvm_threads_states_threads{application="my-prometheus",state="timed-waiting",} 2.0jvm_threads_states_threads{application="my-prometheus",state="terminated",} 0.0jvm_threads_states_threads{application="my-prometheus",state="blocked",} 0.0jvm_threads_states_threads{application="my-prometheus",state="new",} 0.0# HELP process_files_open_files The open file descriptor count# TYPE process_files_open_files gauge...省略更多

          安裝Prometheus

          安裝Prometheus很簡單,在linux系統上安裝,執行以下的安裝命令。其他的操作系統,比如windows、mac等在官網上(https://prometheus.io/download/)下載并安裝。

          wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.darwin-amd64.tar.gztar xvfz prometheus-*.tar.gzcd prometheus-*

          修改Prometheus的配置文件prometheus.yml,代碼如下:

          global: scrape_interval:   15s # By default, scrape targets every 15 seconds. # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels:  monitor: 'codelab-monitor'# 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'  # Override the global default and scrape targets from this job every 5 seconds.  scrape_interval: 5s  static_configs:   - targets: ['localhost:9090'] - job_name: 'springboot_prometheus'  scrape_interval: 5s  metrics_path: '/actuator/prometheus'  static_configs:   - targets: ['127.0.0.1:8081']
          • config.job_name,配置job的名稱
          • config.scrape_interval,配置多久抓一次監控信息
          • config.metrics_path,獲取監控信息的接口
          • config.static_configs.targets配置獲取監控信息的地址。

          使用以下的命令啟動prometheus,并通過–config.file指定配置文件

          ./prometheus --config.file=prometheus.yml

          多次請求springboot項目的接口http://localhost:8081/test , 并訪問prometheus的控制臺http://localhost:9090/,展示的界面如下:

          prometheus提供了一些可視化圖,比如使用柱狀圖來展示每秒請求數:

          安裝grafana

          grafana 是一款采用 go 語言編寫的開源應用,主要用于大規模指標數據的可視化展現,是網絡架構和應用分析中最流行的時序數據展示工具,目前已經支持絕大部分常用的時序數據庫。使用grafana去展示prometheus上的數據。先安裝,安裝命令如下:

          wget https://dl.grafana.com/oss/release/grafana-7.0.4.darwin-amd64.tar.gztar -zxvf grafana-7.0.4.darwin-amd64.tar.gz./grafana-server

          訪問http://localhost:3000/,初始密碼:admin/admin。

          配置數據源,如圖:

          配置prometheus的地址:http://localhost:9090 ,如圖所示:

          在dashboard界面新建panel,展示的metrics為http_server_request_seconds_count,即展示了以時間為橫軸,請求數為縱軸的請求曲線,如圖所示:

          看完了這篇文章,相信你對springboot中Prometheus的簡介及用法有了一定的了解,想了解更多相關知識,歡迎關注本站行業資訊頻道,感謝各位的閱讀!

          標簽:prometheus-

          c語言中正確的字符常量是用一對單引號將一個字符括起表示合法的字符常量。例如‘a’。數值包括整型、浮點型。整型可用十進制,八進制,十六進制。八進制前面要加0,后面...

          2022年天津專場考試原定于3月19日舉行,受疫情影響確定延期,但目前延期后的考試時間推遲。 符合報名條件的考生,須在規定時間登錄招考資訊網(www.zha...

          :喜歡聽,樂意看。指很受歡迎?!巴卣官Y料”喜聞樂見:[ xǐ wén lè jiàn ]詳細解釋1. 【解釋】:喜歡聽,樂意看。指很受歡迎。2. 【示例】:這是...

          國債逆回購利率正常是多少?3%,國債逆回購一般是三個點左右的平均利率,好的話可能有3.5%,國債逆回購利率不是固定的,不同期限的國債逆回購利率也會有所不同,一般在月底或者年底的時候,銀行缺錢時國債逆回購的利率會高一些。收益該怎么計算?債券逆回購收益=成交額×年收益率×實際占款天數/365天。實際占款天數,是指當次回購交易的首次交收日(含)至到期交收日(不含)的實際日歷天數。...

          賣家承擔運費是指從賣家處發貨到買家處的大陸地區首次發貨運費,由賣家承擔,不需要買家支付。買家只需要支付所挑選商品的費用即可。1、淘寶買家在發現商品出現問題時一定要提前和賣家協定退貨的事宜,很多商品是用戶自己不會操作,從而導致的效果不佳,經過客服的指導之后,如果發現產品的效果有所改觀的話,就不需要再退貨了!如果效果實在不行的話,買家就需要申請退貨退款,在買家申請退款時,賣家就會告訴買家退貨的地址,并...

          根據新聞報道,美聯儲預計在5月粉大幅加息,而隨著美國經濟的情況的變化,開始更大規??s表的概率大大提高,那么美國縮表是啥意思?美國縮表意味著什么?下文就來帶大家了解一下。美國縮表的意思是指美聯儲縮減資產負債表。數據顯示,2020年疫情爆發以來,美聯儲的資產負債持續擴大,ONRRP工具用量已經突破1.5萬億,美聯儲官員曾多次強調,未來將要進行縮表??s表是一種縮減資產負債表的方式,所以簡單理解的話,那就...

          TOP
          国产初高中生视频在线观看|亚洲一区中文|久久亚洲欧美国产精品|黄色网站入口免费进人
          1. <nobr id="easjo"><address id="easjo"></address></nobr>

              <track id="easjo"><source id="easjo"></source></track>
              1. 
                

              2. <bdo id="easjo"><optgroup id="easjo"></optgroup></bdo>
              3. <track id="easjo"><source id="easjo"><em id="easjo"></em></source></track><option id="easjo"><span id="easjo"><em id="easjo"></em></span></option>