本文整理匯總了Golang中github.com/elastic/libbeat/outputs.MothershipConfig.Protocol方法的典型用法代碼示例。如果您正苦於以下問題:Golang MothershipConfig.Protocol方法的具體用法?Golang MothershipConfig.Protocol怎麽用?Golang MothershipConfig.Protocol使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elastic/libbeat/outputs.MothershipConfig
的用法示例。
在下文中一共展示了MothershipConfig.Protocol方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Init
// Initialize Elasticsearch as output
func (out *ElasticsearchOutput) Init(config outputs.MothershipConfig, topology_expire int) error {
if len(config.Protocol) == 0 {
config.Protocol = "http"
}
url := fmt.Sprintf("%s://%s:%d%s", config.Protocol, config.Host, config.Port, config.Path)
con := NewElasticsearch(url, config.Username, config.Password)
out.Conn = con
if config.Index != "" {
out.Index = config.Index
} else {
out.Index = "packetbeat"
}
out.TopologyExpire = 15000
if topology_expire != 0 {
out.TopologyExpire = topology_expire /*sec*/ * 1000 // millisec
}
out.FlushInterval = 1000 * time.Millisecond
if config.Flush_interval != nil {
out.FlushInterval = time.Duration(*config.Flush_interval) * time.Millisecond
}
out.BulkMaxSize = 10000
if config.Bulk_size != nil {
out.BulkMaxSize = *config.Bulk_size
}
err := out.EnableTTL()
if err != nil {
logp.Err("Fail to set _ttl mapping: %s", err)
return err
}
out.sendingQueue = make(chan BulkMsg, 1000)
go out.SendMessagesGoroutine()
logp.Info("[ElasticsearchOutput] Using Elasticsearch %s", url)
logp.Info("[ElasticsearchOutput] Using index pattern [%s-]YYYY.MM.DD", out.Index)
logp.Info("[ElasticsearchOutput] Topology expires after %ds", out.TopologyExpire/1000)
if out.FlushInterval > 0 {
logp.Info("[ElasticsearchOutput] Insert events in batches. Flush interval is %s. Bulk size is %d.", out.FlushInterval, out.BulkMaxSize)
} else {
logp.Info("[ElasticsearchOutput] Insert events one by one. This might affect the performance of the shipper.")
}
return nil
}
示例2: Init
// Initialize Elasticsearch as output
func (out *elasticsearchOutput) Init(
beat string,
config outputs.MothershipConfig,
topologyExpire int,
) error {
if len(config.Protocol) == 0 {
config.Protocol = "http"
}
var urls []string
if len(config.Hosts) > 0 {
// use hosts setting
for _, host := range config.Hosts {
url, err := getURL(config.Protocol, config.Path, host)
if err != nil {
logp.Err("Invalid host param set: %s, Error: %v", host, err)
}
urls = append(urls, url)
}
} else {
// usage of host and port is deprecated as it is replaced by hosts
url := fmt.Sprintf("%s://%s:%d%s", config.Protocol, config.Host, config.Port, config.Path)
urls = append(urls, url)
}
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
if err != nil {
return err
}
es := NewElasticsearch(urls, tlsConfig, config.Username, config.Password)
out.Conn = es
if config.Index != "" {
out.Index = config.Index
} else {
out.Index = beat
}
out.TopologyExpire = 15000
if topologyExpire != 0 {
out.TopologyExpire = topologyExpire /*sec*/ * 1000 // millisec
}
if config.Max_retries != nil {
out.Conn.SetMaxRetries(*config.Max_retries)
}
logp.Info("[ElasticsearchOutput] Using Elasticsearch %s", urls)
logp.Info("[ElasticsearchOutput] Using index pattern [%s-]YYYY.MM.DD", out.Index)
logp.Info("[ElasticsearchOutput] Topology expires after %ds", out.TopologyExpire/1000)
if config.Save_topology {
err := out.EnableTTL()
if err != nil {
logp.Err("Fail to set _ttl mapping: %s", err)
// keep trying in the background
go func() {
for {
err := out.EnableTTL()
if err == nil {
break
}
logp.Err("Fail to set _ttl mapping: %s", err)
time.Sleep(5 * time.Second)
}
}()
}
}
return nil
}
示例3: Init
// Initialize Elasticsearch as output
func (out *elasticsearchOutput) Init(beat string, config outputs.MothershipConfig, topology_expire int) error {
if len(config.Protocol) == 0 {
config.Protocol = "http"
}
var urls []string
if len(config.Hosts) > 0 {
// use hosts setting
for _, host := range config.Hosts {
url := fmt.Sprintf("%s://%s%s", config.Protocol, host, config.Path)
urls = append(urls, url)
}
} else {
// use host and port settings
url := fmt.Sprintf("%s://%s:%d%s", config.Protocol, config.Host, config.Port, config.Path)
urls = append(urls, url)
}
es := NewElasticsearch(urls, config.Username, config.Password)
out.Conn = es
if config.Index != "" {
out.Index = config.Index
} else {
out.Index = beat
}
out.TopologyExpire = 15000
if topology_expire != 0 {
out.TopologyExpire = topology_expire /*sec*/ * 1000 // millisec
}
out.FlushInterval = 1000 * time.Millisecond
if config.Flush_interval != nil {
out.FlushInterval = time.Duration(*config.Flush_interval) * time.Millisecond
}
out.BulkMaxSize = 10000
if config.Bulk_size != nil {
out.BulkMaxSize = *config.Bulk_size
}
if config.Max_retries != nil {
out.Conn.SetMaxRetries(*config.Max_retries)
}
logp.Info("[ElasticsearchOutput] Using Elasticsearch %s", urls)
logp.Info("[ElasticsearchOutput] Using index pattern [%s-]YYYY.MM.DD", out.Index)
logp.Info("[ElasticsearchOutput] Topology expires after %ds", out.TopologyExpire/1000)
if out.FlushInterval > 0 {
logp.Info("[ElasticsearchOutput] Insert events in batches. Flush interval is %s. Bulk size is %d.", out.FlushInterval, out.BulkMaxSize)
} else {
logp.Info("[ElasticsearchOutput] Insert events one by one. This might affect the performance of the shipper.")
}
if config.Save_topology {
err := out.EnableTTL()
if err != nil {
logp.Err("Fail to set _ttl mapping: %s", err)
// keep trying in the background
go func() {
for {
err := out.EnableTTL()
if err == nil {
break
}
logp.Err("Fail to set _ttl mapping: %s", err)
time.Sleep(5 * time.Second)
}
}()
}
}
out.sendingQueue = make(chan EventMsg, 1000)
go out.SendMessagesGoroutine()
return nil
}