도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 2

2024. 10. 14. 22:52·DevOps
728x90
반응형

 

 

지난 글에서 도커 파일로 프로메테우스와 그라파나를 띄워보았다.

 

👇🏻

 

2024.10.13 - [DevOps] - 도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 1

 

도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 1

이번 프로젝트에서 프로메테우스와 그라파나를 사용해 모니터링을 하게 되어서 정리용으로 포스팅..  Prometheus🔥 "프로메테우스"는 그리스 로마 신화에 나오는 그 이름이 맞다. 미래를 예측하

tildacoderecorder.tistory.com

 

 

이번 포스팅에서는 그라파나가 제공하는 프로비저닝 Provisioning 기능을 사용하고 이 기능 또한 도커로 띄워볼 예정이다.

 


 

그라파나의 프로비저닝 Provisioning 기능이란

 

그라파나에서 수동으로 설정해줘야 하는 대시보드, 데이터 소스, 알림 채널 등을 코드로 정의하여 자동으로 적용될 수 있도록 도와주는 기능이다.

프로비저닝의 주목적이 자동화와 일관성인 만큼 한번 설정 파일로 지정해두면 어떤 환경에서 배포되어도 그 설정이 유지된다.

 

주로 yml 파일 형식으로 구성되며 /etc/grafana/provioning/ 디렉토리 내에 위치하게 된다.

 

settings
├── prometheus
│   ├── config
│   │   └── prometheus.yml
│   │   
├── grafana
│   ├── provisioning
│   │   ├── alerting
│   │   ├── dashboards
│   │   └── datasources

 

그렇기에 지난 포스팅에서 위와 같이 그라파나의 프로비저닝 폴더까지 미리 만들어두었다.

그라파나 UI를 활용하면 위 프로비저닝 파일들을 쉽게 만들 수 있다.

 

 


 

 

datasources/

apiVersion: 1

datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    # Access mode - proxy (server in the UI) or direct (browser in the UI).
    url: http://localhost:9090
    jsonData:
      httpMethod: POST
      manageAlerts: true
      prometheusType: Prometheus
      prometheusVersion: 2.44.0
      cacheLevel: 'High'
      disableRecordingRules: false
      incrementalQueryOverlapWindow: 10m
      exemplarTraceIdDestinations:
        # Field with internal link pointing to data source in Grafana.
        # datasourceUid value can be anything, but it should be unique across all defined data source uids.
        - datasourceUid: my_jaeger_uid
          name: traceID

        # Field with external link.
        - name: traceID
          url: 'http://localhost:3000/explore?orgId=1&left=%5B%22now-1h%22,%22now%22,%22Jaeger%22,%7B%22query%22:%22$${__value.raw}%22%7D%5D'

 

데이터 소스로 프로메테우스를 사용하기 때문에 위와 같은 yml 파일을 작성한 뒤 datasources/ 안에 넣어주면 그라파나가 실행될 때 자동으로 탐색하여 적용하게 된다.

 

위 파일 속 내용은 데이터 소스의 종류에 따라 다른데 그라파나 홈페이지에서 친절히 예시 코드를 알려준다.

 

 

https://grafana.com/docs/grafana/latest/datasources/prometheus/

 

Prometheus data source | Grafana documentation

Intro to metrics with Grafana: Prometheus, Grafana Mimir, and beyond In this webinar, we’ll go over challenges when scaling metrics systems, with a particular focus on Prometheus and Grafana Mimir.

grafana.com

 

 

 

dashboards/

 

대시 보드 폴더 안에는 대시 보드 기본 설정 yml 파일 하나와 그 대시보드의 템플릿을 설명하는 json 파일이 들어가야 한다.

 

apiVersion: 1

providers:
  - name: Default # A uniquely identifiable name for the provider
    folder: Services # The folder where to place the dashboards
    type: file
    options:
      path:
        <path to dashboard definitions>
        # Default path for Windows: C:/Program Files/GrafanaLabs/grafana/public/dashboards
        # Default path for Linux is: /var/lib/grafana/dashboards

 

기본 설정 파일은 어떤 형식의 대시 보드를 사용할지 알려주는 파일이다.

그라파나 UI에서 대시보드를 생성 후 json 파일로 export 해오면 그 json 파일의 이름을 providers/name에 적고 json 파일의 위치를 Path에 적어주면 된다.

 

 

 

대시보드 위의 Share/Export/View Json 을 누르면 위와 같이 해당 템플릿에 대한 정보를 json 형태로 추출 할 수 있게 된다.

 

 

dashboards
├── gf_dashboard.yml
└── server-check.json
# gf_dashboard.yml

apiVersion: 1

providers:
  - name: server-check
    folder: pickple
    type: file
    options:
      path: /etc/grafana/provisioning/dashboards

 

나의 경우 대시보드 파일을 server-check.json으로 저장하고 dashboards 폴더 안에 두었기 때문에 기본 설정 파일을 위와 같이 적어주었다.

 

 

Alerting

 

 

Alerting
├── gf_alertrule.yml
├── gf_contactpoint.yml
└── gf_notification_policy.yml

 

알림 채널에 대해 정의하는 Alerting 폴더에는 contact point, alert rule, notification policy를 구분해서 넣었다.

 

 

 

그라파나 UI에서 생성한 contact point의 오른쪽에 위치한 More/Export를 누르면 위와 같이 yml 파일로 추출 할 수 있다.

 

전 포스팅에서 슬랙 웹훅 url을 그라파나의 환경변수로 넘겨줬으므로 저 부분만 수정해주면 된다.

url: ${GF_NOTIFIERS_CONTACTPOINT_URL}

 

alert rule과 notification policy 또한 생성 후 Export 하면 그라파나가 친절히 yml 파일로 추출해주기 때문에 그대로 Alerting 폴더에 넣어준다.

 

 

이 모든 설정을 끝마치고 도커 실행 후 그라파나 UI에 접속해보면

 

 

 

 

Provisioned 라는 태그와 함께 파일로 지정한 설정들이 자동으로 띄워져 있는걸 확인 할 수 있다.

 

 

 

당연하지만 Provisioned 된 설정들은 그라파나 UI에서 편집 할 수 없다.

 

 

 


 

 

그라파나 슬랙 메시지 템플릿 변경하기

 

 

따로 설정을 해주지 않으면 위와 같은 형식으로 슬랙 메세지를 받게 되는데 좀 더 간결하고 명확하게 바꾸고 싶다.

 

 

https://grafana.com/docs/grafana/latest/alerting/fundamentals/templates/

 

Templates | Grafana documentation

Getting started with managing your metrics, logs, and traces using Grafana In this webinar, we’ll demo how to get started using the LGTM Stack: Loki for logs, Grafana for visualization, Tempo for traces, and Mimir for metrics.

grafana.com

 

그라파나 공식 홈페이지를 참조하면 템플릿 파일 작성 시 GoLang이 필요한데 나는 모르므로...스택 오버 플로우를 뒤진 결과 나름 깔끔한 템플릿을 발견했다.

 

contactPoints:
  - orgId: 1
    name: server-channel
    receivers:
      - uid: # uid
        type: slack
        settings:
          icon_emoji: ':warning:'
          url: # slack webhook url
          username: Server Up/Down Warn
          text: |
            *Alert:* {{ .CommonAnnotations.summary }}
            *Description:* {{ .CommonAnnotations.description }}
            *Severity:* {{ .Labels.severity }}
        disableResolveMessage: true

 

 

위와 같이 해두면 alert rule에 설정해둔 summary, description, severity만 보여진다.

 

 

 

훨씬 깔끔해졌다.

 

 

 

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'DevOps' 카테고리의 다른 글

도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 1  (0) 2024.10.13
Docker로 Cassandra 띄우기 및 실습하기  (1) 2024.10.04
[✉️ Kafka] Kafka 설치 및 예제로 실습해보기  (2) 2024.09.27
[✉️ Kafka] Kafka 이해하기2 - Zookeper, Broker, Message  (2) 2024.09.27
[✉️ Kafka] Kafka 이해하기1 - Producer, Consumer, Topic, Partition  (0) 2024.09.27
'DevOps' 카테고리의 다른 글
  • 도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 1
  • Docker로 Cassandra 띄우기 및 실습하기
  • [✉️ Kafka] Kafka 설치 및 예제로 실습해보기
  • [✉️ Kafka] Kafka 이해하기2 - Zookeper, Broker, Message
waVwe
waVwe
    반응형
  • waVwe
    waVwe 개발 블로그
    waVwe
  • 전체
    오늘
    어제
    • ALL (184)
      • Python (1)
      • Spring (15)
      • DevOps (10)
      • Git (6)
      • JAVA (4)
      • C (22)
      • 코테 문제 풀이 (124)
        • 프로그래머스 (43)
        • 백준 (2)
        • 정올 (64)
        • SW Expert Academy (1)
        • 온코더 oncoder (14)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

    • 🐙 Github
  • 공지사항

  • 인기 글

  • 태그

    형변환
    docker
    도커
    자료구조
    코테
    while문
    아파치카프카
    온코더
    devops
    스프링부트
    스파르타코딩클럽
    progate
    C언어
    정올
    이진트리
    내일배움캠프
    자바
    프로그래머스
    스프링
    MSA
    연결리스트
    java
    스파르타코딩
    Til
    알고리즘
    깃헙
    C
    springboot
    깃
    CI/CD
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
waVwe
도커로 프로메테우스 & 그라파나 띄우기 + 프로비저닝 기능까지 2
상단으로

티스토리툴바