mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-09-05 07:15:31 +08:00
feat(log): 新增 ul_debug_log_position 表(migration+scheme+model)
This commit is contained in:
27
app/admin/model/DebugLogPosition.php
Normal file
27
app/admin/model/DebugLogPosition.php
Normal 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 DebugLogPosition extends TimeModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $name = "debug_log_position";
|
||||||
|
|
||||||
|
protected $deleteTime = false;
|
||||||
|
|
||||||
|
}
|
||||||
56
app/admin/scheme/DebugLogPosition.php
Normal file
56
app/admin/scheme/DebugLogPosition.php
Normal 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_debug_log_position', comment: '调试日志文件读取位置(增量读取状态)')]
|
||||||
|
#[Index(columns: ['node_id', 'file_path'], name: 'uniq_node_file', type: 'UNIQUE')]
|
||||||
|
class DebugLogPosition 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;
|
||||||
|
}
|
||||||
31
database/migrations/20260815100001_debug_log_position.php
Normal file
31
database/migrations/20260815100001_debug_log_position.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use think\migration\Migrator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试日志 - 文件读取位置表
|
||||||
|
*
|
||||||
|
* 记录每个 debug 日志文件的 inode/offset/最近读取时间/失败计数等增量读取状态。
|
||||||
|
* 唯一键 uniq_node_file(node_id, file_path):多节点导各自文件互不覆盖。
|
||||||
|
*/
|
||||||
|
class DebugLogPosition extends Migrator
|
||||||
|
{
|
||||||
|
public function change()
|
||||||
|
{
|
||||||
|
$table = $this->table('debug_log_position', ['id' => false, 'primary_key' => ['id']])
|
||||||
|
->setComment('调试日志文件读取位置(增量读取状态)')
|
||||||
|
->addColumn('id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
|
||||||
|
->addColumn('node_id', 'string', ['limit' => 64, 'null' => false, 'default' => '', 'comment' => '节点ID(区分不同采集节点)'])
|
||||||
|
->addColumn('file_path', 'string', ['limit' => 500, 'null' => false, 'comment' => '日志文件绝对路径'])
|
||||||
|
->addColumn('inode', 'biginteger', ['default' => 0, 'comment' => '文件 inode,用于检测日志轮转', 'signed' => false])
|
||||||
|
->addColumn('offset', 'biginteger', ['default' => 0, 'comment' => '上次读取到的字节偏移', 'signed' => false])
|
||||||
|
->addColumn('last_read_time', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '上次读取时间戳', 'signed' => false])
|
||||||
|
->addColumn('last_line_hash', 'string', ['limit' => 32, 'default' => '', 'comment' => '上次最后一行的 md5 哈希(容错校验)'])
|
||||||
|
->addColumn('parse_fail_count', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '解析失败累计次数', 'signed' => false])
|
||||||
|
->addColumn('parse_fail_samples', 'text', ['null' => true, 'comment' => '解析失败样本行(最多保留若干条)'])
|
||||||
|
->addColumn('create_time', 'integer', ['limit' => 11, 'comment' => '创建时间戳', 'signed' => false])
|
||||||
|
->addColumn('update_time', 'integer', ['limit' => 11, 'comment' => '更新时间戳', 'signed' => false])
|
||||||
|
->addIndex(['node_id', 'file_path'], ['unique' => true, 'name' => 'uniq_node_file'])
|
||||||
|
->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user