오픈소스로 만드는 db 모니터링 시스템 (w/graphite+grafana)

51
오픈소스를 활용한 모니터링 시스템 (grafana, graphite) LOEN Entertainment MelOn 사업부문 IT인프라팀 유승민

Upload: i-goo-lee

Post on 23-Jan-2018

1.975 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

오픈소스를 활용한 모니터링 시스템 (grafana, graphite)

LOEN Entertainment

MelOn 사업부문 IT인프라팀

유승민

Page 2: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

좋은 모니터링 툴이 필요한 이유

선제적 대응

소 잃기 전에 외양간 고치자!

Page 3: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

보유하고 있던 기존 모니터링 툴의 아쉬운 점

모니터링 지표 추가가 까다롭다.

대시보드 배치를 효율적으로 구성 하기가 쉽지 않다.

Client Agent 방식이 아닌 Server 에서 수집하는 방식이다. (보안 취약)

장기간 추이 분석이 번거롭고 부정확하다.

Page 4: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

그러던 어느 날.. http://play.grafana.org/

Page 5: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

시계열 데이터를 저장하는 DB를 데이터 소스로 연계하여 고급스러운 대시보드를 쉽게 만들 수 있다.

데이터 소스로 Graphite, InfluxDB, OpenTSDB 와 연계할 수 있으며 멀티로도 연계 가능하다.

말이 필요 없이 최고!

Page 6: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

시계열 데이터 저장에 특화된 DB와 그래프 관련 API를 제공하는 서버로 구성되어 있다.

데이터 수집은 사용자가 비교적 쉽게 만들 수 있고 다양한 연계 툴을 활용할 수도 있다.

분산 아키텍처로 유연하게 확장 가능하여 수집 데이터가 많은 대규모 인프라에도 활용 가능하다.

자체 대시보드 기능도 제공하지만 모니터링 툴로 활용하기엔 아쉬운 점이 있다.

Python 으로 개발되었고 의존관계 모듈이 많아 설치가 까다롭다.

Metric 수집 및 전송 (자체 제작 또는 연계 툴 활용)

Render Graph (다양한 연계 툴)

Carbon Cache

Whisper (DB)

Graphite Web (API)

Page 7: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

3개의 Component 로 구성되어 있다.

1. Carbon : 데이터를 수신하는 데몬으로 백그라운드로 항상 실행 상태 유지

2. Whisper : 시계열로 정렬된 데이터 저장에 특화된 경량 DB (RRD와 유사)

3. Graphite Web : 그래프를 그리는데 필요한 API 제공 및 자체 대시보드 기능을 위한 Django 웹 서버

Metric 수집 및 전송 (자체 제작 또는 연계 툴 활용)

Render Graph (다양한 연계 툴)

Carbon Cache

Whisper (DB)

Graphite Web (API)

Page 8: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Metric 수집 및 전송 (자체 제작)

Render Graph

Architecture

Carbon Cache

(수신기)

Whisper (DB)

Graphite Web (API)

graphite_gather_dstat.sh graphite_gather_mariadb.sh graphite_gather_oracle.sh

통합관제 (Alert)

준비중..

Page 9: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

로그 수집

로그 저장/검색

대시보드

ELK Stack 로그분석 시스템

비슷한 것..

그러나 다른..

Page 10: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 1. dependency

# python 이 없을 시 설치 $ sudo yum install python # dependency 확인 $ wget https://launchpad.net/graphite/0.9/0.9.10/+download/check-dependencies.py $ python check-dependencies.py

[FATAL] Unable to import the 'whisper' module, please download this package from the Graphite project page and install it. [FATAL] Unable to import the 'django' module, do you have Django installed for python 2.6.6? [FATAL] Unable to import the 'tagging' module, do you have django-tagging installed for python 2.6.6? [WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python 2.6.6? mod_python is one of the most common ways to run graphite-web under apache. Without mod_python you will still be able to use the built in development server; which is not recommended for production use. wsgi or other approaches for production scale use are also possible without mod_python [WARNING] Unable to import the 'txamqp' module, this is required if you want to use AMQP. Note that txamqp requires python 2.5 or greater. 3 necessary dependencies not met. Graphite will not function until these dependencies are fulfilled. 2 optional dependencies not met. Please consider the warning messages before proceeding. # dependency 모듈 설치 $ yum install Django $ yum install Django-tagging $ yum install mod_python $ yum install python-memcached $ yum install python-ldap $ yum install Twisted $ easy_install txamqp $ easy_install whisper # 아래와 같이 메시지가 나오면 OK $ python check-dependencies.py

All necessary dependencies are met. All optional dependencies are met.

설치 환경은 Oracle Enterprise Linux 6 입니다.

Page 11: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 2. Download and Installation

# 다운로드 $ cd /root/programs $ git clone https://github.com/graphite-project/graphite-web.git $ git clone https://github.com/graphite-project/carbon.git $ git clone https://github.com/graphite-project/whisper.git $ ls -al 합계 2152 drwxr-xr-x 5 root root 4096 2015-08-20 15:50 . dr-xr-x---. 13 root root 4096 2015-08-20 14:33 .. drwxr-xr-x 10 root root 4096 2015-08-20 15:53 carbon -rw-r--r-- 1 root root 42201 2012-06-01 05:38 carbon-0.9.10.tar.gz -rw-r--r-- 1 root root 5196 2012-05-03 23:14 check-dependencies.py drwxr-xr-x 12 root root 4096 2015-08-20 15:54 graphite-web -rw-r--r-- 1 root root 2117421 2012-06-01 05:38 graphite-web-0.9.10.tar.gz drwxr-xr-x 5 root root 4096 2015-08-20 15:50 whisper -rw-r--r-- 1 root root 10661 2012-06-01 05:37 whisper-0.9.10.tar.gz

# Default 경로 (/opt/graphite) 설치 $ cd carbon $ python setup.py install $ cd .. $ $ cd graphite-web $ python setup.py install $ cd .. $ $ cd whisper $ python setup.py install $ cd ..

# Custom 경로 설치 $ cd carbon $ python setup.py install --prefix=/srv/graphite --install-lib=/srv/graphite/lib $ cd .. $ $ cd graphite-web $ python setup.py install --prefix=/srv/graphite --install-lib=/srv/graphite/webapp $ cd ..

정신 건강을 위해 DEFAULT 경로에

설치하는 것을 권고합니다.

Page 12: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 3. Graphite-web's local_settings.py

# 설치경로에 아래와 같이 파일들이 생성된다. $ ls –l /opt/graphite 합계 28 drwxrwxrwx 2 root root 4096 2015-04-03 20:27 bin drwxrwxrwx 2 root root 4096 2015-04-24 15:30 conf drwxrwxrwx 2 root root 4096 2015-05-12 22:57 examples drwxrwxrwx 4 root root 4096 2015-04-03 20:27 lib drwxrwxrwx 7 root root 4096 2015-05-06 21:05 storage drwxrwxrwx 4 root root 4096 2015-04-03 20:28 webapp $ cd /opt/graphite/webapp/graphite $ cp local_settings.py.example local_settings.py $ vi local_settings.py # local_settings.py 파일을 열어서 DEBUG=True 를 주석 해제 한다. # 기본경로로 설치 하지 않았을 경우 아래 설정의 주석 해제 후 설치한 경로를 지정한다. GRAPHITE_ROOT = '/opt/graphite' STATIC_ROOT='/opt/graphite/static' CONF_DIR = '/opt/graphite/conf' STORAGE_DIR = '/opt/graphite/storage' STATIC_ROOT = '/opt/graphite/static'

Page 13: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 4. Configuring The Webapp

# 다운로드한 설치파일에서 manage.py 를 설치경로에 복사 $ cp /root/programs/graphite-web/webapp/manage.py /opt/graphite/webapp/graphite/ $ cd /opt/graphite/webapp/graphite # manage.py 파일을 열어서 붉은색으로 표시한 부분을 추가한다. $ vi manage.py $ python manage.py collectstatic /opt/graphite/webapp/graphite/settings.py:233: UserWarning: SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security warn('SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security') You have requested to collect static files at the destination location as specified in your settings. This will overwrite existing files! Are you sure you want to do this? Type 'yes' to continue, or 'no' to cancel: yes

# /opt/graphite 밑에 static 경로가 생긴 것을 확인할 수 있다.

#!/usr/bin/env python import os import sys sys.path.append('/opt/graphite/webapp') if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "graphite.settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)

Page 14: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 4. Configuring The Webapp

# 아파치 홈 경로의 httpd.conf 에 가상호스트 설정을 한다. (기본경로는 /etc/httpd/conf/httpd.conf) # /opt/graphite/examples/example-graphite-vhost.conf 의 내용을 copy 하여 httpd.conf 에 추가한다. # 기본경로 설치가 아닌 경우 /opt/graphite 부분을 지정한 경로로 모두 바꿔 주어야 한다. # 아파치 설정에 오류가 없는지 확인 $ /etc/init.d/httpd configtest httpd: Syntax error on line 192 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_wsgi.so into server: /etc/httpd/modules/mod_wsgi.so: cannot open shared object file: No such file or directory

# mod_wsgi.so 모듈이 없어서 에러나면 설치하고 다시 확인한다. $ yum install mod_wsgi $ /etc/init.d/httpd configtest Syntax OK

# 아파치 재시작 시 에러가 날 경우 tail -f /opt/graphite/storage/log/webapp/error.log 보면서 트러블슈팅 한다. $ /etc/init.d/httpd reload # 파일 접근 오류가 나면 /home/graphite 경로가 아파치 데몬 실행 유저가 접근할 수 있는 권한이 있는지 확인한다. $ chmod -R 777 /opt/graphite/

<IfModule !wsgi_module.c> LoadModule wsgi_module modules/mod_wsgi.so </IfModule> WSGISocketPrefix run/wsgi <VirtualHost *:80> ServerName graphite.melon.com DocumentRoot "/opt/graphite/webapp" ErrorLog /opt/graphite/storage/log/webapp/error.log CustomLog /opt/graphite/storage/log/webapp/access.log common WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 WSGIProcessGroup graphite WSGIApplicationGroup %{GLOBAL} WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL} WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi Alias /static/ /opt/graphite/static/ Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/" </VirtualHost>

Page 15: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Installation – 4. Configuring The Webapp

# 기본경로 설치가 아닌 경우 붉은색 부분을 수정한다. $ cd /opt/graphite/conf $ cp graphite.wsgi.example graphite.wsgi $ vi graphite.wsgi import sys sys.path.append('/opt/graphite/webapp') from graphite.wsgi import application

# Django database 구성 $ cd /opt/graphite/webapp/graphite $ python manage.py syncdb Creating tables ... Creating table account_profile Creating table account_variable Creating table account_view Creating table account_window Creating table account_mygraph Creating table dashboard_dashboard_owners Creating table dashboard_dashboard Creating table dashboard_template_owners Creating table dashboard_template Creating table events_event Creating table url_shortener_link Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_user_permissions Creating table auth_user_groups Creating table auth_user Creating table django_session Creating table django_admin_log Creating table django_content_type Creating table tagging_tag Creating table tagging_taggeditem You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (leave blank to use 'root'): E-mail address: [email protected] Password: Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s)

$ chown nobody:nobody /opt/graphite/storage/graphite.db

# 접속할 PC의 hosts 설정을 하고 접속한다. # 파일에 다음 추가하고 접속한다. 192.168.238.11 graphite.melon.com # <예외사항> # Exception Value: No module named pyparsing # 누락된 모듈을 설치하면 된다. $ yum install pyparsing # Exception Value: attempt to write a readonly database # Django가 사용하는 sqlite db에 아파치 실행 유저가 쓰기 권한이 없어서 발생하는 에러이므로 쓰기 권한을 부여한다. $ chmod 777 /home/graphite/storage/graphite.db

Page 16: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite 접속 화면

Page 17: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Configuring Carbon – carbon.conf

$ cd /home/graphite/conf $ cp carbon.conf.example carbon.conf # <carbon.conf> #[cache] 섹션이 carbon-cache 관련 설정인데 메트릭을 수신하는 port 가 2003 인 것을 확인한다. # LOG_LISTENER_CONN_SUCCESS 는 False 로 설정하여 불필요한 로그로 디스크가 낭비되는 것을 방지한다. # 설정하지 않으면 /opt/graphite/storage/log/carbon-cache/carbon-cache-a/listener.log 에 아래와 같은 로그가 메트릭 수신할 때마다 남는다.

LINE_RECEIVER_PORT = 2003 UDP_RECEIVER_PORT = 2003 PICKLE_RECEIVER_PORT = 2004 CACHE_QUERY_PORT = 7002 LOG_LISTENER_CONN_SUCCESS = False

15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20612 closed cleanly 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20613 established 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20613 closed cleanly 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20614 established 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20614 closed cleanly 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20615 established 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20615 closed cleanly 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20616 established 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20616 closed cleanly 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20619 established 15/04/2015 14:56:01 :: MetricLineReceiver connection with 192.168.238.100:20619 closed cleanly

LOG_LISTENER_CONN_SUCCESS = False

Page 18: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Configuring Carbon - storage-schemas.conf

$ cd /home/graphite/conf $ cp storage-schemas.conf.example storage-schemas.conf # <storage-schemas.conf> # storage-schemas.conf 는 데이터 보관 주기 설정으로 신경 쓸 필요가 있다. # 1. 섹션은 위에서 부터 아래로 적용된다. # 2. 변경된 설정은 이미 생성된 whisper data file (.wsp) 에는 적용되지 않는다. 적용하려면 whisper-resize.py 를 이용한다. # carbon-cache(메트릭 수신기) 데몬 실행. # carbon.conf 에 설정된 대로 2003, 2004 포트로 데이터를 수신한다. $ cd /opt/graphite/bin $ ./carbon-cache.py start Starting carbon-cache (instance a)

$ ps -ef | grep carbon root 13222 1 0 11:50 ? 00:00:00 /usr/bin/python ./carbon-cache.py start root 14068 8773 0 11:50 pts/2 00:00:00 grep carbon

[carbon] pattern = ^carbon\. 메트릭 계층 구조가 carbon. 으로 시작하는 것들 (메트릭 계층 구조 설계가 중요하다.) retentions = 60:90d 메트릭 포인트가 60초 간격으로 수집되는 것을 90일 동안 저장 [default] pattern = .* retentions = 5s:30d,10s:1y,60s:5y

Page 19: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Getting Your Data Into Graphite

Graphite message format – Plaintext protocol 방식 (2003 Port)

<metric path> <metric value> <metric timestamp>

nc (netcat) 명령어를 이용하여 전송

echo “depth1.depth2.depth3.metric_name 55 `date +%s`” | nc GRAPHITE_SERVER 2003

Graphite message format – Pickle protocol 방식 (2004 Port)

[(path, (timestamp, value)), ...] 와 같이 여러 개의 값을 한번에 전송 가능

Python 개발을 할 줄 안다면 유용

Page 20: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Getting Your Data Into Graphite

echo “`hostname`.db.mariadb.qps.Com_select 55 `date +%s`” | nc graphite.melon.com 2003

Send graphite message example

[root@mlcp02]# pwd /opt/graphite/storage/whisper/mlcp02/db/mariadb/qps [root@mlcp02]# [root@mlcp02]# ls -al 합계 13252 drwxr-xr-x 2 root root 4096 2015-04-10 23:33 . drwxr-xr-x 4 root root 4096 2015-04-10 23:41 .. -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_delete.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_delete_multi.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_insert.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_insert_select.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_select.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_update.wsp -rw-r--r-- 1 root root 1935412 2015-04-10 23:36 Com_update_multi.wsp [root@mlcp02]#

Page 21: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

이제 원하는 대로 수집 하면 됩니다.

Page 22: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite 연계되는 다양한 데이터 수집 툴을 활용해도 됩니다. https://graphite.readthedocs.org/en/latest/tools.html

Page 23: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

OS 모니터링 지표 수집

dstat을 활용하여 쉘 스크립트로 작성 (version 0.7.0 이상)

$ cd /root/graphite_gather/ $ cat .env.ini export SLEEP_TIME=59 ## (수집 주기는 1분) $ $ vi graphite_gather_dstat.sh # 백그라운드로 수행 $ nohup graphite_gather_dstat.sh & $ ps -ef | grep graphite root 50607 45401 0 12:40 pts/1 00:00:00 grep graphite root 64321 1 0 May18 ? 02:33:51 /bin/sh ./graphite_gather_dstat.sh

#!/bin/sh . /root/graphite_gather/.env.ini array_name=("cpu_user" "cpu_sys" "cpu_idle" "cpu_wait" "cpu_hiq" "cpu_siq" "mem_used" "mem_buff" "mem_cach" "mem_free" "disk_read" "disk_write" "io_read" "io_write" "net_recv" "net_send" "swap_used" "swap_free" "paging_in" "paging_out" "open_files" "inodes") while(true) do dstat -cmdrnsg --fs --output /root/graphite_gather/dstat.csv 1 1 stat=`cat /root/graphite_gather/dstat.csv | tail -1` array_value=(`echo $stat | tr ',' ' '`) for (( i = 0 ; i < ${#array_name[@]} ; i++ )) ; do echo "`hostname`.os.${array_name[$i]} ${array_value[$i]} `date +%s`" | nc graphite 2003 #echo "`hostname`.os.${array_name[$i]} ${array_value[$i]} `date +%s`" done cpu_idle=`echo $stat | awk -F, '{printf"%d", $3}'` cpu_usage=$((100-$cpu_idle)) echo "`hostname`.os.cpu_usage $cpu_usage `date +%s`" | nc graphite 2003 #echo "`hostname`.os.cpu_usage $cpu_usage `date +%s`" rm -rf /root/graphite_gather/dstat.csv sleep $SLEEP_TIME done

Page 24: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

OS 모니터링 지표 수집

$ $ pwd /opt/graphite/storage/whisper/mlcp02/os $ $ $ $ ls -l 합계 47300 -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_hiq.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_idle.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_siq.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_sys.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_user.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 cpu_wait.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 disk_read.wsp -rw-r--r-- 1 root root 1935412 2015-04-27 18:29 disk_wirte.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 disk_write.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 inodes.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 io_read.wsp -rw-r--r-- 1 root root 1935412 2015-04-27 18:29 io_wirte.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 io_write.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 mem_buff.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 mem_cach.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 mem_free.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 mem_used.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 net_recv.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 net_send.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 open_files.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 paging_in.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 paging_out.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 swap_free.wsp -rw-r--r-- 1 root root 1935412 2015-08-25 10:58 swap_used.wsp $ $

Page 25: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

MariaDB(MySQL) 모니터링 지표 수집 (5.5기준) $ cd /root/graphite_gather/ $ cat .env.ini export SLEEP_TIME=57 ## (수집주기는 1분) export MYSQL_HOME=/home/mysql/MariaDB # mystat.txt 파일에 현재 상태 값을 나타내는 status 항목 저장 $ cat mystat.txt Threads_cached Threads_connected Threads_running # mystat_com.txt 는 누적 값을 나타내는 항목 저장 $ cat mystat_com.txt Com_delete Com_insert Com_select Com_update $ vi graphite_gather_mariadb.sh # 백그라운드로 수행 $ nohup graphite_gather_mariadb.sh & $ ps -ef | grep graphite_ root 22329 21891 0 13:53 pts/3 00:00:00 grep graphite_ root 45282 1 0 May14 ? 08:41:32 /bin/sh ./graphite_gather_dstat.sh root 62776 1 1 May06 ? 1-18:05:38 /bin/sh ./graphite_gather_mariadb.sh

#!/bin/sh . /root/graphite_gather/.env.ini hostname=`hostname` while(true) do mystat= mystat_com= while read line; do mystat=$mystat'|'$line; done < /root/graphite_gather/mystat.txt $MYSQL_HOME/bin/mysqladmin -uroot -p`cat /home/mysql/.mysqlpw.ini` -S /tmp/mysql.sock extended-status | grep -E `echo ${mystat:1}` | tail -`cat /root/graphite_gather/mystat.txt | wc -l` | awk '{print $2 " " $4}' > /root/graphite_gather/mystat_result while read line; do mystat_com=$mystat_com'|'$line; done < /root/graphite_gather/mystat_com.txt $MYSQL_HOME/bin/mysqladmin -uroot -p`cat /home/mysql/.mysqlpw.ini` -S /tmp/mysql.sock extended-status -r -i 1 -c 2 | grep -E `echo ${mystat_com:1}` | tail -`cat /root/graphite_gather/mystat_com.txt | wc -l` | awk '{print $2 " " $4}' >> /root/graphite_gather/mystat_result while read line; do echo "real.${hostname:0:${#hostname}-1}.${hostname:${#hostname}-1:1}.dbstat.$line `date +%s`" | nc graphite 2003; done < /root/graphite_gather/mystat_result #while read line; do echo "real.${hostname:0:${#hostname}-1}.${hostname:${#hostname}-1:1}.dbstat.$line `date +%s`"; done < /root/graphite_gather/mystat_result sleep $SLEEP_TIME done

Page 26: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Oracle 모니터링 지표 수집 (11.2.0.4 기준)

# 사전작업 (임시 저장용 테이블 생성) SQL> create table mondba.sysstat as select * from v$sysstat where 1=0; SQL> alter table mondba.sysstat add no number not null; SQL> insert into mondba.sysstat select a.*, 1 from v$sysstat a; SQL> commit; $ vi graphite_gather_oracle.sql

set heading off set feedback off set time off timing off set pages 0 col value for 9999999999999999999999999999 insert into mondba.sysstat1 select a.*, (select max(no)+1 from mondba.sysstat1) from v$sysstat a; select replace(replace(replace(name,' ','_'),'(',''),')','')||' '||to_char(value) from ( select pool as name, sum(bytes) as value from v$sgastat where pool is not null group by pool union all select name, bytes as value from v$sgastat where pool is null union all select lower(status)||'_session' as name, count(*) as value from v$session group by status union all select 'data_size' as name, sum(bytes) as value from dba_data_files union all select 'free_size' as name, sum(bytes) as value from dba_free_space union all select b.name, sum(a.value) as value from v$sesstat a, v$statname b where a.statistic#=b.statistic# and b.name in ('session pga memory', 'opened cursors current', 'session uga memory') group by b.name union all select now.name, now.value-bef.value as value from (select name, value from mondba.sysstat1 where no=(select max(no) from mondba.sysstat1)) now, (select name, value from mondba.sysstat1 where no=(select max(no)-1 from mondba.sysstat1)) bef where now.name=bef.name and now.name in ('user calls', 'execute count', 'user commits', 'user rollbacks', 'consistent changes', 'session logical reads', 'db block gets', 'db block changes', /************************** * 원하는 통계 지표 추가 * **************************/ 'cell physical IO bytes saved by storage index', 'cell physical IO interconnect bytes' ) ); delete from mondba.sysstat1 where no=(select max(no)-2 from mondba.sysstat1); commit;

Page 27: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Oracle 모니터링 지표 수집 (11.2.0.4 기준)

$ cat .env.ini export SLEEP_TIME=60 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1 export ORACLE_SID=ORAMP1 # 데이터 수집 쉘 $ vi graphite_gather_oracle.sh # 백그라운드로 수행 $ chmod 744 graphite_gather_oracle.sh $ $ nohup graphite_gather_oracle.sh & $ $ ps -ef | grep graphite_gather root 16544 29835 0 18:15 pts/7 00:00:00 grep graphite_gather root 27760 1 2 10:54 ? 00:10:39 /bin/sh ./graphite_gather_dstat.sh root 45282 1 0 May14 ? 09:03:38 /bin/sh ./graphite_gather_oracle.sh root 62776 1 1 May06 ? 1-19:46:02 /bin/sh ./graphite_gather_mariadb.sh

#!/bin/sh . /root/graphite_gather/.env.ini while(true) do $ORACLE_HOME/bin/sqlplus -s '/as sysdba' < /root/graphite_gather/graphite_gather_oracle.sql > /root/graphite_gather/orastat.txt while read line; do echo "`hostname`.$ORACLE_SID.$line `date +%s`" | nc graphite 2003; done < /root/graphite_gather/orastat.txt #while read line; do echo "`hostname`.$ORACLE_SID.$line `date +%s`"; done < /root/graphite_gather/orastat.txt sleep $SLEEP_TIME done

Page 28: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

원하는 지표를 수집했으니..

이제 그리기만 하면 됩니다.

Page 29: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite에서 기본으로 제공하는 대시보드 (Poor… -_-)

Grafana (Awesome!! +_+)

Page 31: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana Installation

http://docs.grafana.org/installation/

Graphite 와는 다르게 설치가 매우 간단하다.

Page 32: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana Installation

Page 33: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana 접속 화면

Page 34: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana Data source 설정

Page 35: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana - OS 모니터링

Page 36: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana - MariaDB (MySQL) 실시간 모니터링

Page 37: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana - Oracle 모니터링 (1)

Page 38: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana - Oracle 모니터링 (2)

Page 39: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

DEMO Grafana Dashboard design (10 min)

Page 40: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Performance Issue

성능 병목 지점

1. Carbon-Cache

2. Whisper file IO (메트릭 수 = 파일 수)

성능 개선 방안

1. Multiple Carbon-Cache (1 CPU Core = 1 Daemon)

2. Clustering

3. SSD

4. InfluxDB

Page 41: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Multiple Carbon-Cache Daemons

CLIENT (Send Metric)

Render Graph

Graphite Webapp (API)

carbon-cache (2043) carbon-cache (2023) carbon-cache (2013) carbon-cache (2033)

carbon-relay (2003)

Whisper (DB)

Page 42: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Clustering

CLIENT (Send Metric)

Render Graph

Whisper (DB)

carbon-relay (2003)

carbon-cache (2033) carbon-cache (2023)

Graphite Webapp (API)

Whisper (DB)

carbon-cache (2033) carbon-cache (2023)

Graphite Webapp (API)

carbon-relay (2013) carbon-relay (2013)

Page 43: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

모니터링 대상 서버가 많은 대규모 인프라에 적용 시 InfluxDB도 적극 검토해 보자.

이미 graphite 로 구축된 상태라면 InfluxDB와 결합하여 Clustering 구성도 가능하다.

시계열 데이터 저장용 DATABASE

GO 언어로 개발 된 최신 오픈소스 프로젝트 (대량 트래픽 처리에 우수)

Dependency가 없어 설치가 간단함

SQL-like query language

Clustering 지원

Page 44: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Graphite Clustering with InfluxDB

CLIENT (Send Metric)

Render Graph

Whisper (DB)

carbon-relay-ng (2003)

carbon-cache (2033) carbon-cache (2023)

Graphite Webapp (API)

carbon-relay (2013)

Page 45: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

시작은 DB모니터링 이었으나…

Page 46: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

개발자의 제안으로 이런 것도 합니다.

몇 분 정도 사용법 설명 후 담당 개발자가 직접 데이터 수집 및 대시보드 생성하여 다양하게 활용 중

Page 47: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

SE의 제안으로 이런 것도 합니다.

Page 48: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

인프라를 운영하는 개발자 , SE, DBA 가 ..

관심 있는 지표를 수집하고 대시보드로 구현하는데..

불과 몇 시간 또는 몇 분이면 됩니다.

중요한 건 관심 과 사랑

DevOps 환경에서도 많이 사용한다고 합니다.

Page 49: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

신속한 장애 예방, 어뷰징 탐지, 인프라 사이즈 예측 …

점점 개선 및 발전해 나가고 있습니다.

Page 50: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

Grafana http://grafana.org/ Graphite https://graphite.readthedocs.org/en/latest/ http://www.aosabook.org/en/graphite.html Graphite Clustering https://grey-boundary.io/the-architecture-of-clustering-graphite/ http://dieter.plaetinck.be/post/on-graphite-whisper-and-influxdb/ http://dieter.plaetinck.be/post/influxdb-as-graphite-backend-part2/ Graphite Tuning https://grey-boundary.io/minimizing-datapoint-lag-in-graphite/ Carbon-relay-ng (GitHub) https://github.com/graphite-ng/carbon-relay-ng InfluxDB https://influxdb.com/

참고 사이트

Page 51: 오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)

감사합니다