keep hostname of logs consistent with metrics (#10)

* keep hostname of logs consistent with metrics

* update description of bug report template (#2)
This commit is contained in:
kongfei605 2022-06-10 08:47:04 +08:00 committed by GitHub
parent 7263332b1c
commit dcce8640af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 24 deletions

View File

@ -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"

View File

@ -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() {

View File

@ -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()
}

View File

@ -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"`

View File

@ -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"`
}