Score
0
Watch 10 Star 31 Fork 5

qieangel2013 / goMonitorLogGo

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
基于Aho-Corasick 算法+Trie树+DFA 来实现实时匹配,可以实时对文本过滤+字符过滤+敏感词过滤+关键词过滤+脏词过滤+多字符串匹配等处理 支持所有的文本文件类型(包括所有日志) spread retract

Clone or download
main.go 2.17 KB
Copy Edit Web IDE Raw Blame History
qieangel2013 authored 2019-11-11 11:36 . 修复bug
package main
import (
"flag"
"github.com/hpcloud/tail"
"julive.com/handle"
"log"
"strings"
"time"
)
var configFile = flag.String("config", "./etc/log.toml", "log config file")
var currentDaysTime string
var currentHoursTime string
var hoursFile []string
var daysFile []string
func main() {
currentDaysTime = time.Now().Format("2006-01-02")
currentHoursTime = time.Now().Format("2006-01-02_01")
// 创建一个接受匹配上的字符串管道
var MonitorChan = make(chan handle.MonitorChan, 10)
TailDaysPointer := make(chan *tail.Tail, 10)
TailHoursPointer := make(chan *tail.Tail, 10)
FailPointer := make(chan handle.FileChan, 10)
cfg, err := handle.NewConfigWithFile(*configFile)
if err != nil {
log.Println("error:", err)
return
}
handle.LogStart(cfg)
go handle.BuildDicTrie(cfg)
for _, file := range cfg.LogList {
if strings.Contains(file, "$todayhourstr") {
hoursFile = append(hoursFile, file)
} else {
daysFile = append(daysFile, file)
}
}
go handle.AddToDaysMonitor(daysFile, cfg, MonitorChan, TailDaysPointer, FailPointer)
if len(hoursFile) != 0 {
go handle.AddToHoursMonitor(hoursFile, cfg, MonitorChan, TailHoursPointer, FailPointer)
}
go func() {
for {
select {
//读取sqldata
case data := <-MonitorChan:
go func() {
handle.DingToInfo(&data, cfg)
}()
}
}
}()
timerActive := time.NewTimer(600 * time.Second)
for {
select {
case <-timerActive.C:
if len(hoursFile) != 0 {
timerCurrentHoursTime := time.Now().Format("2006-01-02_01")
if timerCurrentHoursTime != currentHoursTime {
if handle.CloseMonitor(TailHoursPointer) {
currentHoursTime = timerCurrentHoursTime
go handle.AddToHoursMonitor(hoursFile, cfg, MonitorChan, TailHoursPointer, FailPointer)
}
}
}
timerCurrentTime := time.Now().Format("2006-01-02")
if timerCurrentTime != currentDaysTime {
if handle.CloseMonitor(TailDaysPointer) {
currentDaysTime = timerCurrentTime
go handle.AddToDaysMonitor(daysFile, cfg, MonitorChan, TailDaysPointer, FailPointer)
}
}
go handle.ExcuteFailFile(cfg, MonitorChan, TailHoursPointer, TailDaysPointer, FailPointer)
timerActive.Reset(600 * time.Second)
}
}
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/qieangel2013/goMonitorLog.git
git@gitee.com:qieangel2013/goMonitorLog.git
qieangel2013
goMonitorLog
goMonitorLog
master

Help Search