SpringBoot使用SOFA-Lookout監(jiān)控的方法
本文介紹SpringBoot使用螞蟻金服SOFA-Lookout配合Prometheus進(jìn)行監(jiān)控。
1.SOFA-Lookout介紹
上一篇已經(jīng)介紹使用Prometheus進(jìn)行暴露SpringBoot的一些指標(biāo)進(jìn)行監(jiān)控,傳送門,這一篇介紹如何使用SOFA-Lookout配合Prometheus。
SOFA-Lookout是螞蟻金服開源的一款解決系統(tǒng)的度量和監(jiān)控問題的輕量級中間件服務(wù)。它提供的服務(wù)包括:Metrics 的埋點(diǎn)、收集、加工、存儲與查詢等。
正如介紹的,SOFA-Lookout提供了一些常用的監(jiān)控指標(biāo),比如JVM線程,JVM類加載,JVM內(nèi)存,JVM垃圾回收,機(jī)器文件系統(tǒng)信息和機(jī)器信息。在1.5.0版本之后默認(rèn)也提供了一些Linux操作系統(tǒng)的信息。具體可以查看:https://www.sofastack.tech/sofa-lookout/docs/client-ext-metrics
2.SpringBoot使用SOFA-Lookout
2.1 配置依賴
新建項(xiàng)目,在項(xiàng)目中加入SOFA依賴,完整pom如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dalaoyang</groupId>
<artifactId>springboot2_sofa_lookout</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot2_sofa_lookout</name>
<description>springboot2_sofa_lookout</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-sofa-boot-starter</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa.lookout</groupId>
<artifactId>lookout-reg-prometheus</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.2 配置SOFA-Lookout端口
這里需要配置一個SOFA-Lookout的端口,生產(chǎn)環(huán)境使用的話一定要查看這個端口是不是被占用了。配置如下,這里配置的端口是8081。
spring.application.name=springboot2_sofa_lookout com.alipay.sofa.lookout.prometheus-exporter-server-port=8081
其實(shí)到這里,SpringBoot項(xiàng)目已經(jīng)配置完成了,當(dāng)然還可以自定義一些指標(biāo),這里不做介紹。
3.Prometheus配置
Prometheus需要配置一下剛剛SOFA-Lookout的端口,如下:
- job_name: 'springboot2_sofa_lookout' scrape_interval: 5s static_configs: - targets: ['localhost:8081']
4.Grafana
這里也可以將Prometheus展示給Grafana,我也查詢了很多,但是貌似目前Grafana還沒有默認(rèn)推薦的Dashboard,大家可以根據(jù)情況自行構(gòu)建,當(dāng)然,如果有好的也希望可以推薦一下。
5.測試
啟動SpringBoot應(yīng)用,控制臺如下所示。

看到紅框部分就是啟動成功了。接下來查看Prometheus界面,如下。

這里Grafana在看一下Grafana界面,如圖。

6.源碼
源碼地址:https://gitee.com/dalaoyang/springboot_learn/tree/master/springboot2_sofa_lookout
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringBoot+Swagger-ui自動生成API文檔
- SpringBoot與Quartz集成實(shí)現(xiàn)分布式定時任務(wù)集群的代碼實(shí)例
- SpringBoot項(xiàng)目整合mybatis的方法步驟與實(shí)例
- 淺談Java(SpringBoot)基于zookeeper的分布式鎖實(shí)現(xiàn)
- SpringBoot整個啟動過程的分析
- 詳解SpringBoot注冊Windows服務(wù)和啟動報(bào)錯的原因
- SpringBoot深入理解之內(nèi)置web容器及配置的總結(jié)
- SpringBoot集成shiro,MyRealm中無法@Autowired注入Service的問題
- SpringBoot thymeleaf eclipse熱部署方案操作步驟
- 在spring boot中使用java線程池ExecutorService的講解
相關(guān)文章
Mybatis-plus數(shù)據(jù)權(quán)限D(zhuǎn)ataPermissionInterceptor實(shí)現(xiàn)
本文主要介紹了Mybatis-plus數(shù)據(jù)權(quán)限D(zhuǎn)ataPermissionInterceptor實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
SpringBoot時區(qū)問題解決以及徹底解決時差問題
這篇文章主要給大家介紹了關(guān)于SpringBoot時區(qū)問題解決以及徹底解決時差問題的相關(guān)資料,spring?boot作為微服務(wù)簡易架構(gòu),擁有其自身的特點(diǎn),快速搭建架構(gòu),簡單快捷,需要的朋友可以參考下2023-08-08
springboot中設(shè)置定時任務(wù)的三種方法小結(jié)
在我們開發(fā)項(xiàng)目過程中,經(jīng)常需要定時任務(wù)來幫助我們來做一些內(nèi)容,本文介紹了springboot中設(shè)置定時任務(wù)的三種方法,主要包括@Scheduled注解,Quartz框架和xxl-job框架的實(shí)現(xiàn),感興趣的可以了解一下2023-12-12
JavaWeb-WebSocket瀏覽器服務(wù)器雙向通信方式
文章介紹了WebSocket協(xié)議的工作原理和應(yīng)用場景,包括與HTTP的對比,接著,詳細(xì)介紹了如何在Java中使用WebSocket,包括配置類、服務(wù)編寫和前端頁面的實(shí)現(xiàn)2025-02-02
基于java ssm springboot+mybatis酒莊內(nèi)部管理系統(tǒng)設(shè)計(jì)和實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了java ssm springboot+mybatis實(shí)現(xiàn)酒店管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
Mybatis 傳參與排序模糊查詢功能實(shí)現(xiàn)
這篇文章主要介紹了Mybatis 傳參與排序模糊查詢功能實(shí)現(xiàn),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2025-04-04

