sudo systemctl status grafana-server - 그라파나 서버 상태 확인
sudo systemctl start grafana-server - 그라파나 시작
sudo systemctl stop grafana-server - 그라파나 종료
netstat -tulnp | grep 3000 - 현재 실행중인 3000포트 확인
sudo systemctl restart grafana-server - 그라파나 재시작
Gradle
implementation 'io.micrometer:micrometer-registry-prometheus'
프로메테우스 다운
- ec2 서버의 보안 설정에서 9090 포트를 열어주고 prometheus 다운 및 압축 해제
- https://prometheus.io/download 링크에 들어가면 아래와 같은 화면이 나온다.
여러 버전중 다운하려는 버전 우클릭, 링크주소 복사
wget 명령어로 다운로드
-> wget {주소 복사}
wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
다운받은 파일 압축 해제
tar xzvf prometheus-2.37.0.linux-amd64.tar.gz
압축 해제한 파일로 이동
cd prometheus-2.37.0.linux-amd64
yaml파일 설정
- vi prometheus.yml 로 yml파일을 열면 아래와 같은 기본 구성이 나온다.
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
스프링부트와 연동하기 위해 targets의 localhost를 springboot 프로젝트를 배포한 ec2 서버 주소 및 포트로 바꿔주면 된다
프로메테우스 실행
./prometheus
http://{ec2서버 ip주소}:9090/ 를 입력해 웹에서 접속 가능하다
그라파나 다운
- ec2 보안에서 3000포트에대한 보안을 열어주고 ec2서버 접속
ec2서버 접속 이후 아래의 코드를 차례로 입력해 그라파나 다운
sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/enterprise/release/grafana-enterprise_10.0.2_amd64.deb
sudo dpkg -i grafana-enterprise_10.0.2_amd64.deb
- grafana가 ubuntu에 설치된 경로는 아래와 같다.
/usr/lib/systemd/system/grafana-server.service
- 그라파나 시작
sudo systemctl start grafana-server
- url에 http://{ec2 ip주소}:3000 입력 및 아래 화면의 로그인 실행
- id: admin
- pw: admin
id와 pw는 로그인 이후 수정하자
- 아래의 화면 순서대로 실행
- 그라파나에 프로메테우스 추가
- url에 http://{배포된 ec2 주소}:9090 입력
- 대시보드 생성
다시 왼쪽 상단 home 버튼 옆 클릭하고 dashboards 클릭.
아래 이미지 따라하기
그리고 연결한 프로메테우스 클릭.
화면이 나오면 cpu 테스트를 위해 쿼리 입력칸에 cpu를 입력하고 나오는 열기 창에서 system cpu 혹은 process cpu 선택 및 run queries 실행
대시보드는 조금 찾아보면 미리 잘 만들어둔 것을 다운받아 사용할 수 있기에 필요한대로 다운받아 사용하기
'Spring' 카테고리의 다른 글
[SpringBoot] flyway와 DB migration 해야하는 이유 (0) | 2023.09.23 |
---|---|
Http, Https 프로토콜 (0) | 2023.07.11 |
Spring - MVC 패턴 (0) | 2023.03.08 |
Spring - 입문 (0) | 2023.02.24 |