欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot-Admin實現微服務監(jiān)控+健康檢查+釘釘告警

 更新時間:2021年10月29日 15:21:03   作者:一張船票  
本文主要介紹了SpringBoot-Admin實現微服務監(jiān)控+健康檢查+釘釘告警,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于SpringCloud微服務平臺,進行服務實例監(jiān)控及健康檢查,注冊中心為eureka,SpringBoot提供了很好的組件SpringBoot Admin,2.X版本直接可以配置釘釘機器人告警。

效果:可以實現eureka注冊的實例上線、下線觸發(fā)釘釘告警。監(jiān)控我們的服務實例健康檢查。

搭建admin-server

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 https://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.4.11</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>admin-server</artifactId>
	<version>1.0.0</version>
	<name>etc-admin-server</name>
	<description>Spring Boot Admin監(jiān)控eureka服務實例和健康檢查,釘釘告警</description>
	<properties>
		<java.version>1.8</java.version>
		<spring-boot-admin.version>2.4.3</spring-boot-admin.version>
		<spring-cloud.version>2020.0.4</spring-cloud.version>
	</properties>
	<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
		<dependency>
			<groupId>de.codecentric</groupId>
			<artifactId>spring-boot-admin-starter-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<dependency>
				<groupId>de.codecentric</groupId>
				<artifactId>spring-boot-admin-dependencies</artifactId>
				<version>${spring-boot-admin.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
        <finalName>${project.name}</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

application.yml配置

spring:
  application:
    name: admin-server
  security:
    user:
      name: "admin"
      password: "pwd"

  boot:
    admin:
      notify:
        dingtalk:
          enabled: true
          webhookUrl: 'https://oapi.dingtalk.com/robot/send?access_token=釘釘機器人access_token'
          secret: '釘釘機器人secret'
          message: '服務告警: #{instance.registration.name} #{instance.id} is #{event.statusInfo.status}'
server:
  port: 9002

eureka:
  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: 'http://127.0.0.1:8020/eureka/'
  instance:
    hostname: ${spring.cloud.client.ip-address}
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    prefer-ip-address: true
    ip-address: ${spring.cloud.client.ip-address}
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

啟動類

package com.example;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @author xxx
 */
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication
public class AdminServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(AdminServerApplication.class, args);
	}
}

config類

package com.example;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

/**
 * WebSecurity配置
 * @author xxxx
 */
@Configuration
public class WebSecurityConfigure extends WebSecurityConfigurerAdapter {

    private final String adminContextPath;

    public WebSecurityConfigure(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                .antMatchers(adminContextPath + "/login").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                .logout().logoutUrl(adminContextPath + "/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        adminContextPath + "/instances",
                        adminContextPath + "/actuator/**"
                );
        // @formatter:on
    }
}

啟動后效果

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

到此這篇關于SpringBoot-Admin實現微服務監(jiān)控+健康檢查+釘釘告警的文章就介紹到這了,更多相關SpringBoot-Admin 微服務監(jiān)控內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 教你一步解決java.io.FileNotFoundException:找不到文件異常

    教你一步解決java.io.FileNotFoundException:找不到文件異常

    這篇文章主要給大家介紹了關于如何一步解決java.io.FileNotFoundException:找不到文件異常的相關資料,文中通過圖文以及代碼介紹的非常詳細,需要的朋友可以參考下
    2024-01-01
  • java web中圖片驗證碼功能的簡單實現方法

    java web中圖片驗證碼功能的簡單實現方法

    下面小編就為大家?guī)硪黄猨ava web 驗證碼的簡單實現方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • Java List簡介_動力節(jié)點Java學院整理

    Java List簡介_動力節(jié)點Java學院整理

    Java中可變數組的原理就是不斷的創(chuàng)建新的數組,將原數組加到新的數組中,下文對Java List用法做了詳解。需要的朋友參考下吧
    2017-05-05
  • Java刪除文件、目錄及目錄下所有文件的方法實例

    Java刪除文件、目錄及目錄下所有文件的方法實例

    這篇文章主要給大家介紹了關于利用Java刪除文件、目錄及目錄下所有文件的方法,文中給出了詳細的示例代碼與注解,有需要的朋友可以參考借鑒,下面來一起看看吧。
    2016-12-12
  • 解析java.library.path和LD_LIBRARY_PATH的介紹與區(qū)別

    解析java.library.path和LD_LIBRARY_PATH的介紹與區(qū)別

    這篇文章主要介紹了java.library.path和LD_LIBRARY_PATH的介紹與區(qū)別,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-05-05
  • Sentinel實現動態(tài)配置的集群流控的方法

    Sentinel實現動態(tài)配置的集群流控的方法

    這篇文章主要介紹了Sentinel實現動態(tài)配置的集群流控,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • ant使用指南詳細入門教程

    ant使用指南詳細入門教程

    這篇文章主要介紹了ant使用指南詳細入門教程,本文詳細的講解了安裝、驗證安裝、使用方法、使用實例、ant命令等內容,需要的朋友可以參考下
    2015-06-06
  • SpringBoot+slf4j實現全鏈路調用日志跟蹤的方法(一)

    SpringBoot+slf4j實現全鏈路調用日志跟蹤的方法(一)

    本文重點給大家介紹Tracer集成的slf4j MDC功能,方便用戶在只簡單修改日志配置文件的前提下輸出當前 Tracer 上下文 TraceId,文章通過代碼給大家講解了在springboot中使用的技巧,感興趣的朋友跟隨小編一起看看吧
    2021-05-05
  • 詳解JUC 常用4大并發(fā)工具類

    詳解JUC 常用4大并發(fā)工具類

    這篇文章主要介紹了JUC 常用4大并發(fā)工具類的相關資料,幫助大家更好的理解和學習Java 并發(fā)編程,感興趣的朋友可以了解下
    2020-10-10
  • springboot跨域CORS處理代碼解析

    springboot跨域CORS處理代碼解析

    這篇文章主要介紹了springboot跨域CORS處理代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-12-12

最新評論