本文整理匯總了Golang中github.com/mozilla-services/heka/pipeline.PluginHelper.Hostname方法的典型用法代碼示例。如果您正苦於以下問題:Golang PluginHelper.Hostname方法的具體用法?Golang PluginHelper.Hostname怎麽用?Golang PluginHelper.Hostname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/pipeline.PluginHelper
的用法示例。
在下文中一共展示了PluginHelper.Hostname方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (di *DockerLogInput) Run(ir pipeline.InputRunner, h pipeline.PluginHelper) error {
var (
pack *pipeline.PipelinePack
ok bool
)
hostname := h.Hostname()
go di.attachMgr.Listen(di.logstream, di.closer)
// Get the InputRunner's chan to receive empty PipelinePacks
packSupply := ir.InChan()
ok = true
var err error
for ok {
select {
case logline := <-di.logstream:
pack = <-packSupply
pack.Message.SetType("DockerLog")
pack.Message.SetLogger(logline.Type) // stderr or stdout
pack.Message.SetHostname(hostname) // Use the host's hosntame
pack.Message.SetPayload(logline.Data)
pack.Message.SetTimestamp(time.Now().UnixNano())
pack.Message.SetUuid(uuid.NewRandom())
for k, v := range logline.Fields {
message.NewStringField(pack.Message, k, v)
}
ir.Deliver(pack)
case err, ok = <-di.attachErrors:
if !ok {
err = errors.New("Docker event channel closed")
break
}
ir.LogError(fmt.Errorf("Attacher error: %s", err))
case err = <-di.stopChan:
ok = false
}
}
di.closer <- struct{}{}
close(di.logstream)
return err
}
示例2: Run
func (dei *DockerEventInput) Run(ir pipeline.InputRunner, h pipeline.PluginHelper) error {
defer dei.dockerClient.RemoveEventListener(dei.eventStream)
defer close(dei.eventStream)
var (
ok bool
err error
pack *pipeline.PipelinePack
)
hostname := h.Hostname()
// Provides empty PipelinePacks
packSupply := ir.InChan()
ok = true
for ok {
select {
case event := <-dei.eventStream:
pack = <-packSupply
pack.Message.SetType("DockerEvent")
pack.Message.SetLogger(event.ID)
pack.Message.SetHostname(hostname)
payload := fmt.Sprintf("id:%s status:%s from:%s time:%d", event.ID, event.Status, event.From, event.Time)
pack.Message.SetPayload(payload)
pack.Message.SetTimestamp(time.Now().UnixNano())
pack.Message.SetUuid(uuid.NewRandom())
message.NewStringField(pack.Message, "ID", event.ID)
message.NewStringField(pack.Message, "Status", event.Status)
message.NewStringField(pack.Message, "From", event.From)
message.NewInt64Field(pack.Message, "Time", event.Time, "ts")
ir.Deliver(pack)
case err = <-dei.stopChan:
ok = false
}
}
return err
}