Print
카테고리: [ Miscellaneous ]
조회수: 39693

1. 개요

일단 프로메테우스를 설치해보는 것에 의의를 두는 문서이다.


2. 프로메테우스란?

2.1. 소개

Prometheus는 오픈 소스 모니터링 솔루션으로 크게 다음과 같이 구성되어 있다.

일반적인 모니터링 툴과의 차이점이 있는데 대부분의 모니터링 방식이 개별 서버에서 중앙 서버로 push하는 방식인데 반해, Prometheus는 중앙 서버에서 메트릭을 polling하는 방식이다. 이 방식의 장점은 모든 메트릭을 중앙 서버로 보내지 않아도 된다는 것이다. 특히 부하가 많은 상황에서 메트릭 전송이 더해진다면 문제가 더 커질 수 있다. Prometheus는 중앙에서 일정 주기(디폴트는 15초)로 메트릭을 수집하기 때문에 좀 더 낫다고 할 수 있다.

하지만 단점도 있다. Scale-out이 안된다는 점인데 근본적인 고가용성을 제공한다기 보다는 여러 Prometheus를 연결해서 Hierachy 구조로 사용할 수 있다는 정도이다.

2.2. 구성요소

다음은 Prometheus 내부 구성 요소이다.

Retrival

HTTP로 접근하여 메트릭을 가져오거나 Pushgateway를 통하여 접근할 수 없는 곳에 있는 데이터를 가져오는 역할을 한다. Pushgateway는 접근할 수 없는 곳에 데이터가 존재하는 경우에 Port forward를 통해 사용할 수 있다. 예를 들면 사내망에 데이터가 있어서 외부에서 scrape가 안되는 경우 등이다.

TSDB (Time-series Database)

Prometheus에는 수집한 데이터를 저장하고 시간에 흐름에 따라 조회를 할 수 있도록 시계열(Time-series) 데이터를 저장할 수 있는 저장소가 내장되어 있다. 데이터를 저장하는 방법은 Local Storage와 Remote Storage를 이용하는 방법이 있다. 대부분은 Local Storage를 사용하겠지만 원격지에 있는 서버에 데이터를 저장하는 방법도 사용할 수 있다.

HTTP Server

Prometheus는 내부에 저장된 데이터 조회 기능을 제공하기 위한 HTTP Server를 내장하고 있다.

Web UI

자체 Dashboard를 제공한다. 물론 별도의 시각화 도구를 붙여 보는 것이 더 좋다.

Alert manager

문제가 발생하면 이를 알람으로 보내는 기능을 제공한다.


3. 다운로드

페이지 : https://prometheus.io/download

적당히 필요한 버전을 다운한다.

예: https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.linux-amd64.tar.gz


4. 설치

설치랄 것도 없다. tar 파일을 풀면 디렉토리가 나오고 디렉토리에 들어가면 파일들이 있다.

가장 빨리 실행하는 방법은 기본 내장된 prometheus.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=` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

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

눈썰미가 있다면 9090포트로 접근해야 한다는 것쯤은 알 수 있겠다.

이제 다음과 같이 실행한다.

$ ./prometheus --config.file=prometheus.yml
level=info ts=2019-11-11T10:32:33.439Z caller=main.go:296 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2019-11-11T10:32:33.439Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.1, branch=HEAD, revision=6f92ce56053866194ae5937012c1bec40f1dd1d9)"
level=info ts=2019-11-11T10:32:33.439Z caller=main.go:333 build_context="(go=go1.13.1, user=root@88e419aa1676, date=20191017-13:15:01)"
level=info ts=2019-11-11T10:32:33.439Z caller=main.go:334 host_details="(Linux 4.15.0-1044-aws #46-Ubuntu SMP Thu Jul 4 13:38:28 UTC 2019 x86_64 ip-172-31-6-133 (none))"
level=info ts=2019-11-11T10:32:33.439Z caller=main.go:335 fd_limits="(soft=1024, hard=1048576)"
level=info ts=2019-11-11T10:32:33.440Z caller=main.go:336 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-11-11T10:32:33.442Z caller=main.go:657 msg="Starting TSDB ..."
level=info ts=2019-11-11T10:32:33.443Z caller=web.go:450 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-11-11T10:32:33.445Z caller=head.go:514 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2019-11-11T10:32:33.449Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=1
level=info ts=2019-11-11T10:32:33.450Z caller=head.go:562 component=tsdb msg="WAL segment loaded" segment=1 maxSegment=1
level=info ts=2019-11-11T10:32:33.453Z caller=main.go:672 fs_type=EXT4_SUPER_MAGIC
level=info ts=2019-11-11T10:32:33.453Z caller=main.go:673 msg="TSDB started"
level=info ts=2019-11-11T10:32:33.453Z caller=main.go:743 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-11-11T10:32:33.463Z caller=main.go:771 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2019-11-11T10:32:33.463Z caller=main.go:626 msg="Server is ready to receive web requests."

이제 이 호스트의 9090포트로 붙으면 된다. 하지만 뭐가 없다.