Пример #1
0
func newLumberjackClient(
	conn *transport.Client,
	compressLevel int,
	maxWindowSize int,
	timeout time.Duration,
	beat string,
) (*client, error) {
	c := &client{}
	c.Client = conn
	c.win.init(defaultStartMaxWindowSize, maxWindowSize)

	enc, err := makeLogstashEventEncoder(beat)
	if err != nil {
		return nil, err
	}

	cl, err := v2.NewSyncClientWithConn(conn,
		v2.JSONEncoder(enc),
		v2.Timeout(timeout),
		v2.CompressionLevel(compressLevel))
	if err != nil {
		return nil, err
	}

	c.client = cl
	return c, nil
}
Пример #2
0
func newAsyncLumberjackClient(
	conn *transport.Client,
	queueSize int,
	compressLevel int,
	maxWindowSize int,
	timeout time.Duration,
	beat string,
) (*asyncClient, error) {
	c := &asyncClient{}
	c.Client = conn
	c.win.init(defaultStartMaxWindowSize, maxWindowSize)

	enc, err := makeLogstashEventEncoder(beat)
	if err != nil {
		return nil, err
	}

	c.connect = func() error {
		err := c.Client.Connect()
		if err == nil {
			c.client, err = v2.NewAsyncClientWithConn(c.Client,
				queueSize,
				v2.JSONEncoder(enc),
				v2.Timeout(timeout),
				v2.CompressionLevel(compressLevel))
		}
		return err
	}
	return c, nil
}
Пример #3
0
func main() {
	connect := flag.String("c", "localhost:5044", "Remote address")
	compress := flag.Int("compress", 3, "Compression level (0-9)")
	timeout := flag.Duration("timeout", 30*time.Second, "Connection timeouts")
	batchSize := flag.Int("batch", 2048, "Batch size")
	pipelined := flag.Int("pipeline", 0, "enabled pipeline mode with number of batches kept in pipeline")
	httpprof := flag.String("httpprof", ":6060", "HTTP profiling server address")
	flag.Parse()

	stat := expvar.NewInt("ACKed")

	batch := make([]interface{}, *batchSize)
	for i := range batch {
		batch[i] = makeEvent()
	}
	L := int64(len(batch))

	go func() {
		log.Printf("Listening: %v\n", *httpprof)
		http.ListenAndServe(*httpprof, nil)
	}()

	log.Printf("connect to: %v", *connect)
	if *pipelined == 0 {
		cl, err := v2.SyncDial(*connect,
			v2.CompressionLevel(*compress),
			v2.Timeout(*timeout))
		if err != nil {
			log.Println(err)
			os.Exit(1)
		}

		for {
			_, err := cl.Send(batch)
			if err != nil {
				log.Println(err)
				return
			}

			stat.Add(L)
		}
	} else {
		cl, err := v2.AsyncDial(*connect,
			*pipelined,
			v2.CompressionLevel(*compress),
			v2.Timeout(*timeout))
		if err != nil {
			log.Println(err)
			os.Exit(1)
		}

		for {
			cb := func(_ uint32, err error) {
				if err != nil {
					log.Println(err)
					return
				}

				stat.Add(L)
			}

			err := cl.Send(cb, batch)
			if err != nil {
				log.Println(err)
				return
			}
		}
	}
}