一个将日志收集发送到kafka的程序

main
Your Name 2024-09-14 21:11:05 +08:00
parent bbb93ac5cb
commit a418787e0b
4 changed files with 4 additions and 4 deletions

View File

@ -54,7 +54,7 @@ func sendToKafka() {
if err != nil { if err != nil {
fmt.Println("send message err:", err) fmt.Println("send message err:", err)
} }
fmt.Printf("pid:%v offset:%v\n", pid, offset) fmt.Printf("pid:%v offset:%v text:%v\n", pid, offset, msg.Value)
default: default:
time.Sleep(time.Millisecond * 50) time.Sleep(time.Millisecond * 50)
} }

View File

@ -20,7 +20,7 @@ func main() {
// put // put
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
value := `[{"path":"c:/tmp/nginx.log","topic":"web_log"},{"path":"d:/xxx/redis.log","topic":"redis_log"}]` value := `[{"path":"c:/tmp/nginx.log","topic":"web_log"},{"path":"d:/xxx/redis.log","topic":"redis_log"}]`
_, err = cli.Put(ctx, "/logagent/collect_log_config", value) _, err = cli.Put(ctx, "/logagent/192.168.0.104/collect_log_config", value)
cancel() cancel()
if err != nil { if err != nil {
fmt.Println("put to etcd failed,error:", err) fmt.Println("put to etcd failed,error:", err)

View File

@ -20,7 +20,7 @@ func main() {
// put // put
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
value := `[{"path":"c:/tmp/nginx.log","topic":"web_log"},{"path":"d:/xxx/redis.log","topic":"redis_log"},{"path":"d:/xxx/mysql.log","topic":"mysql_log"}]` value := `[{"path":"c:/tmp/nginx.log","topic":"web_log"},{"path":"d:/xxx/redis.log","topic":"redis_log"},{"path":"d:/xxx/mysql.log","topic":"mysql_log"}]`
_, err = cli.Put(ctx, "/logagent/collect_log_config", value) _, err = cli.Put(ctx, "/logagent/192.168.0.104/collect_log_config", value)
cancel() cancel()
if err != nil { if err != nil {
fmt.Println("put to etcd failed,error:", err) fmt.Println("put to etcd failed,error:", err)

View File

@ -61,7 +61,7 @@ func (t *TailTask) run() {
fmt.Printf("tail task:%v exit\n", t.path+t.topic) fmt.Printf("tail task:%v exit\n", t.path+t.topic)
return return
case line := <-t.ReadChan(): case line := <-t.ReadChan():
fmt.Printf("日志已发送kafkatext,%v\n", line.Text) fmt.Printf("日志已发送channeltext%v\n", line.Text)
//kafka.SendToKafka(t.topic, line.Text) //函数调用函数 //kafka.SendToKafka(t.topic, line.Text) //函数调用函数
//先把日志发送到一个通道中 //先把日志发送到一个通道中
kafka.SendToChan(t.topic, line.Text) kafka.SendToChan(t.topic, line.Text)