관리 메뉴

IT.FARMER

Grafana 설치 prometheus 본문

모티터링도구

Grafana 설치 prometheus

아이티.파머 2020. 8. 31. 16:06
반응형

2020/08/31 - [모티터링도구] - 그라파나 키바나 차이점 (모니터링 서비스)

2020/08/31 - [모티터링도구] - Grafana 설치 pormetheus

2020/08/31 - [모티터링도구] - Grafana loki, promtail

2020/08/31 - [모티터링도구] - exporter 설치 및 Grafana 연동

2020/08/31 - [모티터링도구] - grafana Mysql Datasource 연동

 

그라파나란 ?

 

오픈소스 시각화 웹 어플리 케이션.

Grafana를 사용하면 저장된 위치에 상관없이 메트릭 을 쿼리, 시각화, 경고 및 이해할 수 있습니다. 팀과 대시 보드를 생성, 탐색 및 공유하고 데이터 중심의 시각화를 제공합니다.

Grafana 프로젝트는 2014 년 Torkel Ödegaard에 의해 시작되었으며 지난 2 년 동안 GitHub에서 가장 인기있는 오픈 소스 프로젝트 중 하나가되었습니다. 저장된 위치에 상관없이 메트릭 및 로그를 쿼리, 시각화 및 경고 할 수 있습니다.

Grafana는 플러그 가능한 데이터 소스 모델을 가지고 있으며 Graphite, Prometheus, Elasticsearch, OpenTSDB 및 InfluxDB와 같은 가장 널리 사용되는 시계열 데이터베이스를 풍부하게 지원합니다. 또한 Google Stackdriver, Amazon Cloudwatch, Microsoft Azure 및 MySQL 및 Postgres와 같은 SQL 데이터베이스와 같은 클라우드 모니터링 공급 업체를 기본적으로 지원합니다. Grafana는 많은 장소의 데이터를 단일 대시 보드로 결합 할 수있는 유일한 도구입니다.

 

 

Standalone Linux Binaries(64 Bit)

wget <https://dl.grafana.com/oss/release/grafana-7.1.3.linux-amd64.tar.gz> tar -zxvf grafana-7.1.3.linux-amd64.tar.gz cd grafana-7.1.3 ./bin/grafana-server

Red Hat, CentOS, RHEL 및 Fedora ( 64 비트 )

wget <https://dl.grafana.com/oss/release/grafana-7.1.3-1.x86_64.rpm> sudo yum install grafana-7.1.3-1.x86_64.rpm service grafana-server start

 

그라파나 백엔드 구성파일은 일반적으로 /etc/grafana/grafana.ini 위치에 정의되어 있다.

이 구성파일에서 기본관리자 암호 http 포트 그라파나 데이터 베이스 (sqllite3, mysql, postgress )

인증옵션 (google, github, ldap, auth proxy) 을 변경할수 있다.

기본 암호는 admin/admin 이다. http://192.168.0.10:3000

 

설치는 간편하고 쉽다. 

프로메테우스를 설치한후 그라파나와 연동하여 메트릭스 지표를 확인 할 수있다.

 

프로메타우스란 ?

오픈소스 모니터링 플랫폼 - 각 모니터링 대상의 expoter또는 prometheus client를 통해서 지표를 긁어 가는 방식으로 데이터를 수집한다.

 

 

다운로드 (https://prometheus.io/download/) 페이지에서 필요한 에이전트 다운로드.

 

tar xvfz prometheus-*.tar.gz cd prometheus-*

 

프로메테우스는 HTTP 엔드 포인트를 스크랩 하여 모니터링 대상에서 메트릭을 수집한다. 프로메테우스는 자신에 대해 동일한 방식으로 데이터를 노출하고, 자체 상태를 긁고(Scrap) 모니터링 할수 있다. prometheus.yml 기본 프로메테우스 구성파일에 대한 설정은 자신에 대한 데이터만 수집하도록 되어 있다.

 

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# 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'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

 

scrape_configs 에서 잡을 추가한다. JOB을 추가한 뒤에는 항상 재시작이 필요함.

필요한 프로메테우스 에이전트를 다운받아 설치한후 긁어올 정보를 해당 prometheus.yml 에 등록한다.

prometheus 시작

새로 생성된 구성파일로 프로메테우스를 시작 하려면 바이너리가 포함된 디렉터리로 변경하고 다음을 실행한다.

 

# Start Prometheus.
# By default, Prometheus stores its database in ./data (flag --storage.tsdb.path).
./prometheus --config.file=prometheus.yml

prometheus service 등록

 

# sudo vim /etc/systemd/system/prometheus.service
# sudo vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network-online.target

[Service]
Type=simple
User=mezzo
Group=mezzo
SyslogIdentifier=prometheus
WorkingDirectory=/home/mezzo/utils/prometheus-2.20.1.linux-amd64
Restart=always
RestartSec=0s
ExecStart=/home/mezzo/utils/prometheus-2.20.1.linux-amd64/prometheus --config.file=prometheus.yml


[Install]
WantedBy=multi-user.target

 

데몬 리로드

sudo systemctl daemon-reload

 

프로메테우스 서비스 시작,중지

sudo systemctl start prometheus

 

  1. 각서버에 프로메테우스 클라이언트 에이전트 설치
  2. 프로메테우스 서버설치
    • 긁어올 클라이언트 HTTP end point 설정
  3. 그라파나와 연동 하여 데이터 시각화

→ SpringBoot 에서도 prometheus http end point 를 제공하여 이를 사용 할수있다.

 

 

Grapana & Prometheus 연동

그라파나 시각화 웹어플리케이션에 오픈 모니터링 도구인 프로메테우스를 연동하여 보기 쉽게 구성한다. AleltManager를 이용하여 알림으로도 사용

 

프로메테우스의 시각화를 위해 그라파나에서 DataSource를 추가하여 연동한다.

1. Expore → Add data dource

 

 

2. DataSource 에 Prometheus 추가

프로메테우스의 URL 정보 입력후 SAVE 한다.

 

그라파나와 프로메테우스를 연동하는것은 이렇게 쉽다.

원하는 데쉬보드를 DSL을 이용하여 만드는게 까다롭다. 잘만들어 놓은 데시 보드를 임포트 하여 사용하는게 정신건강에 이로울듯 하다.

 

3. 데시보드 추가

데시보드는 프로메테우스에서 제공하는 디폴트 데시보드를 사용한다.

좀더 익숙해 지면 직접 쿼리를 이용하여 사용

 

 

반응형