49 lines
989 B
Go
49 lines
989 B
Go
|
package taillog
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"logagent/etcd"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var tskMgr *tailLogMgr
|
||
|
|
||
|
//tailTask管理者
|
||
|
|
||
|
type tailLogMgr struct {
|
||
|
logEntry []*etcd.LogEntry
|
||
|
tskMap map[string]*TailTask
|
||
|
newConfChan chan []*etcd.LogEntry
|
||
|
}
|
||
|
|
||
|
func Init(logEntryConf []*etcd.LogEntry) {
|
||
|
tskMgr = &tailLogMgr{
|
||
|
logEntry: logEntryConf, //把当前的日志收集项信息保存起来
|
||
|
tskMap: make(map[string]*TailTask, 32),
|
||
|
newConfChan: make(chan []*etcd.LogEntry), //无缓冲区的通道
|
||
|
}
|
||
|
for _, logEntry := range logEntryConf {
|
||
|
//logEntry: *etcd.LogEntry
|
||
|
//要收集的日志文件的路径
|
||
|
NewTailTask(logEntry.Path, logEntry.Topic)
|
||
|
|
||
|
}
|
||
|
go tskMgr.run()
|
||
|
}
|
||
|
|
||
|
// 监听自己的newConfChan 有了新的配置过来就做对应的除了
|
||
|
|
||
|
func (t *tailLogMgr) run() {
|
||
|
for {
|
||
|
select {
|
||
|
case newConf := <-t.newConfChan:
|
||
|
// 1.配置新增
|
||
|
// 2.配置删除
|
||
|
// 3.配置变更
|
||
|
fmt.Printf("新的配置来了%v\n", newConf)
|
||
|
default:
|
||
|
time.Sleep(time.Second)
|
||
|
}
|
||
|
}
|
||
|
}
|