一个将日志收集发送到kafka的程序
parent
bbb93ac5cb
commit
a418787e0b
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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("日志已发送kafka,text:,%v\n", line.Text)
|
fmt.Printf("日志已发送channel,text:%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)
|
||||||
|
|
Loading…
Reference in New Issue