Created
January 25, 2026 01:15
-
-
Save DaikiSuganuma/bcd9c4d39a62325a8655eafdd956bb84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ================================================================================ | |
| MariaDB Performance Dashboard View (パフォーマンス監視用ビュー) | |
| ================================================================================ | |
| [概要] | |
| MariaDBのステータス変数(GLOBAL_STATUS)を加工し、データベースの健全性を | |
| 一目で判断できる形式で表示するビューです。 | |
| [主な機能] | |
| 1. InnoDBバッファプールヒット率の計算 | |
| 2. 一時テーブルのディスク書き込み状況の分析(論理的なディスク使用か、物理I/Oか) | |
| 3. テーブルキャッシュのヒット率計算 | |
| 4. 各指標に対する健全な状態の目安と、計算式の解説を表示 | |
| [出力項目の説明] | |
| - ステータス変数 : 監視対象の変数名 | |
| - 現在の値 : 変数の生の値(カンマ区切り) | |
| - 分析/ヒット率など : 関連する変数から計算された重要な比率(%) | |
| - 計算内容の説明 : 「分析/ヒット率」がどのような式で算出されたかの解説 | |
| - 健全な状態の目安 : 値が良い状態か悪い状態かを判断するための閾値やアドバイス | |
| [Created_tmp_disk_tables の判定について] | |
| この変数は「ディスク対応エンジン(Aria)が選択された回数」を示しますが、 | |
| 実際に物理ディスク(SSD/HDD)への書き込みが発生したとは限りません。 | |
| 本ビューでは「Aria_pagecache_writes / Aria_pagecache_write_requests」を計算し、 | |
| 実際に物理ディスクへの書き込みが発生した割合を「物理書込率」として表示します。 | |
| これが 0% であれば、全てメモリ(キャッシュ)上で処理されており、パフォーマンスへの影響はありません。 | |
| ================================================================================ | |
| */ | |
| CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `performance_dashboard` AS | |
| SELECT | |
| `gs`.`VARIABLE_NAME` AS `ステータス変数`, | |
| format(`gs`.`VARIABLE_VALUE`, 0) AS `現在の値`, | |
| -- 【分析/ヒット率など】 | |
| CASE | |
| -- InnoDBバッファプールヒット率 | |
| WHEN `gs`.`VARIABLE_NAME` = 'Innodb_buffer_pool_reads' THEN | |
| concat(round((1 - `gs`.`VARIABLE_VALUE` / nullif((select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Innodb_buffer_pool_read_requests'), 0)) * 100, 3), ' % ヒット率') | |
| -- Ariaページキャッシュの物理書き込み発生率(ここを物理負荷の指標として使用) | |
| WHEN `gs`.`VARIABLE_NAME` = 'Created_tmp_disk_tables' THEN | |
| concat(round((select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Aria_pagecache_writes') / nullif((select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Aria_pagecache_write_requests'), 0) * 100, 3), ' % 物理書込率') | |
| -- テーブルキャッシュヒット率 | |
| WHEN `gs`.`VARIABLE_NAME` = 'Table_open_cache_misses' AND `gs`.`VARIABLE_VALUE` + (select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Table_open_cache_hits') > 0 THEN | |
| concat(round((select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Table_open_cache_hits') / nullif(`gs`.`VARIABLE_VALUE` + (select `information_schema`.`GLOBAL_STATUS`.`VARIABLE_VALUE` from `information_schema`.`GLOBAL_STATUS` where `information_schema`.`GLOBAL_STATUS`.`VARIABLE_NAME` = 'Table_open_cache_hits'), 0) * 100, 2), ' % ヒット率') | |
| ELSE '--' | |
| END AS `分析/ヒット率など`, | |
| -- 【計算内容の説明】 | |
| CASE `gs`.`VARIABLE_NAME` | |
| WHEN 'Innodb_buffer_pool_reads' THEN '1 - (物理読込数 / 全読込要求数)' | |
| WHEN 'Created_tmp_disk_tables' THEN 'Aria物理書込数 / Aria書込要求数 (0%なら全てメモリ内で完結)' | |
| WHEN 'Table_open_cache_misses' THEN 'ヒット数 / (ヒット数 + ミス数)' | |
| ELSE '生の値を表示' | |
| END AS `計算内容の説明`, | |
| -- 【健全な状態の目安】 | |
| CASE `gs`.`VARIABLE_NAME` | |
| WHEN 'Innodb_buffer_pool_read_requests' THEN '総読み込み回数(メモリ+ディスク)。' | |
| WHEN 'Innodb_buffer_pool_reads' THEN '[目標: ヒット率 > 99.5%] ディスクからの読み込み回数。高いほど良い。' | |
| WHEN 'Created_tmp_tables' THEN '作成された一時テーブル総数。' | |
| WHEN 'Created_tmp_disk_tables' THEN '[目標: 物理書込率 = 0%] ディスク用エンジンが使われた回数。分析列が0%なら無害。' | |
| WHEN 'Aria_pagecache_writes' THEN '[目標: 0 または増加しない] 実際に物理ディスクへ書き込まれた回数。' | |
| WHEN 'Slow_queries' THEN '[目標: 急増しない] 遅いクエリの数。アプリ/プラグインの調査が必要な場合も。' | |
| WHEN 'Select_full_join' THEN '[目標: 常に 0] インデックス未使用のテーブル結合。0より大きい場合、インデックス不足を示唆。' | |
| WHEN 'Table_open_cache_hits' THEN 'キャッシュからテーブル定義を取得した回数。ヒット率の計算元。' | |
| WHEN 'Table_open_cache_misses' THEN '[目標: ヒット率 > 95%] キャッシュになかった回数。高いほど良い。' | |
| WHEN 'Max_used_connections' THEN '[目標: max_connectionsの80%未満] ピーク時の最大同時接続数。' | |
| ELSE '--' | |
| END AS `健全な状態の目安` | |
| FROM `information_schema`.`GLOBAL_STATUS` AS `gs` | |
| WHERE `gs`.`VARIABLE_NAME` in ( | |
| 'Innodb_buffer_pool_read_requests', | |
| 'Innodb_buffer_pool_reads', | |
| 'Created_tmp_tables', | |
| 'Created_tmp_disk_tables', | |
| 'Aria_pagecache_writes', | |
| 'Table_open_cache_hits', | |
| 'Table_open_cache_misses', | |
| 'Slow_queries', | |
| 'Select_full_join', | |
| 'Max_used_connections' | |
| ) | |
| ORDER BY field(`gs`.`VARIABLE_NAME`, | |
| 'Innodb_buffer_pool_read_requests', | |
| 'Innodb_buffer_pool_reads', | |
| 'Created_tmp_tables', | |
| 'Created_tmp_disk_tables', | |
| 'Aria_pagecache_writes', | |
| 'Table_open_cache_hits', | |
| 'Table_open_cache_misses', | |
| 'Slow_queries', | |
| 'Select_full_join', | |
| 'Max_used_connections' | |
| ) ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment