自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在SpringBoot中如何通過Prometheus實時監(jiān)控系統(tǒng)各項指標

數(shù)據(jù)庫 其他數(shù)據(jù)庫
prometheus存儲的是時序數(shù)據(jù),即按相同時序(相同名稱和標簽),以時間維度存儲連續(xù)的數(shù)據(jù)的集合。

環(huán)境:springboot2.4.12 + prometheus1.6.7 + grafana7.5.7

什么是Prometheus

Prometheus 是一個開源的服務監(jiān)控系統(tǒng)和時間序列數(shù)據(jù)庫。

圖片圖片


prometheus存儲的是時序數(shù)據(jù),即按相同時序(相同名稱和標簽),以時間維度存儲連續(xù)的數(shù)據(jù)的集合。

時序(time series)是由名字(Metric)以及一組key/value標簽定義的,具有相同的名字以及標簽屬于相同時序。

配置依賴

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
  </dependency>
</dependencies
spring:
  application:
    name: app-prometheus
---
management:
  server:
    port: 9999
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: '*'

注冊MeterRegistry

@Bean
public MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String name) {
  return (registry) -> registry.config().commonTags("application", name);
}

訪問Prometheus actuator

圖片圖片

Springboot與Prometheus的整合完成。

Prometheus配置安裝

Prometheus下載

圖片圖片

通過如上地址下載自己需要的版本。

配置Prometheus

scrape_configs:
  - job_name: 'app-prometheus'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['localhost:9999']

localhost:9999為項目的Actuator訪問地址。

啟動Prometheus

圖片圖片

訪問

圖片圖片

查看監(jiān)控的應用

圖片圖片

圖片圖片

自定義meter

@Resource
private MeterRegistry registry ;
private Counter counter ;
  
@PostConstruct
public void init() {
  counter = this.registry.counter("vistor") ;
}


@GetMapping("/count")
public String count() {
  this.counter.increment() ; 
  return "訪問次數(shù):" + this.counter.count() ;
}

先多訪問幾次該接口,通過Prometheus查看

圖片圖片

Grafana安裝配置

下載

圖片圖片

通過上面的地址下載grafana

啟動服務

圖片圖片

默認用戶名密碼:admin/admin

圖片

添加Prometheus數(shù)據(jù)源

圖片圖片

查看數(shù)據(jù)

圖片圖片

圖片圖片

這里展示了visitor中的統(tǒng)計信息

監(jiān)控數(shù)據(jù)庫連接池

圖片圖片

先在grafana上搜索

圖片圖片


通過id導入

圖片圖片


圖片圖片

圖片圖片

項目中配置hikari數(shù)據(jù)庫連接池,grafana自動會展示數(shù)據(jù)庫連接信息

圖片圖片

完畢?。?!

責任編輯:武曉燕 來源: Spring全家桶實戰(zhàn)案例源碼
相關推薦

2023-12-29 08:01:52

自定義指標模板

2021-03-10 11:47:01

CPU服務器指標

2022-07-08 08:00:31

Prometheus監(jiān)控

2021-03-26 20:37:14

Prometheus監(jiān)控指標

2023-11-06 01:39:02

Go語言開發(fā)

2021-10-14 08:07:33

Go 應用Prometheus監(jiān)控

2022-05-12 08:01:26

vmagentprometheus

2017-04-20 14:55:36

LinuxPyinotifyPython

2025-03-11 00:25:00

Springmetrics數(shù)據(jù)

2025-04-08 05:00:00

2025-03-03 08:00:00

2022-03-14 08:25:49

云原生prometheusPushProx

2023-11-16 08:00:00

Datadog部署實時監(jiān)控

2024-04-08 08:00:00

云監(jiān)控監(jiān)控數(shù)據(jù)Prometheus

2024-06-14 08:19:45

2023-10-11 09:58:07

2021-04-07 14:53:09

Prometheus開源監(jiān)控

2020-12-30 08:09:46

運維Prometheus 監(jiān)控

2022-11-08 00:00:00

監(jiān)控系統(tǒng)Prometheus

2020-12-29 10:45:22

運維Prometheus-監(jiān)控
點贊
收藏

51CTO技術棧公眾號