Skip to content

Commit

Permalink
keep hostname of logs consistent with metrics (#10)
Browse files Browse the repository at this point in the history
* keep hostname of logs consistent with metrics

* update description of bug report template (#2)
  • Loading branch information
kongfei605 authored Jun 10, 2022
1 parent 7263332 commit dcce864
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
10 changes: 5 additions & 5 deletions conf/logs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## key 占位符
api_key = "ef4ahfbwzwwtlwfpbertgq1i6mq0ab1q"
## 是否开启日志采集
enable = true
enable = false
## 接受日志的server地址
send_to = "127.0.0.1:17878"
## 发送日志的协议 http/tcp
Expand All @@ -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"
7 changes: 2 additions & 5 deletions logs/diagnostic/message_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 2 additions & 11 deletions logs/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package message

import (
"os"
"time"

coreconfig "flashcat.cloud/categraf/config"
logsconfig "flashcat.cloud/categraf/config/logs"
)

Expand Down Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion logs/pb/agent_logs_payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions logs/processor/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down

0 comments on commit dcce864

Please sign in to comment.