Prometheus

[Prometheus] mysqld_exporter 연동 (Linux)

Dev.Congsik 2024. 8. 26. 14:55
728x90

 

 

  • prometheus에서 MariaDB galera cluster 환경을 모니터링하기 위해서는 mysqld_exporter가 필요하며, 연동 작업이 필요하다.

 

  • mysqld_exporter 다운로드
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gz

→ 다운로드 링크 : https://github.com/prometheus/mysqld_exporter

 

  • 압축해제
tar xzvf mysqld_exporter-0.15.1.linux-amd64.tar.gz

 

 

  • my.cnf 수정
vi /etc/my.cnf   //mariaDB에 접속 후 데이터 스크래핑을 위한 계정정보 입력

#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client]
user=root       //mariadb 접속 유저명
password=root   //mariadb 접속 계정 패스워드
#
# include *.cnf from the config directory
#
!includedir /etc/my.cnf.d

 

  • mysql_exporter 서비스 파일 생성
vi /etc/systemd/system/mysql_exporter.service

[Unit]
Description=Prometheus MySQL Exporter
After=network.target
User=root    //소유자
Group=root   //그룹

[Service]
Type=simple
Restart=always
ExecStart=/root/install/mysqld_exporter-0.15.1.linux-amd64/mysqld_exporter \    //mysqld_exporter 실행파일 경로
--config.my-cnf /etc/my.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104

[Install]
WantedBy=multi-user.target

 

  • 데이터 내보내기 환경변수 설정
export DATA_SOURCE_NAME='root:root@192.168.54.134:3306/' //'계정:패스워드@mariadb 주소:3306'

 

  • 설정파일 적용
systemctl daemon-reload  //systemd 서비스 파일 수정 시 적용

 

  • 서비스 실행 및 자동 등록
systemctl start mysql_exporter
systemctl status mysql_exporter
systemctl enable mysql_exporter

 

  • prometheus 서버에서 targets 확인

→ 이때 리눅스 서버와 로컬 윈도우 pc 사이의 방화벽 확인 (포트개방) 필요

→ State=up 확인, 이때 metrics도 정상적으로 수집 되는 지 확인해야 함

→ mysql 관련 metric이 2개 정도밖에 표시되지 않는 경우, 정상적으로 데이터를 가져오는 것이 아니므로 확인이 필요하다.

 

  • 데이터 scrape 테스트

→ mysql_global_status_wsrep_cluster_size : galera 클러스터 내 노드 수

-> 클러스터 노드 수 3이 정상적으로 출력됨

 

  • 나머지 서버 동일하게 구성 진행 (2대)

→ galera_host / galera_ro / galera_rw

 

  • 최종 모니터링 화면

 

  • prometheus.yml 수정
//기존 scrape_configs: 최하단부에 추가 작성

  #galera cluster 메트릭 수집설정
  - job_name: 'galera-host'
    scrape_interval: "30s"
    static_configs:
      - targets: ['192.168.59.134:9104']

  - job_name: 'galera-rw'
    scrape_interval: "30s"
    static_configs:
      - targets: ['192.168.59.135:9104']

  - job_name: 'galera-ro'
    scrape_interval: "30s"
    static_configs:
      - targets: ['192.168.59.136:9104']

 

  • 수정 내용 적용을 위해 prometheus 재기동
systemctl daemon-reload
systemctl restart prometheus.service
systemctl status prometheus.service

 

728x90

'Prometheus' 카테고리의 다른 글

[Prometheus] Redis_exporter 연동 (Linux)  (0) 2024.08.26
[Prometheus] Node-exporter 연동 (Linux)  (0) 2024.08.26
Prometheus?  (0) 2024.08.26