mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-09-04 23:13:26 +08:00
feat(nginx-log): 新增 6 张表 phinx migration + Scheme + model
This commit is contained in:
44
database/migrations/20260726100002_nginx_access_log.php
Normal file
44
database/migrations/20260726100002_nginx_access_log.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
|
||||
/**
|
||||
* nginx 日志分析 - 原始访问日志表
|
||||
*
|
||||
* 解析 nginx access.log 后入库的明细数据,按行一条记录。
|
||||
* country/province/city 留作 GeoIP 扩展字段,默认 NULL。
|
||||
*/
|
||||
class NginxAccessLog extends Migrator
|
||||
{
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('nginx_access_log', ['id' => false, 'primary_key' => ['id']])
|
||||
->setComment('nginx 访问日志明细(解析入库)')
|
||||
->addColumn('id', 'biginteger', ['null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
|
||||
->addColumn('file_path', 'string', ['limit' => 500, 'null' => false, 'comment' => '来源日志文件路径'])
|
||||
->addColumn('remote_addr', 'string', ['limit' => 45, 'null' => false, 'comment' => '客户端 IP(含 IPv6)'])
|
||||
->addColumn('remote_user', 'string', ['limit' => 100, 'null' => true, 'comment' => 'HTTP 认证用户名'])
|
||||
->addColumn('time_local', 'integer', ['limit' => 11, 'null' => false, 'comment' => '请求时间戳(业务时区)', 'signed' => false])
|
||||
->addColumn('method', 'string', ['limit' => 10, 'null' => true, 'comment' => 'HTTP 方法'])
|
||||
->addColumn('uri', 'string', ['limit' => 255, 'null' => false, 'comment' => '请求 URI(超 255 截断)'])
|
||||
->addColumn('query_string', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => '查询字符串'])
|
||||
->addColumn('http_version', 'string', ['limit' => 10, 'null' => true, 'comment' => 'HTTP 协议版本'])
|
||||
->addColumn('status', 'integer', ['limit' => 11, 'default' => 0, 'comment' => 'HTTP 状态码'])
|
||||
->addColumn('body_bytes_sent', 'biginteger', ['default' => 0, 'comment' => '响应体字节数'])
|
||||
->addColumn('http_referer', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => 'Referer'])
|
||||
->addColumn('http_user_agent', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => 'User-Agent(超 500 截断)'])
|
||||
->addColumn('request_time', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => 0, 'comment' => 'nginx 请求总耗时(秒)'])
|
||||
->addColumn('upstream_response_time', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => 0, 'comment' => 'upstream 响应时间(秒)'])
|
||||
->addColumn('bytes_sent', 'biginteger', ['default' => 0, 'comment' => '总发送字节数(含 header)'])
|
||||
->addColumn('country', 'string', ['limit' => 50, 'null' => true, 'comment' => '国家(GeoIP 预留)'])
|
||||
->addColumn('province', 'string', ['limit' => 50, 'null' => true, 'comment' => '省份(GeoIP 预留)'])
|
||||
->addColumn('city', 'string', ['limit' => 50, 'null' => true, 'comment' => '城市(GeoIP 预留)'])
|
||||
->addColumn('create_time', 'integer', ['limit' => 11, 'comment' => '入库时间戳', 'signed' => false])
|
||||
->addIndex(['time_local'], ['name' => 'idx_time_local'])
|
||||
->addIndex(['remote_addr'], ['name' => 'idx_remote_addr'])
|
||||
->addIndex(['status'], ['name' => 'idx_status'])
|
||||
->addIndex(['uri'], ['name' => 'idx_uri'])
|
||||
->addIndex(['file_path'], ['name' => 'idx_file_path'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user