# 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: ["localhost:9093"]
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files: ["alert.rules.yml"]
# - "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: "node"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["ip:9100"]
level=warn component=cluster err="couldn't deduce an advertise address: no private IP found, explicit advertise addr not provided"
ts=2024-06-05T03:36:10.082Z caller=main.go:278 level=error msg="unable to initialize gossip mesh" err="create memberlist: Failed to get final advertise address: No private IP address found, and explicit IP not provided"
해당 오류는 클러스터 모드에서 사용할 광고 주소(advertise address)를 설정하지 않았기 때문
#!/bin/bash
# 체크할 프로세스의 경로를 변수에 저장합니다.
PROCESS_PATH="./venv/bin/python tool/checkup_crawler.py --prod -d"
# 프로세스가 실행 중인지 확인합니다.
if pgrep -f "$PROCESS_PATH" > /dev/null
then
PROCESS_STATUS=1 # 프로세스가 실행 중이면 1
else
PROCESS_STATUS=0 # 프로세스가 실행 중이지 않으면 0
fi
# Prometheus 메트릭 포맷으로 출력합니다.
echo "# HELP process_up Is the process running (1 for yes, 0 for no)"
echo "# TYPE process_up gauge"
echo "process_up $PROCESS_STATUS"
metric_server.sh — 반복적으로 메트릭 체크
#!/bin/bash
while true; do
/usr/local/bin/crawler_check.sh > /var/www/html/metrics
sleep 60
done
sh 파일을 생성 후, 서비스 등록을 해줘야 터미널 종료 후에도 prometheus scrap 가능
# cd /usr/local/bin 에
### crawler_check.sh
#!/bin/bash
# 체크할 프로세스의 경로를 변수에 저장합니다.
PROCESS_PATH="./venv/bin/python tool/checkup_crawler.py --prod -d"
# 프로세스가 실행 중인지 확인합니다.
if pgrep -f "$PROCESS_PATH" > /dev/null
then
PROCESS_STATUS=1 # 프로세스가 실행 중이면 1
else
PROCESS_STATUS=0 # 프로세스가 실행 중이지 않으면 0
fi
# Prometheus 메트릭 포맷으로 출력합니다.
echo "# HELP process_up Is the process running (1 for yes, 0 for no)"
echo "# TYPE process_up gauge"
echo "process_up $PROCESS_STATUS"
# 이렇게 작성 함.
위의 파일이 정기적으로 돌면서 http에 update하는 sh파일
#!/bin/bash
while true; do
/usr/local/bin/crawler_check.sh > /var/www/html/metrics
sleep 60
done
혹시 모르니, /var/www/html => 디렉토리 생성.
작성했던 sh 파일을 기반으로 systemd에 등록해주자.
### python-http 서버 데몬으로 실행.
### crawler_http.service
[Unit]
Description=crawler_check
After=network.target
[Service]
WorkingDirectory=/var/www/html
ExecStart=/bin/python3 -m http.server 8080
User=root
Restart=always
[Install]
WantedBy=multi-user.target
만들었던 sh 파일 실행.
### metric_server.service
[Unit]
Description=Metric Server Script
After=network.target
[Service]
ExecStart=/usr/local/bin/metric_server.sh
User=root
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target