1.4. MariaDB Metrics 수집

신복호·2025년 2월 2일
0

Monitoring

목록 보기
5/9
post-thumbnail

개요

지난 포스팅에서는 RabbitMQ Metrics를 수집하고 이를 Grafana 대시보드에서 볼수 있도록 설정하였습니다.

이번 포스팅에서는 MariaDB Metrics를 수집하고 Grafana 대시보드에 표시 되도록 설정하고자 합니다.

1. MariaDB 설정

Mariadb 계정 생성 및 권한 부여

다른 Node Exporter와는 다르게 MariaDB는 metrics 정보를 수집 하기 위해선 우선 권한을 가진 계정이 필요합니다.

# 계정 생성 
CREATE USER 'monitoring'@'%' IDENTIFIED by 'password' WITH MAX_USER_CONNECTIONS 2; 

# 권한 부여
## PROCESS : 현재 실행중인 프로세스 조회 권한
## REPLICATION CLIENT : Master, Slave 조회 권한
## SELECT : 모든 DB, 테이블에 대한 SELECT 조회 권한
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'monitoring'@'%';
FLUSH PRIVILEGES;

Mysql Node Exporter 설치

계정을 생성하고 조회 권한을 부여하였다면, 다음으로 MySQL Exporter 설치를 진행합니다.

 wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gz
 tar xvfz mysqld_exporter-0.15.0.linux-amd64.tar.gz 
 sudo mv mysqld_exporter-0.15.0.linux-amd64 /usr/local/mysqld_exporter

Mysql Exporter 서비스 등록

Mysql Exporter 설치하였다면 Systemd에 등록하여 사용할수 있도록 작업이 필요합니다.

Service 파일 생성

우선 /etc/systemd/system/ 경로에 mysqld_exporter.service 생성합니다.

[Unit]
Description=Prometheus MySQL Exporter
After=network.target

[Service]
User=root
Group=root
Type=simple
Restart=always
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
--config.my-cnf /usr/local/mysqld_exporter/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                        

Service 등록 및 실행

Service 파일을 생성하였다면 daemon에 등록한 후에 Service 실행이 필요합니다.

# 추가 된 서비스 설정을 데몬에 반영
sudo systemctl daemon-reload

# MySQL Exporter 서비스 실행
sudo systemctl enable --now mysqld_exporter

Mysql Exporter 동작 확인

MySQL Exporter 실행이 끝났다면 해당 서비스가 제대로 동작하는지 확인이 필요합니다.

  • systemctl 명령어
    sudo systemctl status mysqld_exporter
  • 포트 확인
    • netstat -tnlp 으로 9104 포트 LISTEN 여부 확인

2. Prometheus 설정

Mysql Exporter 설치, 세팅 작업이 완료되었습니다.

다음 MariaDB Metrics 정보를 수집하기 위한 Prometheus 설정이 필요합니다.

MySQL Prometheus 설정

우선 /etc/prometheus/prometheus.yml 에 MySQL 설정 작업을 추가해야 합니다.

      scrape_configs:
      - job_name: 'mysql-server'
        static_configs:
        - targets: ['${mysql_server_ip}:9104']

prometheus 재기동

설정이 완료되었다면 Prometheus를 재기동 합니다.

    sudo systemctl restart prometheus
    sudo systemctl status prometheus

prometheus 동작확인

Prometheus를 재기동 하였다면 브라우저로 접근하여 연결 되었는지 확인이 필요합니다.

3. Grafana 대시보드 생성

MySQL Exporter, Prometheus까지 연동이 완료되었습니다.

이제 마지막으로 Grafana를 연동하여 대시보드에 데이터를 시각화해 보겠습니다

대시보드 선택

RabbitMQ, Redis Dashboard 연결과 마찬가지로 직접 구현할 수도 있으나 아래 사이트 들어가서 Mysql 관련 테마를 검색한 후 나에게 맞는 테마를 선택하였습니다.

대시보드 구성

  1. 우측 하단에 Dashboard ID copied! 클릭
  1. Grafana 대시보드에 접속하여 왼쪽 매뉴에 ‘Create’ > ‘import’ 클릭

3.복사 했던 ID를 붙여놓기 한 다음 import 클릭

  1. Name, Folder, Prometheus 선택후 import 클릭

해당 과정을 진행하면 아래와 같이 MySQL 대시보드가 생성 됩니다.

4. 마무리

MariaDB Metrics 정보까지 수집이 완료되었습니다.
다음 블로그 글에는 Nginx Metrics를 수집하도록 하겠습니다.

5. 참조

0개의 댓글