티끌모아 태산

Metricbeat을 이용해 시스템 메트릭 수집 (with Logstash) 본문

환경/Metricbeats

Metricbeat을 이용해 시스템 메트릭 수집 (with Logstash)

yesman9 2023. 9. 22. 17:44

Metricbeat 설치가 안되어있다면 아래 링크를 참고하길 바란다.

https://wonseok.tistory.com/36

 

Metricbeat 설치

내 경우에는 Elasticsearch와 Kibana는 다른 서버에 이미 설치되어있으므로 이것의 설치는 생략한다. tar.gz파일을 받아서 푸는 방법도 있지만 yum명령어를 사용하는게 나중에 관리하는게 편할 것 같다.

wonseok.tistory.com

 


 

보통의 예제들은 Metricbeat에서 Elasticsearch로 전송하는 것을 다루고있다.

나는 Logstash로 데이타를 전송한 후, Logstash에서 Metricbeat로 보내보도록 하겠다.

 

1. /etc/metricbeat/modules.d 경로에서 system.yml 파일을 수정해준다.

# Module: system
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/master/metricbeat-module-system.html

- module: system
  period: 60s 
  metricsets: 
    - cpu
    - load
    - memory
    - network
    - process
    #- process_summary
    - socket_summary
    #- entropy
    - core
    #- diskio
    # - socket
    #- service
    #- users
#  process.include_top_n:
#    by_cpu: 5      # include top 5 processes by CPU
#    by_memory: 5   # include top 5 processes by memory
# Configure the mount point of the host’s filesystem for use in monitoring a host from within a container# hostfs: "/hostfs"

#- module: system
#  period: 1m
#  metricsets:
#    - filesystem
#    - fsstat
#  processors:
#  - drop_event.when.regexp:
#      system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib|snap)($|/)'

#- module: system
#  period: 15m
#  metricsets:
#    - uptime

#- module: system
#  period: 5m
#  metricsets:
#    - raid
#  raid.mount_point: '/'

내게 필요한 정보 빼고는 모두 주석처리했다.
또한 period가 기본 10초로 되어있는데, 60초로 변경했다.

 

2. 혹시 /etc/metricbeat/modules.d 경로에 ".yml"로 끝나는 것이 "system.yml"말고 더 있다면 "~.yml.disable"로 바꿔주자
그렇지 않으면 내가 원하는 system메트릭 말고 다른 메트릭이 수집되어 헷갈리게된다.

 

3. 상위 경로인 /etc/metricbeat 경로에서 metricbeat.yml 파일을 수정하자

3-1. Output 옵션 수정

기본으로 설정되어있던 Output 옵션은 모두 주석처리하고 Logstash Output을 아래와 같이 설정한다.
HostIP 부분은 본인에게 맞게 수정해서 사용하면 된다.

(Outpuet을 여러 개 설정하면 안된다. Metricbeat은 하나의 Output만 설정할 수 있다)

# ------------------------------ Logstash Output -------------------------------
output.logstash:
  # The Logstash hosts
  hosts: ["hostIP:5044"]

  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

3-2. Processors 옵션 수정

기존에 있던 옵션은 주석처리했고, 내가 필요한 정보들만 볼 수 있도록 include_fileds옵션을 사용했다.
include_fileds옵션을 사용하지않으면 메트릭이 어마어마어마하게 많이 출력된다.
그럼 내가 원하는 데이터를 쉽게 찾기 힘들며, Elasticsearch의 저장소도 많이 차지하게된다.

# ================================= Processors =================================

# Configure processors to enhance or manipulate events generated by the beat.

processors:
  - include_fields:
      fields:
        [ "system.cpu.total"            # 총 CPU 사용률 (최대치: 100*코어 수)
        , "system.core.core_id"         # CPU 코어별 ID
        , "system.core.total"           # CPU 코어별 사용률
        , "system.load"                 # 총 부하량 (1미만: 낮음, 1~5: 보통, 5이상: 높음)
        , "system.memory"               # RAM 사용량 정보
        , "system.network"              # 네트워크 in/out 정보
        , "system.socket.summary.all"   # 사용중인 소캣 개수 등
        , "system.process.fd"           # 프로세스별 filediscripter 정보
        , "system.process.cmdline"      # 프로세스별 실행 명령어 정보
        , "system.process.memory"       # 프로세스별 메모리 사용률
        , "system.process.state"        # 프로세스별 상태 정보
        , "system.process.cpu" ]        # 프로세스별 CPU 사용률
#  - add_host_metadata: ~
#  - add_cloud_metadata: ~
#  - add_docker_metadata: ~
#  - add_kubernetes_metadata: ~

자신에게 필요한 정보가 무엇인지는 아래 도큐먼트를 읽고 파악해보면 될것같다.
https://www.elastic.co/guide/en/beats/metricbeat/current/exported-fields-system.html

 

System fields | Metricbeat Reference [8.10] | Elastic

System status metrics, like CPU and memory usage, that are collected from the operating system. process Process metrics. process.state The process state. For example: "running". type: keyword process.cpu.pct The percentage of CPU time spent by the process

www.elastic.co

 

3-3. Logging 옵션 수정

필수는 아니지만 메트릭빗의 로그를 볼 수 없다면 초기 설정이나, 중간에 문제가 생겼을 때 파악하기가 힘들 것이다.

# ================================== Logging ===================================

# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
logging.level: debug

# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publisher", "service".
#logging.selectors: ["*"]
logging.to_files: true
logging.files:
  path: /var/log/metricbeat
  name: metricbeat.log
  keepfiles: 7

여기까지하면 Logstash로 보낼 준비가 끝났다. 아래 명령어로 Metricbeat을 실행해보자

systemctl start metricbeat

/var/log/metricbeat 에서 매트릭빗의 실행 로그를 볼 수 있다.

 

Logstash 설정은 다음 포스팅에서 다루겠다

https://wonseok.tistory.com/38

 

[Logstash] Metricbeats의 데이터를 받아서 ElasticSearch로 전송

이 글은 아래 포스팅에서 이어지는 글이다. https://wonseok.tistory.com/37 Metricbeat을 이용해 시스템 메트릭 수집 (with Logstash) Metricbeat 설치가 안되어있다면 아래 링크를 참고하길 바란다. https://wonseok.tis

wonseok.tistory.com

 

'환경 > Metricbeats' 카테고리의 다른 글

Metricbeat 설치  (0) 2023.09.22
Metricbeat 실행 오류 발생 (GLIBC 2.12)  (0) 2023.09.22