Spring Boot 서버 메소드 별 실행시간을 모니터링하기 위해 Pinpoint APM을 운영하기로 하였다.
처음에는 EC2에 구축했으나 어디서나 셋업하기 유용하게 Docker 기반으로 만들기로 하였다.
Pinpoint 띄우기
Dockerfile
# Base image
FROM ubuntu:20.04
# 환경 변수 설정
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
ENV PATH=$JAVA_HOME/bin:$PATH
ENV HBASE_VERSION=2.5.10
ENV PINPOINT_VERSION=3.0.1
ENV HBASE_HOME=/opt/hbase
# 비대화식 설치를 위한 설정
ARG DEBIAN_FRONTEND=noninteractive
# 필요한 패키지 설치
RUN apt-get update && \
apt-get install -y wget openjdk-17-jdk tar && \
apt-get clean
# 작업 디렉토리 설정
WORKDIR /opt
# HBase 다운로드 및 설치
RUN wget https://archive.apache.org/dist/hbase/${HBASE_VERSION}/hbase-${HBASE_VERSION}-bin.tar.gz && \
tar xzf hbase-${HBASE_VERSION}-bin.tar.gz && \
ln -s hbase-${HBASE_VERSION} hbase && \
rm hbase-${HBASE_VERSION}-bin.tar.gz
# Pinpoint Collector 및 Web 다운로드
WORKDIR /opt/pinpoint
RUN wget https://repo1.maven.org/maven2/com/navercorp/pinpoint/pinpoint-collector/${PINPOINT_VERSION}/pinpoint-collector-${PINPOINT_VERSION}-exec.jar && \
wget https://repo1.maven.org/maven2/com/navercorp/pinpoint/pinpoint-web/${PINPOINT_VERSION}/pinpoint-web-${PINPOINT_VERSION}-exec.jar
# HBase 설정 파일 복사
# 로컬 디렉토리에 있는 파일을 컨테이너 내부로 복사
COPY hbase-create.hbase /opt/hbase/scripts/hbase-create.hbase
COPY hbase-env.sh /opt/hbase/conf/hbase-env.sh
COPY hbase-site.xml /opt/hbase/conf/hbase-site.xml
# 포트 공개
EXPOSE 8080 9991 9992 9993 16010
# 시작 스크립트 복사 및 실행 권한 부여
COPY start.sh /opt/start.sh
RUN chmod +x /opt/start.sh
# 컨테이너 시작 시 실행할 명령어
CMD ["/opt/start.sh"]
start.sh
#!/bin/bash
echo "Starting HBase..."
/opt/hbase/bin/start-hbase.sh
# Wait for HBase to initialize
sleep 3
# Create Pinpoint HBase tables
echo "Creating Pinpoint HBase tables..."
echo "exit" | /opt/hbase/bin/hbase shell /opt/hbase/scripts/hbase-create.hbase
# Start Pinpoint Collector
echo "Starting Pinpoint Collector..."
nohup java -jar -Dpinpoint.zookeeper.address=localhost /opt/pinpoint/pinpoint-collector-3.0.1-exec.jar > /dev/null 2>&1 &
# Start Pinpoint Web
echo "Starting Pinpoint Web..."
nohup java -jar -Dpinpoint.zookeeper.address=localhost /opt/pinpoint/pinpoint-web-3.0.1-exec.jar > /dev/null 2>&1 &
# Keep the container running
tail -f /dev/null
hbase-create.hbase 파일은 TTL을 조금 조정하였다. 기본 설정을 쓸꺼면 pinpoint github에 있는 파일을 wget으로 가져와 사용하면 된다.
조금 운영해보다가 갑자기 hbase가 종료되는 문제가 발생하여 설정을 조금 바꾸었다.
hbase-env.sh
# The maximum amount of heap to use. Default is left to JVM default.
export HBASE_HEAPSIZE=2G
hbase-env.sh는 힙사이즈만 조정하였다. 수정하지 않을 사람은 Dockerfile에서 COPY 문을 지우면 되겠다.
hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<!--
The following properties are set for running HBase as a single process on a
developer workstation. With this configuration, HBase is running in
"stand-alone" mode and without a distributed file system. In this mode, and
without further configuration, HBase and ZooKeeper data are stored on the
local filesystem, in a path under the value configured for `hbase.tmp.dir`.
This value is overridden from its default value of `/tmp` because many
systems clean `/tmp` on a regular basis. Instead, it points to a path within
this HBase installation directory.
Running against the `LocalFileSystem`, as opposed to a distributed
filesystem, runs the risk of data integrity issues and data loss. Normally
HBase will refuse to run in such an environment. Setting
`hbase.unsafe.stream.capability.enforce` to `false` overrides this behavior,
permitting operation. This configuration is for the developer workstation
only and __should not be used in production!__
See also https://hbase.apache.org/book.html#standalone_dist
-->
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>./tmp</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>120000</value>
</property>
</configuration>
hbase-site.xml 에서는 zookeeper.session.timeout 항목만 추가하였다. 마찬가지로 수정하지않을 사람은 Dockerfile에서 COPY 문을 지우면 되겠다.
컨테이너 생성 및 빌드

다섯 가지 파일들을 모두 같은 경로에 둔다.
밑에 있는 명령어를 실행한다.
docker build -t pinpoint .
docker run -d --name pinpoint -p 8080:8080 -p 9991:9991 -p 9992:9992 -p 9993:9993 pinpoint
8080포트로 들어가보면 Pinpoint가 띄워진 것을 볼 수 있다.

Spring Boot Application에 Pinpoint Agent 붙이기
https://repo1.maven.org/maven2/com/navercorp/pinpoint/pinpoint-agent/3.0.1/
Central Repository: com/navercorp/pinpoint/pinpoint-agent/3.0.1
repo1.maven.org
위에 있는 주소에서 pinpoint-agent-3.0.1.tar.gz 파일을 받고 압축을 푼다.
다음 명령어로 javaagent로 pinpoint를 붙여준다. app.jar는 본인의 애플리케이션을 붙여주면 된다.
java \
-javaagent:/pinpoint-agent/pinpoint-bootstrap-3.0.1.jar \
-Dprofiler.transport.grpc.collector.ip={Pinpoint IP 주소} \
-Dprofiler.sampling.counting.sampling-rate=1 \
-Dpinpoint.agentId={고유 인스턴스 ID} \
-Dprofiler.tomcat.excludeurl=/health-check,/favicon.ico,/actuator/** \
-Dpinpoint.applicationName={고유 Application Name} \
-Dspring.profiles.active=local \
-jar ./app.jar
profiler.sampling.counting.sampling-rate: 샘플링 비율, 1 = 100%, 2 = 50%, 3 = 33%, 4 = 25% ...
profiler.transport.grpc.collector.ip: Pinpoint collector ip주소
pinpoint.agentId: 인스턴스 구분자, 같은 Application이어도 달라야함.
pinpoint.applicationName: Application의 Name
profiler.tomcat.excludeurl: 추적 제외 URL
ECS에 올리기
TODO()..
완성


메소드 별로 실행 시간과 JPQL들을 직접 확인할 수 있는게 정말 좋은 것 같다.