// Configure initializes this producer with values from a plugin config. func (prod *Scribe) Configure(conf core.PluginConfig) error { err := prod.ProducerBase.Configure(conf) if err != nil { return err } host := conf.GetString("Address", "localhost:1463") bufferSizeMax := conf.GetInt("BatchSizeMaxKB", 8<<10) << 1 // 8 MB prod.category = make(map[core.MessageStreamID]string, 0) prod.batchSize = conf.GetInt("BatchSizeByte", 8192) prod.batchTimeout = time.Duration(conf.GetInt("BatchTimeoutSec", 5)) * time.Second prod.batch = createScribeMessageBatch(bufferSizeMax) prod.bufferSizeKB = conf.GetInt("ConnectionBufferSizeKB", 1<<10) // 1 MB prod.category = conf.GetStreamMap("Category", "") // Initialize scribe connection prod.socket, err = thrift.NewTSocket(host) if err != nil { Log.Error.Print("Scribe socket error:", err) return err } prod.transport = thrift.NewTFramedTransport(prod.socket) binProtocol := thrift.NewTBinaryProtocol(prod.transport, false, false) prod.scribe = scribe.NewScribeClientProtocol(prod.transport, binProtocol, binProtocol) return nil }
// Configure initializes this producer with values from a plugin config. func (prod *Scribe) Configure(conf core.PluginConfig) error { err := prod.ProducerBase.Configure(conf) if err != nil { return err } prod.SetStopCallback(prod.close) host := conf.GetString("Address", "localhost:1463") prod.batchMaxCount = conf.GetInt("BatchMaxCount", 8192) prod.windowSize = prod.batchMaxCount prod.batchFlushCount = conf.GetInt("BatchFlushCount", prod.batchMaxCount/2) prod.batchFlushCount = shared.MinI(prod.batchFlushCount, prod.batchMaxCount) prod.batchTimeout = time.Duration(conf.GetInt("BatchTimeoutSec", 5)) * time.Second prod.batch = core.NewMessageBatch(prod.batchMaxCount) prod.bufferSizeByte = conf.GetInt("ConnectionBufferSizeKB", 1<<10) << 10 // 1 MB prod.category = conf.GetStreamMap("Category", "") // Initialize scribe connection prod.socket, err = thrift.NewTSocket(host) if err != nil { Log.Error.Print("Scribe socket error:", err) return err } prod.transport = thrift.NewTFramedTransport(prod.socket) binProtocol := thrift.NewTBinaryProtocol(prod.transport, false, false) prod.scribe = scribe.NewScribeClientProtocol(prod.transport, binProtocol, binProtocol) prod.lastMetricUpdate = time.Now() prod.counters = make(map[string]*int64) shared.Metric.New(scribeMetricWindowSize) shared.Metric.SetI(scribeMetricWindowSize, prod.windowSize) for _, category := range prod.category { shared.Metric.New(scribeMetricMessages + category) shared.Metric.New(scribeMetricMessagesSec + category) prod.counters[category] = new(int64) } prod.SetCheckFuseCallback(prod.tryOpenConnection) return nil }
func WriteScribe(category string, message string) { // currently available on linux platform if runtime.GOOS != "linux" { Log(category + " : " + message) return } entry := scribe.NewLogEntry() entry.Category = category entry.Message = message messages := []*scribe.LogEntry{entry} socket, err := thrift.NewTSocket("localhost:1463") CheckError(err) transport := thrift.NewTFramedTransport(socket) protocol := thrift.NewTBinaryProtocol(transport, false, false) client := scribe.NewScribeClientProtocol(transport, protocol, protocol) transport.Open() result, err := client.Log(messages) CheckError(err) transport.Close() Log(result.String()) }