java - Spring Boot 管理页面

标签 java spring-boot monitoring spring-boot-actuator spring-boot-admin

我试图了解如何在我的应用程序中使用 SBAP,因为它是一个非常方便的开发工具。我正在阅读他们的 reference guide但我不明白一些事情。 这是我现在的应用程序的 pom:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <packaging>war</packaging>

    <groupId>com.batch.books.test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>1.3.1.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <version>1.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>test</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

这是我的Application.java:

package app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class Application {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

}

还有我的application.yml 文件:

info:
  version: @pom.version@
  stage: test

spring:
  application:
    name: @pom.artifactId@
  boot:
    admin:
      url: http://localhost:8080

其余的我很困惑。

  1. 那么我是否将我的应用程序注册为服务器和客户端?
  2. 如何运行此应用程序并访问管理页面?他们没有提到任何可以访问管理页面的 URL。是否只是:http://localhost:8080
  3. 如何为开发设置它,但在生产中关闭它?底部的引用指南说:

Can I include spring-boot-admin into my business application?

tl;dr You can, but you shouldn’t. You can set spring.boot.admin.context-path to alter the path where the UI and REST-api is served, but depending on the complexity of your application you might get in trouble. On the other hand in my opinion it makes no sense for an application to monitor itself. In case your application goes down your monitioring tool also does.

我的意思是你不应该在生产中使用它。因此,如果您不能使用 spring boot admin 来监控生产中的应用程序,那又有什么意义呢?是否有 2 个应用程序的解决方案,1 个是您的业务应用程序,另一个是监控业务应用程序的监控应用程序?

最佳答案

  1. So am I registering my application as the server and the client?

在你的例子中,你做到了。管理服务器是其自身的客户端不是问题。事实上,spring-boot-admin-sample 是以这种方式配置的,因此您可以获得有关管理服务器本身的信息。

  1. How do I run this application and access the admin page? They don't mention any URL to go to to see the admin page. Is it just: http://localhost:8080?

是的。如果你没有设置 spring.boot.admin.context-path admin 是在 root 上服务的。因此,如果您在业务应用程序中提供管理员,则应配置 spring.boot.admin.context-path 以便在其他地方提供服务。

  1. How do I set this up for development but turn it off in production? There reference guide at the bottom says: ...

关键是要使用两个单独的应用程序。这就是我们从开发阶段到质量保证阶段再到生产阶段的方式。我们总是将业务与管理服务器分开。如果您想有条件地在业务应用程序中启用管理服务器,请尝试以下方法: 编写一个 @Configuration 类,它只在特定配置文件中处于 Activity 状态,并将 @EnableAdminServer 移至此配置。

希望这对您有所帮助。

关于java - Spring Boot 管理页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34905356/

相关文章:

java - 检查 Android 中的子 Firebase 数据库中是否存在值

java - 用于匹配引号内模式的正则表达式

java - 重写应用程序 MVC 风格

google-app-engine - 需要 "appengine.applications.get"权限

mysql - 让 Prometheus 发送 SQL 查询

ruby-on-rails - [prometheus, rails]如何在rails服务器上启用prometheus

java - 关于 JPQL 的困惑

java - Spring Boot 和 OAuth2.0 : At least one redirect_uri must be registered with the client

java - @ConditionalOnMissingBean 和 @ConditionalOnBean 位于同一类型上

linux - Icinga 2 安装