phpfui/mysql-slow-log-parser

具有可排序结果的 MySQL 和 MariaDB 慢查询日志解析器

V1.1.1 2023-11-23 14:50 UTC

This package is auto-updated.

Last update: 2024-09-10 14:31:41 UTC


README

PHP 解析器,用于 MySQL 和 MariaDB 慢查询日志,具有可排序的结果

要求

  • 现代 PHP 版本
  • MySQL 5.7 或更高版本,或 MariaDB

用法

$parser = new \PHPFUI\MySQLSlowQuery\Parser($logFilePath);

// Return the sessions in the file as array
$sessions = $parser->getSessions();

// Return all entries in file as array, or pass session number (0 based)
$entries = $parser->getEntries();

if (count($entries))
  {
  // Get the worst offender
  $entry = $parser->sortEntries()->getEntries()[0];
  echo 'Query ' . implode(' ', $entry->Query) . " took {$entry->Query_time} seconds at {$entry->Time}\n";

  // Get the most rows examined
  $entry = $parser->sortEntries('Rows_examined', 'desc')->getEntries()[0];
  echo 'Query ' . implode(' ', $entry->Query) . " looked at {$entry->Rows_examined} rows\n";
  }

条目

\PHPFUI\MySQLSlowQuery\Entry 提供了每个查询的详细信息。支持的字段

  • 时间
  • 用户
  • 主机
  • Id
  • Query_time
  • Lock_time
  • Rows_sent
  • Rows_examined
  • Query (数组)
  • Session (基于0)

MariaDB 添加以下字段

  • Thread_id
  • Schema
  • QC_hit
  • Rows_affected
  • Bytes_sent
  • Tmp_tables
  • Tmp_disk_tables
  • Tmp_table_sizes
  • Full_scan
  • Full_join
  • Tmp_table
  • Tmp_table_on_disk
  • Filesort
  • Filesort_on_disk
  • Merge_passes
  • Priority_queue
  • explain

会话

\PHPFUI\MySQLSlowQuery\Session 包含 MySQL 服务器信息,并在服务器重启和日志刷新时创建。传递基于0的会话编号以获取仅该会话条目的 getEntries。支持的字段

  • 服务器
  • 版本
  • 端口
  • 传输

排序条目

默认情况下,条目按日志顺序返回,但可以通过在解析器上调用 sortEntries 来按任何有效字段(参数1)排序。排序默认为 'desc',其他任何内容都将按升序排序。

完整的类文档

PHPFUI/InstaDoc

许可证

在 MIT 许可证下分发。