feat(admin): XHProf 性能日志五张表 Scheme 迁移与模型

This commit is contained in:
augushong
2026-08-14 22:04:52 +08:00
parent da388a8c4f
commit 7e73902325
15 changed files with 478 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
/**
* @property int $id 主键ID
* @property string $node_id 节点ID区分不同采集节点
* @property string $file_path 日志文件绝对路径
* @property int $inode 文件 inode用于检测日志轮转
* @property int $offset 上次读取到的字节偏移
* @property int $last_read_time 上次读取时间戳
* @property string $last_line_hash 上次最后一行的 md5 哈希(容错校验)
* @property int $parse_fail_count 解析失败累计次数
* @property string $parse_fail_samples 解析失败样本行(最多保留若干条)
* @property int $create_time 创建时间戳
* @property int $update_time 更新时间戳
*/
class XhprofLogPosition extends TimeModel
{
protected $name = "xhprof_log_position";
protected $deleteTime = false;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
/**
* @property int $id 主键ID
* @property string $node_id 节点ID区分不同采集节点
* @property string $url 请求完整 URL超长截断
* @property string $simple_url 规范化 URL去 query、数字段替换聚合用
* @property string $method HTTP 方法
* @property int $wall_time 总耗时微秒main() 的 wt
* @property int $cpu_time CPU 耗时微秒main() 的 cpu
* @property int $memory_peak 内存峰值字节main() 的 pmu
* @property string $request_time 请求开始时间REQUEST_TIME_FLOAT 浮点秒)
* @property int $create_time 入库时间戳
*/
class XhprofRun extends TimeModel
{
protected $name = "xhprof_run";
protected $deleteTime = false;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
/**
* @property int $id 主键,值=ul_xhprof_run.id不自增
* @property string $profile_data 原始 profile JSON
*/
class XhprofRunDetail extends TimeModel
{
protected $name = "xhprof_run_detail";
protected $deleteTime = false;
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
/**
* @property int $id 主键ID
* @property int $run_id 采样记录IDul_xhprof_run.id
* @property int $watch_id 监控规则IDul_xhprof_watch.id
* @property int $ct 命中边次数和
* @property int $wt_sum 命中耗时合计(微秒)
* @property int $wt_max 命中单次最大耗时(微秒)
* @property int $create_time 入库时间戳
*/
class XhprofRunWatch extends TimeModel
{
protected $name = "xhprof_run_watch";
protected $deleteTime = false;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
/**
* @property int $id 主键ID
* @property string $name 规则名称(人读)
* @property string $regex PCRE 正则(对被调用函数名匹配)
* @property string $note 备注
* @property int $threshold_ms 比对阈值毫秒0=不比对
* @property int $status 状态:1=启用,0=禁用
* @property int $create_time 创建时间戳
* @property int $update_time 更新时间戳
*/
class XhprofWatch extends TimeModel
{
protected $name = "xhprof_watch";
protected $deleteTime = false;
}

View File

@@ -0,0 +1,56 @@
<?php
namespace app\admin\scheme;
use app\common\scheme\BaseScheme;
use app\common\scheme\attribute\Table;
use app\common\scheme\attribute\Field;
use app\common\scheme\attribute\Component;
use app\common\scheme\attribute\Index;
#[Table(name: 'ul_xhprof_log_position', comment: 'XHProf 日志文件读取位置(增量读取状态)')]
#[Index(columns: ['node_id', 'file_path'], name: 'uniq_node_file', type: 'UNIQUE')]
class XhprofLogPosition extends BaseScheme
{
#[Field(type: 'int', length: 11, nullable: false, unsigned: true, autoIncrement: true, primary: true)]
public $id;
#[Field(type: 'varchar', length: 64, nullable: false, default: '', comment: '节点ID区分不同采集节点')]
public $node_id;
#[Field(type: 'varchar', length: 500, nullable: false, comment: '日志文件绝对路径')]
#[Component(type: 'text', options: [])]
public $file_path;
#[Field(type: 'bigint', default: '0', unsigned: true, comment: '文件 inode用于检测日志轮转')]
#[Component(type: 'text', options: [])]
public $inode;
#[Field(type: 'bigint', default: '0', unsigned: true, comment: '上次读取到的字节偏移')]
#[Component(type: 'text', options: [])]
public $offset;
#[Field(type: 'int', length: 11, default: '0', unsigned: true, comment: '上次读取时间戳')]
#[Component(type: 'date', options: [])]
public $last_read_time;
#[Field(type: 'varchar', length: 32, default: '', comment: '上次最后一行的 md5 哈希(容错校验)')]
#[Component(type: 'text', options: [])]
public $last_line_hash;
#[Field(type: 'int', length: 11, default: '0', unsigned: true, comment: '解析失败累计次数')]
#[Component(type: 'text', options: [])]
public $parse_fail_count;
#[Field(type: 'text', nullable: true, comment: '解析失败样本行(最多保留若干条)')]
#[Component(type: 'textarea', options: [])]
public $parse_fail_samples;
#[Field(type: 'int', length: 11, unsigned: true, comment: '创建时间戳')]
#[Component(type: 'date', options: [])]
public $create_time;
#[Field(type: 'int', length: 11, unsigned: true, comment: '更新时间戳')]
#[Component(type: 'date', options: [])]
public $update_time;
}

View File

@@ -0,0 +1,55 @@
<?php
namespace app\admin\scheme;
use app\common\scheme\BaseScheme;
use app\common\scheme\attribute\Table;
use app\common\scheme\attribute\Field;
use app\common\scheme\attribute\Component;
use app\common\scheme\attribute\Index;
#[Table(name: 'ul_xhprof_run', comment: 'XHProf 性能采样记录(每次请求一条)')]
#[Index(columns: ['simple_url', 'request_time'], name: 'idx_simple_url_time', type: 'NORMAL')]
#[Index(columns: ['request_time'], name: 'idx_request_time', type: 'NORMAL')]
#[Index(columns: ['wall_time'], name: 'idx_wall_time', type: 'NORMAL')]
class XhprofRun extends BaseScheme
{
#[Field(type: 'int', length: 11, nullable: false, unsigned: true, autoIncrement: true, primary: true)]
public $id;
#[Field(type: 'varchar', length: 64, nullable: false, default: 'default', comment: '节点ID区分不同采集节点')]
#[Component(type: 'text', options: [])]
public $node_id;
#[Field(type: 'varchar', length: 500, nullable: false, comment: '请求完整 URL超长截断')]
#[Component(type: 'text', options: [])]
public $url;
#[Field(type: 'varchar', length: 255, nullable: false, default: '', comment: '规范化 URL去 query、数字段替换聚合用')]
#[Component(type: 'text', options: [])]
public $simple_url;
#[Field(type: 'varchar', length: 10, nullable: false, default: '', comment: 'HTTP 方法')]
#[Component(type: 'text', options: [])]
public $method;
#[Field(type: 'bigint', default: '0', comment: '总耗时微秒main() 的 wt')]
#[Component(type: 'text', options: [])]
public $wall_time;
#[Field(type: 'bigint', default: '0', comment: 'CPU 耗时微秒main() 的 cpu')]
#[Component(type: 'text', options: [])]
public $cpu_time;
#[Field(type: 'bigint', default: '0', comment: '内存峰值字节main() 的 pmu')]
#[Component(type: 'text', options: [])]
public $memory_peak;
#[Field(type: 'decimal', precision: 12, scale: 3, default: '0.000', comment: '请求开始时间REQUEST_TIME_FLOAT 浮点秒)')]
#[Component(type: 'text', options: [])]
public $request_time;
#[Field(type: 'int', length: 11, unsigned: true, comment: '入库时间戳')]
#[Component(type: 'date', options: [])]
public $create_time;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace app\admin\scheme;
use app\common\scheme\BaseScheme;
use app\common\scheme\attribute\Table;
use app\common\scheme\attribute\Field;
/**
* XHProf 采样原始 profile 数据表(显式豁免表)
*
* - 不进后台:无 CURD 页面、无 Component 注解
* - 无 create_time/update_time/delete_time 约定字段
* - 无额外索引主键即查询入口id = ul_xhprof_run.id
*/
#[Table(name: 'ul_xhprof_run_detail', comment: 'XHProf 采样原始 profile 数据(按 run 1:1不进后台')]
class XhprofRunDetail extends BaseScheme
{
#[Field(type: 'int', length: 11, nullable: false, unsigned: true, autoIncrement: false, primary: true, comment: '主键,值=ul_xhprof_run.id不自增')]
public $id;
#[Field(type: 'longtext', nullable: true, comment: '原始 profile JSON')]
public $profile_data;
}

View File

@@ -0,0 +1,42 @@
<?php
namespace app\admin\scheme;
use app\common\scheme\BaseScheme;
use app\common\scheme\attribute\Table;
use app\common\scheme\attribute\Field;
use app\common\scheme\attribute\Component;
use app\common\scheme\attribute\Index;
#[Table(name: 'ul_xhprof_run_watch', comment: 'XHProf 采样与监控规则命中聚合(导入时物化)')]
#[Index(columns: ['watch_id', 'create_time'], name: 'idx_watch_time', type: 'NORMAL')]
#[Index(columns: ['run_id'], name: 'idx_run_id', type: 'NORMAL')]
class XhprofRunWatch extends BaseScheme
{
#[Field(type: 'int', length: 11, nullable: false, unsigned: true, autoIncrement: true, primary: true)]
public $id;
#[Field(type: 'int', length: 11, default: '0', unsigned: true, comment: '采样记录IDul_xhprof_run.id')]
#[Component(type: 'text', options: [])]
public $run_id;
#[Field(type: 'int', length: 11, default: '0', unsigned: true, comment: '监控规则IDul_xhprof_watch.id')]
#[Component(type: 'text', options: [])]
public $watch_id;
#[Field(type: 'int', length: 11, default: '0', comment: '命中边次数和')]
#[Component(type: 'text', options: [])]
public $ct;
#[Field(type: 'bigint', default: '0', comment: '命中耗时合计(微秒)')]
#[Component(type: 'text', options: [])]
public $wt_sum;
#[Field(type: 'bigint', default: '0', comment: '命中单次最大耗时(微秒)')]
#[Component(type: 'text', options: [])]
public $wt_max;
#[Field(type: 'int', length: 11, unsigned: true, comment: '入库时间戳')]
#[Component(type: 'date', options: [])]
public $create_time;
}

View File

@@ -0,0 +1,45 @@
<?php
namespace app\admin\scheme;
use app\common\scheme\BaseScheme;
use app\common\scheme\attribute\Table;
use app\common\scheme\attribute\Field;
use app\common\scheme\attribute\Component;
use app\common\scheme\attribute\Index;
#[Table(name: 'ul_xhprof_watch', comment: 'XHProf 函数监控规则')]
#[Index(columns: ['regex'], name: 'uniq_regex', type: 'UNIQUE')]
class XhprofWatch extends BaseScheme
{
#[Field(type: 'int', length: 11, nullable: false, unsigned: true, autoIncrement: true, primary: true)]
public $id;
#[Field(type: 'varchar', length: 100, nullable: false, comment: '规则名称(人读)')]
#[Component(type: 'text', options: [])]
public $name;
#[Field(type: 'varchar', length: 255, nullable: false, comment: 'PCRE 正则(对被调用函数名匹配)')]
#[Component(type: 'text', options: [])]
public $regex;
#[Field(type: 'varchar', length: 255, nullable: false, default: '', comment: '备注')]
#[Component(type: 'text', options: [])]
public $note;
#[Field(type: 'int', length: 11, default: '0', comment: '比对阈值毫秒0=不比对')]
#[Component(type: 'text', options: [])]
public $threshold_ms;
#[Field(type: 'tinyint', length: 4, default: '1', comment: '状态:1=启用,0=禁用')]
#[Component(type: 'switch', options: ['0' => '禁用', '1' => '启用'])]
public $status;
#[Field(type: 'int', length: 11, unsigned: true, comment: '创建时间戳')]
#[Component(type: 'date', options: [])]
public $create_time;
#[Field(type: 'int', length: 11, unsigned: true, comment: '更新时间戳')]
#[Component(type: 'date', options: [])]
public $update_time;
}