diff --git a/conf/logs.toml b/conf/logs.toml index 593226df..606fd938 100644 --- a/conf/logs.toml +++ b/conf/logs.toml @@ -2,7 +2,7 @@ ## key 占位符 api_key = "ef4ahfbwzwwtlwfpbertgq1i6mq0ab1q" ## 是否开启日志采集 -enable = true +enable = false ## 接受日志的server地址 send_to = "127.0.0.1:17878" ## 发送日志的协议 http/tcp @@ -19,17 +19,17 @@ run_path = "/opt/categraf/run" open_files_limit = 100 ## 定期扫描目录下是否有新增日志 scan_period = 10 -## -frame_size = 10 +## udp 读buffer的大小 +frame_size = 9000 ## collect_container_all = true ## 全局的处理规则 [[logs.Processing_rules]] ## 单个日志采集配置 [[logs.items]] - ## file/journald + ## file/journald/tcp/udp type = "file" - ## type=file时 path必填,type=journald时 port必填 + ## type=file时 path必填,type=journald/tcp/udp时 port必填 path = "/opt/tomcat/logs/*.txt" source = "tomcat" service = "my_service" diff --git a/logs/diagnostic/message_receiver.go b/logs/diagnostic/message_receiver.go index 067b7434..73f60d69 100644 --- a/logs/diagnostic/message_receiver.go +++ b/logs/diagnostic/message_receiver.go @@ -7,10 +7,10 @@ package diagnostic import ( "fmt" - "os" "sync" "time" + coreconfig "flashcat.cloud/categraf/config" logsconfig "flashcat.cloud/categraf/config/logs" "flashcat.cloud/categraf/logs/message" ) @@ -137,10 +137,7 @@ func shouldHandleMessage(m *message.Message, filters *Filters) bool { } func formatMessage(m *message.Message, redactedMsg []byte) string { - hostname, err := os.Hostname() - if err != nil { - hostname = "unknown" - } + hostname := coreconfig.Config.GetHostname() ts := time.Now().UTC() if !m.Timestamp.IsZero() { diff --git a/logs/message/message.go b/logs/message/message.go index a2121245..17a17181 100644 --- a/logs/message/message.go +++ b/logs/message/message.go @@ -6,9 +6,9 @@ package message import ( - "os" "time" + coreconfig "flashcat.cloud/categraf/config" logsconfig "flashcat.cloud/categraf/config/logs" ) @@ -78,14 +78,5 @@ func (m *Message) GetLatency() int64 { // GetHostname returns the hostname to applied the given log message func (m *Message) GetHostname() string { - if m.Lambda != nil { - return m.Lambda.ARN - } - hostname, err := os.Hostname() - if err != nil { - // this scenario is not likely to happen since - // the agent cannot start without a hostname - hostname = "unknown" - } - return hostname + return coreconfig.Config.GetHostname() } diff --git a/logs/pb/agent_logs_payload.pb.go b/logs/pb/agent_logs_payload.pb.go index 8d2e9bdd..f4e3c8f2 100644 --- a/logs/pb/agent_logs_payload.pb.go +++ b/logs/pb/agent_logs_payload.pb.go @@ -34,7 +34,7 @@ type Log struct { Status string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // from host - Hostname string `protobuf:"bytes,4,opt,name=hostname,proto3" json:"hostname,omitempty"` + Hostname string `protobuf:"bytes,4,opt,name=agent_hostname,proto3" json:"hostname,omitempty"` // from config Service string `protobuf:"bytes,5,opt,name=service,proto3" json:"service,omitempty"` Source string `protobuf:"bytes,6,opt,name=source,proto3" json:"source,omitempty"` diff --git a/logs/processor/json.go b/logs/processor/json.go index bdc2d1c4..551d83f7 100644 --- a/logs/processor/json.go +++ b/logs/processor/json.go @@ -25,8 +25,8 @@ type jsonPayload struct { Message string `json:"message"` Status string `json:"status"` Timestamp int64 `json:"timestamp"` - Hostname string `json:"hostname"` - Service string `json:"service"` + Hostname string `json:"agent_hostname"` + Service string `json:"fcservice"` Source string `json:"fcsource"` Tags string `json:"fctags"` }