iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot-Admin实现微服务监控+健康检查+钉钉告警
  • 515
分享到

SpringBoot-Admin实现微服务监控+健康检查+钉钉告警

2024-04-02 19:04:59 515人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

基于SpringCloud微服务平台,进行服务实例监控及健康检查,注册中心为eureka,SpringBoot提供了很好的组件springBoot Admin,2.X版本直接可以配置

基于SpringCloud微服务平台,进行服务实例监控及健康检查,注册中心为eureka,SpringBoot提供了很好的组件springBoot Admin,2.X版本直接可以配置钉钉机器人告警。

效果:可以实现eureka注册的实例上线、下线触发钉钉告警。监控我们的服务实例健康检查。

搭建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监控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;


@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;


@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实现微服务监控+健康检查+钉钉告警的文章就介绍到这了,更多相关SpringBoot-Admin 微服务监控内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: SpringBoot-Admin实现微服务监控+健康检查+钉钉告警

本文链接: https://www.lsjlt.com/news/155911.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • SpringBoot-Admin实现微服务监控+健康检查+钉钉告警
    基于SpringCloud微服务平台,进行服务实例监控及健康检查,注册中心为eureka,SpringBoot提供了很好的组件SpringBoot Admin,2.X版本直接可以配置...
    99+
    2024-04-02
  • SpringBoot-Admin如何实现微服务监控+健康检查+钉钉告警
    小编给大家分享一下SpringBoot-Admin如何实现微服务监控+健康检查+钉钉告警,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!基于SpringCloud微服务平台,进行服务实例监控及健康检查,注册中心为eureka...
    99+
    2023-06-25
  • SpringBoot Admin健康检查功能的实现
    目录admin实现admin功能创建客户端主动上报的服务端实现效果异常通知邮件通知其他通知代码地址admin 监控检查,检查的是什么了。检查的是应用实例状态,说白了就是被查服务提供信...
    99+
    2024-04-02
  • 服务器健康检查:掌握服务器硬件监控的艺术
    服务器健康检查是系统管理和网络可靠性中至关重要的任务。通过定期监控服务器硬件,管理员可以识别潜在问题,防止宕机,并优化服务器性能。以下是掌握服务器硬件监控的关键步骤: 1. 确定监控指标 服务器硬件监控的目标是检测可能影响服务器性能和可...
    99+
    2024-04-02
  • SpringBoot整合Spring Boot Admin实现服务监控的方法
    目录1. Server端服务开发1.1. 引入核心依赖1.2. application.yml配置文件1.3. Security配置文件1.4. 主启动类2. Client端服务开发...
    99+
    2024-04-02
  • Rancher+Docker+SpringBoot实现微服务部署、扩容、环境监控
    目录前言一、前置需求1.linux虚拟机或系统2.创建好docker环境3.写一个简单的微服务并创建为docker镜像二、安装Rancher1.拉取rancher镜像2.启动ranc...
    99+
    2024-04-02
  • 如何使用PHP微服务实现分布式监控和报警功能
    随着互联网的快速发展,应用系统的规模和复杂性也逐渐增加。为了确保系统的稳定性和可用性,分布式监控和报警功能成为了每个开发人员都需要关注的重要问题。本文将介绍如何使用PHP微服务来实现分布式监控和报警功能,并提供具体的代码示例。一、概述分布式...
    99+
    2023-10-21
    分布式监控 PHP微服务 报警功能
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作