어플리케이션 모니터링하기 [springBoot actuator, springboot admin server - client]

공부는 혼자하는 거·2021년 11월 26일
0

Spring Tip

목록 보기
22/52

스프링 부트 액추에이터 사용

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html

https://www.baeldung.com/spring-boot-actuators

https://incheol-jung.gitbook.io/docs/study/srping-in-action-5th/chap-16.

https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/#logfile

httpStackTrace 활성화시키려면..

@Configuration
public class ActuatorConfig {

    @Bean
    public HttpTraceRepository httpTraceRepository(){
        return new InMemoryHttpTraceRepository();
    }
    
}

SBA 사용

클라이언트 yml 설정

<!--        반드시 서버 admin 과 버전을 맞춰줘야 된다.-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.4.1</version>
        </dependency>

서버 yml 설정

      <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.4.1</version>
        </dependency>


        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui-login</artifactId>
            <version>1.5.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.4.0</version>
        </dependency>


UI 는 라이브러리로 제공해준다.

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    private final AdminServerProperties adminServer;

    public WebSecurityConfig(AdminServerProperties adminServer) {
        this.adminServer = adminServer;
    }


    @Bean
    public CorsConfigurationSource corsConfigurationSource(){
        System.out.println("----------------cors config-----------------------");

        CorsConfiguration configuration = new CorsConfiguration();

        configuration.addAllowedOrigin("*");
        configuration.addAllowedMethod("*");
        configuration.addAllowedHeader("*");
        configuration.setAllowCredentials(true);
        configuration.setMaxAge(3600L);
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);

        System.out.println("----------------cors config end-----------------------");
        return source;
    }


//    @Override
//    public void configure(WebSecurity web) throws Exception {
//        web.ignoring()
//                .mvcMatchers();
//    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        SavedRequestAwareAuthenticationSuccessHandler successHandler =
                new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/");

        http
                .cors().configurationSource(corsConfigurationSource())
                .and()
                .authorizeRequests()
                .antMatchers(this.adminServer.getContextPath() + "/assets/**").permitAll()
                .antMatchers(this.adminServer.getContextPath() + "/login").permitAll()
                .antMatchers("/assets/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage(this.adminServer.getContextPath() + "/login")
                .successHandler(successHandler)
                .and()
                //.logout()
               // .logoutUrl(this.adminServer.path("/logout"))
                .logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout")))
                //.and()
                .httpBasic(Customizer.withDefaults())
                //.and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringRequestMatchers(
                        new AntPathRequestMatcher(this.adminServer.getContextPath() +
                                "/instances", HttpMethod.POST.toString()),
                        new AntPathRequestMatcher(this.adminServer.getContextPath() +
                                "/instances/*", HttpMethod.DELETE.toString()),
                        new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**"))
                .and()
                .rememberMe()
                .key(UUID.randomUUID().toString())
                .tokenValiditySeconds(1209600);
    }
}

https://github.com/codecentric/spring-boot-admin

https://codecentric.github.io/spring-boot-admin/current/#getting-started

https://www.baeldung.com/spring-boot-admin

https://otrodevym.tistory.com/entry/spring-boot-설정하기-12-adminsecurity-설정-및-테스트-소스

https://andole98.github.io/spring/spring-boot-admin/#

https://dncjf64.tistory.com/312

https://jaehyun8719.github.io/2019/06/20/springboot/admin/

https://www.youtube.com/watch?v=z0EaPjF3pCQ

https://drive.google.com/file/d/10G1qCgdFrVXpxLUTgrSwp5ZMboXlfwmH/view

https://niiiii99.github.io/Springboot-Admin/

https://stackoverflow.com/questions/39587818/actuator-custom-logfile-endpoint-possible

https://github.com/codecentric/spring-boot-admin/issues/1191

x-forward-proxy header

https://akageun.github.io/2019/08/08/spring-boot-admin-01.html

예제

https://github.com/stella6767/spring-boot-admin-example

profile
시간대비효율

0개의 댓글