最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot集成普羅米修斯(Prometheus)的方法

 更新時間:2020年08月08日 09:45:08   作者:方志朋  
這篇文章主要介紹了springboot集成普羅米修斯(Prometheus)的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

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

簡介

Prometheus 具有以下特點:

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

Prometheus 組成及架構(gòu)

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

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

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

一些其他的工具。

其大概的工作流程是:

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

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: 8081
spring:
 application:
  name: my-prometheus
management:
 endpoints:
  web:
   exposure:
    include: 'prometheus'
 metrics:
  tags:
   application: ${spring.application.name}

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

@RestController
public 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的一些監(jiān)控信息。

# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool
# TYPE jvm_gc_max_data_size_bytes gauge
jvm_gc_max_data_size_bytes{application="my-prometheus",} 2.863661056E9
# HELP http_server_requests_seconds 
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{application="my-prometheus",exception="None",method="GET",outcome="CLIENT_ERROR",status="404",uri="/**",} 1.0
http_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 gauge
http_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 gauge
jvm_threads_states_threads{application="my-prometheus",state="waiting",} 12.0
jvm_threads_states_threads{application="my-prometheus",state="runnable",} 8.0
jvm_threads_states_threads{application="my-prometheus",state="timed-waiting",} 2.0
jvm_threads_states_threads{application="my-prometheus",state="terminated",} 0.0
jvm_threads_states_threads{application="my-prometheus",state="blocked",} 0.0
jvm_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系統(tǒng)上安裝,執(zhí)行以下的安裝命令。其他的操作系統(tǒng),比如windows、mac等在官網(wǎng)上(https://prometheus.io/download/)下載并安裝。

wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.darwin-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd 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,配置多久抓一次監(jiān)控信息
  • config.metrics_path,獲取監(jiān)控信息的接口
  • config.static_configs.targets配置獲取監(jiān)控信息的地址。

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

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

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

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

安裝grafana

grafana 是一款采用 go 語言編寫的開源應(yīng)用,主要用于大規(guī)模指標數(shù)據(jù)的可視化展現(xiàn),是網(wǎng)絡(luò)架構(gòu)和應(yīng)用分析中最流行的時序數(shù)據(jù)展示工具,目前已經(jīng)支持絕大部分常用的時序數(shù)據(jù)庫。使用grafana去展示prometheus上的數(shù)據(jù)。先安裝,安裝命令如下:

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

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

配置數(shù)據(jù)源,如圖:

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

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

參考資料

[Prometheus 入門與實踐]

到此這篇關(guān)于springboot集成普羅米修斯(Prometheus)的方法的文章就介紹到這了,更多相關(guān)springboot集成普羅米修斯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java LinkedHashSet集合的底層原理和TreeSet集合

    Java LinkedHashSet集合的底層原理和TreeSet集合

    LinkedHashSet保證元素有序且唯一,底層通過雙鏈表實現(xiàn),TreeSet元素不重復且可排序,底層使用紅黑樹實現(xiàn)排序,自定義類型排序可通過實現(xiàn)Comparable接口或提供Comparator來定義排序規(guī)則,適用于需要大量元素快速檢索的場景
    2024-10-10
  • Java對象比較之equals與hashCode詳解

    Java對象比較之equals與hashCode詳解

    這篇文章主要介紹了Java對象比較之equals與hashCode詳解,equals?方法和?hashCode?方法是?Object?類中的兩個基礎(chǔ)方法,它們共同協(xié)作來判斷兩個對象是否相等,需要的朋友可以參考下
    2023-12-12
  • mybatis使用collection嵌套查詢的實現(xiàn)

    mybatis使用collection嵌套查詢的實現(xiàn)

    本文主要介紹了mybatis使用collection嵌套查詢的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • 幾種JAVA細粒度鎖的實現(xiàn)方式

    幾種JAVA細粒度鎖的實現(xiàn)方式

    這篇文章主要為大家詳細介紹了幾種JAVA細粒度鎖的實現(xiàn)方式,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Java中List集合按指定條件排序

    Java中List集合按指定條件排序

    這篇文章主要介紹了Java中List集合按指定條件排序,List是一種有序集合,可以隨時添加和刪除其中元素,本篇文章針對List集合按照條件排序的幾種方式做了實例演示,需要的朋友可以參考下
    2023-07-07
  • Java 裝箱與拆箱詳解及實例代碼

    Java 裝箱與拆箱詳解及實例代碼

    這篇文章主要介紹了Java 裝箱與拆箱詳解及實例代碼的相關(guān)資料,這里對java 的裝箱及拆箱進行了基本概念詳解及簡單使用,需要的朋友可以參考下
    2017-01-01
  • 10分鐘搞定Java并發(fā)隊列

    10分鐘搞定Java并發(fā)隊列

    這篇文章主要介紹了Java并發(fā)隊列,對此感興趣的同學,可以參考下
    2021-04-04
  • 詳解JavaEE中Apollo安裝使用小結(jié)

    詳解JavaEE中Apollo安裝使用小結(jié)

    這篇文章主要介紹了詳解JavaEE中Apollo安裝與使用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • spring boot Rabbit高級教程(最新推薦)

    spring boot Rabbit高級教程(最新推薦)

    RabbitMQ的消息過期是基于追溯方式來實現(xiàn)的,也就是說當一個消息的TTL到期以后不一定會被移除或投遞到死信交換機,而是在消息恰好處于隊首時才會被處理,本篇文章給大家介紹spring boot Rabbit高級教程,感興趣的朋友一起看看吧
    2023-10-10
  • Spring配置數(shù)據(jù)源的三種方式(小結(jié))

    Spring配置數(shù)據(jù)源的三種方式(小結(jié))

    本文主要介紹了Spring配置數(shù)據(jù)源的三種方式,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評論

沾益县| 重庆市| 浦北县| 九寨沟县| 洪洞县| 榆树市| 当涂县| 炉霍县| 弥渡县| 东阿县| 常熟市| 绥棱县| 张家川| 西吉县| 搜索| 读书| 灵璧县| 桃园市| 鹤庆县| 晋江市| 阿图什市| 黑龙江省| 久治县| 西峡县| 太和县| 琼海市| 肇州县| 阿城市| 抚州市| 长岛县| 南昌县| 泰兴市| 磐安县| 五常市| 临夏县| 姜堰市| 石河子市| 锡林郭勒盟| 汉寿县| 金堂县| 信阳市|