示例#1
0
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())
}
示例#2
0
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
}