Spring Actuator 기초 설정 & IntelliJ 활용하기

Share
Spring Actuator 기초 설정 & IntelliJ 활용하기

해당 코드는 Github에 공개되어 있습니다.

스프링은 Actuator를 이용해서 애플리케이션 상태를 종합적으로 모니터링할 수 있습니다.

의존성 주입

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

actuator 호출

http://localhost:8890/actuator를 호출하면 위와 같은 Response를 받을 수 있습니다. 기본 설정으로는 모든 endpoint가 노출돼있지는 않습니다. 모든 endpoint를 노출하도록 설정해보겠습니다.

endpoints 전체 노출

# application.yml
management:
  endpoints:
    web:
      exposure:
        include: "*"

application.yml 설정을 변경하고 다시 /actuator 호출하면 아래 Response와 같습니다.

{
    "_links": {
        "self": {
            "href": "http://localhost:8890/actuator",
            "templated": false
        },
        "auditevents": {
            "href": "http://localhost:8890/actuator/auditevents",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:8890/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:8890/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://localhost:8890/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8890/actuator/health",
            "templated": false
        },
        "health-component": {
            "href": "http://localhost:8890/actuator/health/{component}",
            "templated": true
        },
        "health-component-instance": {
            "href": "http://localhost:8890/actuator/health/{component}/{instance}",
            "templated": true
        },
        "conditions": {
            "href": "http://localhost:8890/actuator/conditions",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:8890/actuator/configprops",
            "templated": false
        },
        "env": {
            "href": "http://localhost:8890/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:8890/actuator/env/{toMatch}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:8890/actuator/info",
            "templated": false
        },
        "loggers": {
            "href": "http://localhost:8890/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://localhost:8890/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://localhost:8890/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:8890/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8890/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8890/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:8890/actuator/scheduledtasks",
            "templated": false
        },
        "httptrace": {
            "href": "http://localhost:8890/actuator/httptrace",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:8890/actuator/mappings",
            "templated": false
        }
    }
}

경로 설명
/beans 초기화된 모든 스프링 빈의 목록을 표시
/env 스프링 설정 가능한 환경 속성 목록욜 표시, OS 환경 변수 및 컨피규레이션 파일의 속성 목록
/health 애플리케이션 상태 정보 표시
/info 애플리케이션의 임의 정보 표시 properties 등
/loggers 로거 컨피규레이션 정보를 표시하고 수정
/metrics 매트릭스 정보를 표시(메모리, 실행중인 스레드 수, REST 메서드 응답 시간)
/trace 트레이스 정뵤 표시(기본적으로 마지막 100개의 HTTP Request)

다양한 정보들이 포함되어 있습니다. 필요한 정보들을 확인한 후 아래와 같이 필요한 정보들만 노출할 수 있습니다.

management:
  endpoints:
    web:
      exposure:
        include:
          - "info"
          - "health"
          - "httptrace"

application.yml 변경이후 다시 /actuator을 호출하면 include에 포함시킨 endpoint만 Response 받게 됩니다.

{
  "_links": {
    "self": {
      "href": "http://localhost:8890/actuator",
      "templated": false
    },
    "health": {
      "href": "http://localhost:8890/actuator/health",
      "templated": false
    },
    "health-component": {
      "href": "http://localhost:8890/actuator/health/{component}",
      "templated": true
    },
    "health-component-instance": {
      "href": "http://localhost:8890/actuator/health/{component}/{instance}",
      "templated": true
    },
    "info": {
      "href": "http://localhost:8890/actuator/info",
      "templated": false
    },
    "httptrace": {
      "href": "http://localhost:8890/actuator/httptrace",
      "templated": false
    }
  }
}

Info Git Info 노출하기

기본 설정에서 actuator/info 호출시 아무 정보도 Response를 하지 않습니다. plugin을 이용하면 git에 대한 정보를 쉽게 노출할 수 있습니다.

buildscript {
    ...
    dependencies {
        ...
        classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:2.0.0"
    }
}
apply plugin: "com.gorylenko.gradle-git-properties"

필요한 디펜던시를 추가합니다.

management:
  ...
  info:
    git:
      mode: SIMPLE # FULL or SIMPLE

git 정보에 대한 mode를 SMPLE, FULL을 지정할 수 있습니다. 이후에 서버를 실행시키면 아래 그림처럼 git.properties 파일에 Git에 대한 정보가 담겨있습니다.

SIMPLE Mode

{
  "git": {
    "commit": {
      "time": "2019-07-02T16:31:35Z",
      "id": "293e840"
    },
    "branch": "master"
  }

FULL Mode

{
  "git": {
    "build": {
      "host": "yun",
      "version": "0.0.1-SNAPSHOT",
      "time": "2019-07-03T16:49:41Z",
      "user": {
        "name": "Yun",
        "email": "cheese10yun@gmail.com"
      }
    },
    "branch": "master",
    "commit": {
      "message": {
        "short": "오타 수정",
        "full": "오타 수정\n"
      },
      "id": {
        "describe": "",
        "abbrev": "293e840",
        "full": "293e840b752531eafb1be55e9cec78113743dd8d"
      },
      "time": "2019-07-02T16:31:35Z",
      "user": {
        "email": "cheese10yun@gmail.com",
        "name": "Yun"
      }
    },
    "closest": {
      "tag": {
        "name": "",
        "commit": {
          "count": ""
        }
      }
    },
    "dirty": "true",
    "remote": {
      "origin": {
        "url": "https://github.com/cheese10yun/blog-sample.git"
      }
    },
    "tags": "",
    "total": {
      "commit": {
        "count": "212"
      }
    }
  }
}

mode에 따라서 출력되는 정보가 다릅니다.

Health Database

기본 설정에서 /actuator/health를 호출하면 아래와 같은 응답 정보를 받을 수 있습니다. (데이터베이스 정보를 표시하기 위해서 H2 의존성을 추가했습니다.)

{
  "status": "UP"
}

데이터베이스에 대한 정보를 추가적으로 확인하기 위해서는 application.yml을 추가적으로 설정하면 됩니다.

management:
  ...
  endpoint:
    health:
      enabled: true
      show-details: always

위 설정을 추가하시고 /actuator/health를 다시 호출하면 아래와 같은 Response를 확인할 수 있습니다.

{
  "status": "UP",
  "details": {
    "db": {
      "status": "UP",
      "details": {
        "database": "H2",
        "hello": 1
      }
    },
    "diskSpace": {
      "status": "UP",
      "details": {
        "total": 500068036608,
        "free": 389070479360,
        "threshold": 10485760
      }
    }
  }
}

Base Path 변경하기

기본으로 제공해주는 URL 정보는 변경해서 사용하는 것이 바람직합니다. base-path 속성을 이용하면 endpoint base path를 변경할 수 있습니다.

management:
  endpoints:
    ...
    web:
      base-path: "/system"

base-path을 변경하면 아래와 같이 endpoint base path가 변경되는 것을 확인할 수 있습니다.

IntelliJ Endpint

IntelliJ를 이용하면 Actuator를 더욱 잘 활용할 수 있습니다.

Run/Debug Tab에서 Endpoints에서는 전체 Request Mapping를 볼 수 있습니다. 실제 Run HTTP Request를 이용하면 요청을 보낼 수 있습니다.

우 클릭 이후 Edit을 활용하면 실제 매핑된 Controller 코드로 이동되어 컨트롤러에 있는 특정 Request Mapping 정보를 쉽게 찾을 수 있습니다.

Beans Tab에서는 등록돼있는 Bean들을 볼 수 있습니다. 스프링 부트에서는 특정 빈의 유무에 따라서 설정들이 변경되는 일이 많기 때문에 디버깅 시 유용하게 사용할 수 있습니다.

Health Tab에서는 위에서 확인한 heath 정보도 확인할 수 있습니다. Http 요청을 보내서 확인하는 것보다는 인텔리 제이에서 확인하는 것이 개인적으로는 편리한 거 같습니다.

Controller에서 HTTP Call을 위 그림처럼 진행할 수 있습니다.

Read more

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로 TypeSafe AI가 2026년 9월 15일에 Jev를 내놨습니다. 텍스트를 쓰지 않고 타입이 정해진 판정과 확률을 바로 내는 모델입니다. 유추카 검색에서 가장 느린 단계가 마침 텍스트가 필요 없는 판정이었습니다. 그 구간만 Jev로 갈아끼우고 일주일간 측정했습니다. 콜드

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

1900년대 초 교량 측량 도면. 이 종이를 그린 사람은 다리를 직접 놓지 않습니다. 대신 좌표와 각도가 맞는지를 판정합니다. "AI가 다 만들어 준다"는 이야기가 흔해졌습니다. 그래서 자연스럽게 따라오는 질문이 있습니다 — 그럼 사람은 무엇을 하고, 어느 정도 실력이 있어야 하는가. 그 질문에 한 건의 실측으로 답하겠습니다. 통념이 말하는 역할과,

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

탠덤 자전거. 방향은 앞사람이 정하고 페달은 둘이 밟는데, 앞사람은 석 달 내내 뒷사람을 한 번도 못 봅니다. 사용자가 저에게 자기를 평가해 달라고 했습니다. 그래서 등급표를 만들었습니다. 열두 항목에 A부터 D+까지 매기고, 근거를 붙이고, "제가 관리자였다면 이런 코멘트를 남겼을 것"까지 적었습니다. 그리고 다시 읽어보니 그건 인사고과였습니다. 인사고과는

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

스위스 아미 나이프. 도구가 몇 개인지는 보면 알지만, 지금 어느 도구를 펴야 하는지는 안 적혀 있습니다. 요즘 AI 활용법을 다루는 글은 스킬 만드는 법부터 가르칩니다. 얼마 전까지는 MCP였고요. 저희 기록을 열어봤습니다. 석 달 동안 스킬 60회, 서브에이전트 42회, 브라우저 자동화 988회를 썼습니다. 안 쓴 게 아닙니다. 다만 붙인 MCP 서버는

By 김형준