引入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

@@ -3,13 +3,18 @@
package db
import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/actions"
"strings"
)
const clickhouseConfigCode = "clickhouseConfig"
@@ -29,29 +34,37 @@ func (this *ClickHouseAction) RunGet(params struct{}) {
this.ErrorPage(err)
return
}
cfg := &systemconfigs.ClickHouseSetting{Port: 8123, Database: "default", Scheme: "http"}
cfg := &systemconfigs.ClickHouseSetting{Port: 8443, Database: "default", Scheme: "https"}
if len(resp.ValueJSON) > 0 {
_ = json.Unmarshal(resp.ValueJSON, cfg)
}
if cfg.Port <= 0 {
cfg.Port = 8123
cfg.Port = 8443
}
if cfg.Database == "" {
cfg.Database = "default"
}
if strings.TrimSpace(cfg.Scheme) == "" {
cfg.Scheme = "http"
cfg.Scheme = "https"
}
this.Data["config"] = map[string]interface{}{
"host": cfg.Host,
"port": cfg.Port,
"user": cfg.User,
"password": cfg.Password,
"database": cfg.Database,
"scheme": cfg.Scheme,
"tlsSkipVerify": cfg.TLSSkipVerify,
"tlsServerName": cfg.TLSServerName,
"host": cfg.Host,
"port": cfg.Port,
"user": cfg.User,
"password": cfg.Password,
"database": cfg.Database,
"scheme": cfg.Scheme,
}
// 自动检测连接状态
connStatus := "unconfigured" // unconfigured / connected / disconnected
connError := ""
if strings.TrimSpace(cfg.Host) != "" {
connStatus, connError = this.probeClickHouse(cfg)
}
this.Data["connStatus"] = connStatus
this.Data["connError"] = connError
this.Show()
}
@@ -62,20 +75,18 @@ func (this *ClickHouseAction) RunPost(params struct {
Password string
Database string
Scheme string
TLSSkipVerify bool
TLSServerName string
Must *actions.Must
}) {
defer this.CreateLogInfo(codes.DBNode_LogUpdateDBNode, 0)
if params.Port <= 0 {
params.Port = 8123
}
if params.Database == "" {
params.Database = "default"
}
if params.Scheme != "https" {
params.Scheme = "http"
if params.Scheme != "http" {
params.Scheme = "https"
}
if params.Port <= 0 {
params.Port = 8443
}
password := params.Password
if password == "" {
@@ -94,8 +105,8 @@ func (this *ClickHouseAction) RunPost(params struct {
Password: password,
Database: params.Database,
Scheme: params.Scheme,
TLSSkipVerify: params.TLSSkipVerify,
TLSServerName: strings.TrimSpace(params.TLSServerName),
TLSSkipVerify: true,
TLSServerName: "",
}
valueJSON, err := json.Marshal(cfg)
if err != nil {
@@ -112,3 +123,51 @@ func (this *ClickHouseAction) RunPost(params struct {
}
this.Success()
}
// probeClickHouse 快速检测 ClickHouse 连接状态SELECT 1
func (this *ClickHouseAction) probeClickHouse(cfg *systemconfigs.ClickHouseSetting) (status string, errMsg string) {
scheme := strings.ToLower(strings.TrimSpace(cfg.Scheme))
if scheme == "" {
scheme = "https"
}
port := cfg.Port
if port <= 0 {
port = 8443
}
db := cfg.Database
if db == "" {
db = "default"
}
testURL := fmt.Sprintf("%s://%s:%d/?query=SELECT+1&database=%s", scheme, cfg.Host, port, db)
transport := &http.Transport{}
if scheme == "https" {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
client := &http.Client{
Timeout: 3 * time.Second,
Transport: transport,
}
req, err := http.NewRequest(http.MethodGet, testURL, nil)
if err != nil {
return "disconnected", err.Error()
}
if cfg.User != "" || cfg.Password != "" {
req.SetBasicAuth(cfg.User, cfg.Password)
}
resp, err := client.Do(req)
if err != nil {
return "disconnected", err.Error()
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "disconnected", fmt.Sprintf("HTTP %d", resp.StatusCode)
}
return "connected", ""
}