MySQL, MariaDB

MySQL/MariaDB QPS(Query per second) 모니터링

SungWookKang 2019. 3. 24. 11:02
반응형

MySQL/MariaDB QPS(Query per second) 모니터링

 

-       Version : MySQL 5.7.21, Ubuntu 16.0.4

 

MySQL 서버에 요청되는 초당 요청량 (Query per Second, QPS)을 모니터링 하는 방법에 대해서 알아본다.

 

아래 스크립트를 실행하면 현재까지 수행된 Query의 요청에 대해서 확인할 수 있다. 여기에 나타난 값은 누적값이기 때문에, 수집 시간 간격에 따라 산술적 연상이 필요 하다.

show global status where variable_name in (

'questions',

'com_select',

'com_insert',

'com_delete',

'com_update',

'com_replace',

'com_load',

'com_delete_multi',

'com_insert_select',

'com_update_multi',

'com_replace_select'

);

 


 

Variable Name

Comment

questions

-   전체 쿼리 요청 횟수 (누적값)

-   Com_ping, com_statistics, com_stmt_prepare, com_stmt_close, com_stmt_reset횟수 제외

-   Stored programs 내부에서 실행하는 쿼리 실행 횟수 제외

com_select

SELECT 쿼리 실행 횟수

com_insert

INSERT 쿼리 실행 횟수

com_delete

DELETE 쿼리 실행 횟수

com_update

UPDATE 쿼리 실행 횟수

com_replace

REPLACE 쿼리 실행 횟수

com_load

LOAD 쿼리 실행 횟수

com_delete_multi

다중 테이블 DELETE 쿼리 실행 횟수

com_insert_select

INSERT SELECT 쿼리 실행 횟수

com_update_multi

다중 테이블 UPDATE 쿼리 실행 횟수

com_replace_select

REPLACE SELEC V쿼리 실행 횟수

 

아래 스크립트를 실행하면 위의 정보를 보기 쉽게 나타낼 수 있다.

select

  SUBSTRING(VARIABLE_NAME, 5) as query_type,

  VARIABLE_VALUE as total_count,

  round(VARIABLE_VALUE / ( select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'), 2) as per_second,

  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60)))       as per_minute,

  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60)))    as per_hour,

  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60*24))) as per_day,

  FROM_UNIXTIME(round(UNIX_TIMESTAMP(sysdate()) - (select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'))) report_period_start,

  sysdate() as report_period_end,

  TIME_FORMAT(SEC_TO_TIME((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status')),'%Hh %im') as report_period_duration

from

  information_schema.GLOBAL_STATUS

where

  VARIABLE_NAME in ('Com_select', 'Com_delete', 'Com_update', 'Com_insert');

 


 

MySQL 5.7 버전에서는 위 스크립트 실행시 아래와 같은 오류가 발생할 수 있다.

ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.GLOBAL_STATUS' feature is disabled;

see the documentation for 'show_compatibility_56'

 

오류가 발생한다면 아래 스크립트를 실행하여 호환성을 활성화 하도록 한다.

set @@global.show_compatibility_56=ON;

 

[참고자료]

https://dba.stackexchange.com/questions/57418/how-to-determine-mysql-queries-per-day

https://support.servosity.com/hc/en-us/articles/221071687-ISSUE-The-INFORMATION-SCHEMA-GLOBAL-STATUS-feature-is-disabled-see-the-documentation-for-show-compatibility-56-

 

 

 

2018-03-30 / 강성욱 / http://sqlmvp.kr / http://sqlangeles.com

 

MySQL, QPS, Query per second, show global status, 쿼리 모니터링, MySQL 사용량 모니터링, 초당 쿼리 요청 수


반응형