springboot admin 监控springcloud 组件化服务

springboot admin 监控springcloud 组件化服务,SpringBoot 2.x 监控中心:Admin

最近公司新项目架构重新搭建,项目服务化之后,对服务的治理以及监控,稳定性要到位。所以鄙人在此集成了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);
}
}


启动服务之后,访问界面如下:

attachments-2019-08-nRiRxo4I5d4a4047b8bc7.png


至此,服务端已经部署完毕(因为我这里已经是集成好了的,监控的服务所以这里是我们项目的服务)


二、客户端集成

 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的监控,控制台不刷新可以实时看到。


  • 发表于 2019-08-07 10:59
  • 阅读 ( 246 )
  • 分类:Java

1 条评论

请先 登录 后评论
不写代码的码农
威猛的小站长

107 篇文章

作家榜 »

  1. 威猛的小站长 107 文章
  2. Jonny 65 文章
  3. 江南烟雨 33 文章
  4. - Nightmare 33 文章
  5. doublechina 31 文章
  6. HJ社区-肖峰 29 文章
  7. 伪摄影 20 文章
  8. Alan 14 文章