最近公司新项目架构重新搭建,项目服务化之后,对服务的治理以及监控,稳定性要到位。所以鄙人在此集成了springboot admin进行了简单的监控。
一、服务端集成
集成gradle 依赖
group 'com.whale.v2'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
set('springCloudVersion', "Greenwich.SR1")
}
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public"}
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'app-admin'
version = '1.0.0'
enabled = true
}
bootJar {
manifest {
attributes 'Start-Class': 'com.whale.admin.AdminServerApplication'
}
version = '1.0.0'
}
sourceCompatibility = 1.8
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public"}
jcenter()
}
dependencies {
api('org.springframework.boot:spring-boot-starter-web')
//邮件通知
api('org.springframework.boot:spring-boot-starter-mail')
//服务端:带UI界面
api 'de.codecentric:spring-boot-admin-starter-server:2.1.6'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
application.yml 配置
server: port: 8900 spring: application: name: whale-admin mail: host: smtp.qq.com username: noreply@xxx.cn password: xxxx properties: mail: smtp: auth: true starttls: enable: true required: true boot: admin: notify: mail: ## 接收告警通知的人 to: 127821@xxx.cn ## 发送者 from: noreply@xxx.cn
启动类:
package com.whale.admin;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
启动服务之后,访问界面如下:
至此,服务端已经部署完毕(因为我这里已经是集成好了的,监控的服务所以这里是我们项目的服务)
二、客户端集成
1、gradle依赖
buildscript { ext { springBootVersion = '2.1.0.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.admin' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile('org.springframework.boot:spring-boot-starter-web') //客户端包 compile 'de.codecentric:spring-boot-admin-starter-client:2.1.6' compile ('org.springframework.boot:spring-boot-starter-security') }
application.yml 配置
server: port: 8081 spring: boot: admin: client: url: "http://localhost:8900" management: endpoints: web: exposure: include: "*"
最后,客户端一启动,就会将服务加入到 springboot admin的监控,控制台不刷新可以实时看到。
124 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!