Linux Health Sentinel Phase 2: 측정값에서 의미로 Grafana Loki와 함께

발행: (2026년 2월 6일 오전 02:17 GMT+9)
3 min read
원문: Dev.to

Source: Dev.to

개념: 메트릭 vs. 로그

메트릭은 문제가 있다는 것을 알려주고, 로그는 문제가 무엇인지 알려줍니다.

아키텍처

  • Loki (The Library) – 노트북에서 실행되며 로그를 저장하고 검색 기능을 제공합니다.
  • Promtail (The Spy) – Vagrant VM에서 실행되며 로그 파일을 tail하고 Loki로 전송합니다.

사전 요구 사항

  • Grafana + Prometheus가 실행 중인 Ubuntu 노트북.
  • Phase 1에서 만든 Vagrant VM(또는 로컬 VM).
  • 호스트와 VM 간 기본 네트워킹.

단계 1: 라이브러리(Loki) 설정

# Download and unzip Loki
wget https://github.com/grafana/loki/releases/latest/download/loki-linux-amd64.zip
sudo apt update && sudo apt install unzip -y
unzip loki-linux-amd64.zip
chmod +x loki-linux-amd64

# Download the default config file
wget https://raw.githubusercontent.com/grafana/loki/main/cmd/loki/loki-local-config.yaml

Loki 실행:

./loki-linux-amd64 -config.file=loki-local-config.yaml

주의: 이 설정은 로컬 학습용이며 인증 없이 실행됩니다. Loki를 인터넷에 직접 노출하지 마세요.

단계 2: 스파이(Promtail) 배포

Promtail 설치

curl -O -L "https://github.com/grafana/loki/releases/download/v3.5.9/promtail-linux-amd64.zip"
unzip promtail-linux-amd64.zip
chmod a+x promtail-linux-amd64

Promtail 구성

# Download the basic config file
wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml

promtail-local-config.yaml을 편집하고 클라이언트 URL을 노트북의 IP 주소로 바꿉니다(hostname -I로 확인):

clients:
  - url: http://:3100/loki/api/v1/push

scrape_configs:
  - job_name: system
    static_configs:
      - targets:
          - localhost
        labels:
          job: varlogs
          host: vagrant-vm
          __path__: /var/log/*log

Promtail 실행:

./promtail-linux-amd64 -config.file=promtail-local-config.yaml

단계 3: Grafana에서 시각화

  1. Grafana(http://localhost:3000)에 접속합니다.
  2. Add Data SourceLoki 선택.
    • URL을 http://localhost:3100으로 설정.
    • Save & Test 클릭.
  3. Explore 탭(나침반 아이콘)으로 이동.
  4. Label Browser에서 job="varlogs" 또는 host="vagrant-vm"을 선택.
  5. Run Query 클릭.

실시간 로그 스트리밍 활성화

  • Grafana UI 오른쪽 상단의 Live 버튼을 클릭.
  • Auto‑Refresh를 5 초 또는 10 초로 설정해 거의 실시간 업데이트를 확인합니다.

테스트 로그 생성

sudo logger "Sentinel Test: Can you hear me, Grafana?"
sudo logger "Hello Loki, this is a test"
sudo logger "Sentinel Alert: Testing log flow to Grafana"
sudo logger -p user.err "Simulating a critical system error"
sudo logger "Hello Loki, this is test-2."

결론

다음 단계: Sentinel이 문제를 감지했을 때 Slack, Discord, 이메일 등으로 알림을 보내도록 Alerting을 설정합니다.

Back to Blog

관련 글

더 보기 »