引入lumberjack和fluentbit自动分发

This commit is contained in:
robin
2026-02-13 22:36:17 +08:00
parent c6da67db79
commit e9093baffb
47 changed files with 4589 additions and 317 deletions

View File

@@ -1,70 +1,76 @@
{$layout}
{$template "menu"}
<h3>ClickHouse 配置</h3>
<p class="comment">用于访问日志列表查询logs_ingest 表)。配置后,访问日志列表将优先从 ClickHouse 读取;不配置则仅从 MySQL 读取。留空表示不使用 ClickHouse。</p>
<div style="display:flex;align-items:baseline;gap:0.8em;margin-bottom:0.5em">
<h3 style="margin:0">ClickHouse 配置</h3>
<span v-if="connStatus === 'connected'" class="ui label green tiny" style="vertical-align:baseline">
<i class="icon circle" style="margin-right:0.25em"></i>已连接
</span>
<span v-else-if="connStatus === 'disconnected'" class="ui label red tiny" style="vertical-align:baseline"
:title="connError">
<i class="icon circle" style="margin-right:0.25em"></i>已断开
</span>
<span v-else class="ui label grey tiny" style="vertical-align:baseline">
<i class="icon circle outline" style="margin-right:0.25em"></i>未配置
</span>
</div>
<p class="comment">配置后,需要在网站列表-日志策略中创建"文件+ClickHouse"的策略才能将访问日志绕过api组件直接由边缘节点发送给ClickHouse。</p>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success" @submit.prevent="onSubmit">
<form method="post" class="ui form" @submit.prevent="onSubmit">
<csrf-token></csrf-token>
<table class="ui table definition selectable">
<tr>
<td class="title">连接地址Host</td>
<td>
<input type="text" name="host" maxlength="200" ref="focus" placeholder="如 127.0.0.1 或 clickhouse.example.com" :value="config.host"/>
<input type="text" name="host" maxlength="200" ref="focus"
placeholder="如 127.0.0.1 或 clickhouse.example.com" v-model="form.host" />
<p class="comment">ClickHouse 服务器地址。</p>
</td>
</tr>
<tr>
<td>协议Scheme</td>
<td>
<select name="scheme" class="ui dropdown auto-width">
<option value="http" :selected="config.scheme != 'https'">HTTP</option>
<option value="https" :selected="config.scheme == 'https'">HTTPS</option>
<select name="scheme" class="ui dropdown auto-width" v-model="form.scheme">
<option value="http">HTTP</option>
<option value="https">HTTPS</option>
</select>
<p class="comment">默认 HTTP;选择 HTTPS 时将启用 TLS 连接</p>
<p class="comment">默认 HTTPS当前后台固定跳过证书校验</p>
</td>
</tr>
<tr>
<td>端口Port</td>
<td>
<input type="number" name="port" min="1" max="65535" style="width:6em" :value="config.port"/>
<p class="comment">接口端口HTTP 默认 8123HTTPS 常用 8443以你的 ClickHouse 实际配置为准)</p>
<input type="number" name="port" min="1" max="65535" style="width:6em" v-model.number="form.port" />
<p class="comment">接口端口默认 8443HTTPS请与 ClickHouse 实际开放端口保持一致</p>
</td>
</tr>
<tr>
<td>用户名User</td>
<td>
<input type="text" name="user" maxlength="100" :value="config.user"/>
<input type="text" name="user" maxlength="100" v-model="form.user" />
</td>
</tr>
<tr>
<td>密码Password</td>
<td>
<input type="password" name="password" maxlength="200" placeholder="不修改请留空" value=""/>
<input type="password" name="password" maxlength="200" placeholder="不修改请留空" v-model="form.password" />
<p class="comment">留空则不修改已保存的密码。</p>
</td>
</tr>
<tr>
<td>TLS 跳过证书校验</td>
<td>
<checkbox name="tlsSkipVerify" value="1" :checked="config.tlsSkipVerify"></checkbox>
<p class="comment">仅测试环境建议开启;生产建议关闭并使用受信任证书。</p>
</td>
</tr>
<tr>
<td>TLS Server Name</td>
<td>
<input type="text" name="tlsServerName" maxlength="200" placeholder="可选证书校验域名SNI" :value="config.tlsServerName"/>
<p class="comment">可选;当 ClickHouse 证书域名与连接 Host 不一致时使用。</p>
</td>
</tr>
<tr>
<td>数据库名Database</td>
<td>
<input type="text" name="database" maxlength="100" placeholder="default" :value="config.database"/>
<input type="text" name="database" maxlength="100" placeholder="default" v-model="form.database" />
<p class="comment">logs_ingest 表所在库,默认 default。</p>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>
<div style="display:flex; align-items:center; gap:0.5em; margin-top:1em">
<submit-btn></submit-btn>
<button type="button" class="ui button basic blue" @click="testConnection" :disabled="isTesting">
<i :class="isTesting ? 'icon spinner loading' : 'icon plug'"></i> 测试连接
</button>
<span v-if="testResult"
:style="{color: testOk ? '#21ba45' : '#db2828', fontWeight:'bold'}">{{testResult}}</span>
</div>
</form>

View File

@@ -1,4 +1,22 @@
Tea.context(function () {
var config = this.config || {}
this.form = {
host: config.host || "",
scheme: config.scheme || "https",
port: config.port > 0 ? config.port : 8443,
user: config.user || "",
password: "",
database: config.database || "default",
}
this.isTesting = false
this.testResult = ""
this.testOk = false
// 页面加载时的连接状态(后端自动检测)
this.connStatus = this.connStatus || "unconfigured"
this.connError = this.connError || ""
this.success = function () {
teaweb.success("保存成功")
}
@@ -9,4 +27,50 @@ Tea.context(function () {
Tea.Vue.success()
})
}
this.testConnection = function () {
var that = Tea.Vue
that.isTesting = true
that.testResult = ""
var form = document.querySelector("form")
var fd = new FormData(form)
fd.set("host", that.form.host || "")
fd.set("scheme", that.form.scheme || "https")
fd.set("port", String(that.form.port > 0 ? that.form.port : 8443))
fd.set("user", that.form.user || "")
fd.set("password", that.form.password || "")
fd.set("database", that.form.database || "default")
var xhr = new XMLHttpRequest()
xhr.open("POST", Tea.url("/db/testClickhouse"), true)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
xhr.timeout = 10000
xhr.onload = function () {
that.isTesting = false
try {
var resp = JSON.parse(xhr.responseText)
if (resp.code === 200) {
that.testOk = true
that.testResult = "✅ 连接成功"
} else {
that.testOk = false
that.testResult = "❌ " + (resp.message || "连接失败")
}
} catch (e) {
that.testOk = false
that.testResult = "❌ 响应解析失败"
}
}
xhr.onerror = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 网络请求失败"
}
xhr.ontimeout = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 请求超时"
}
xhr.send(fd)
}
})