func (this *NetReceiverInput) handleTcpConnection(conn net.Conn, r engine.InputRunner) { var ( lineReader = bufio.NewReader(conn) line string err error pack *engine.PipelinePack ok bool inChan = r.InChan() globals = engine.Globals() ) globals.Printf("Connection from %s", conn.RemoteAddr()) for { line, err = lineReader.ReadString('\n') if err != nil { globals.Printf("[%s]%s", conn.RemoteAddr(), err) continue } atomic.AddInt64(&this.totalBytes, int64(len(line))) atomic.AddInt64(&this.periodBytes, int64(len(line))) pack, ok = <-inChan if !ok { break } // TODO marshal the pack from line r.Inject(pack) } globals.Printf("Closed connection from %s", conn.RemoteAddr().String()) }
func (this *NetReceiverInput) reportStats(r engine.InputRunner) { globals := engine.Globals() for _ = range r.Ticker() { globals.Printf("Total %s, speed: %s/s", gofmt.ByteSize(this.totalBytes), gofmt.ByteSize(this.periodBytes)) this.periodBytes = int64(0) } }
func (this *SelfSysInput) Run(r engine.InputRunner, h engine.PluginHelper) error { var ( stopped = false ) for !stopped { select { case <-this.stopChan: stopped = true case <-r.Ticker(): // same effect as sleep } } return nil }
func (this *SelfSysInput) Run(r engine.InputRunner, h engine.PluginHelper) error { var ( globals = engine.Globals() stats = newSysStat() inChan = r.InChan() pack *engine.PipelinePack jsonString string err error stopped = false ) for !stopped { select { case <-this.stopChan: stopped = true case <-r.Ticker(): // same effect as sleep } if stopped { break } stats.gatherStats() jsonString, err = stats.jsonString() if err != nil { globals.Println(err) continue } pack = <-inChan if err = pack.Message.FromLine(fmt.Sprintf("als,%d,%s", time.Now().Unix(), jsonString)); err != nil { globals.Printf("invalid sys stat: %s\n", jsonString) pack.Recycle() continue } pack.Project = "als" pack.Ident = this.ident pack.EsIndex = "fun_als" pack.EsType = "sys" r.Inject(pack) } return nil }
func (this *ArchiveInput) Run(r engine.InputRunner, h engine.PluginHelper) error { this.runner = r this.h = h this.chkpnt.Load() go func() { for !this.stopping { select { case <-r.Ticker(): this.chkpnt.Dump() if this.leftN > 0 { engine.Globals().Printf("[%s]Left %d files", r.Name(), this.leftN) } } } }() this.workersWg = new(sync.WaitGroup) filepath.Walk(this.rootDir, this.setLeftN) globals := engine.Globals() if globals.Verbose { globals.Printf("Total files:%d", this.leftN) } // do the real job filepath.Walk(this.rootDir, this.runSingleLogfile) // wait for all workers done this.workersWg.Wait() this.chkpnt.Dump() if globals.Verbose { globals.Printf("[%s]Total msg: %d", r.Name(), this.lineN) } return nil }