• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang publisher.Publisher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/elastic/beats/libbeat/publisher.Publisher的典型用法代码示例。如果您正苦于以下问题:Golang Publisher类的具体用法?Golang Publisher怎么用?Golang Publisher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Publisher类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewPublisher

func NewPublisher(pub *publisher.Publisher, hwm, bulkHWM int) *PacketbeatPublisher {
	return &PacketbeatPublisher{
		pub:    pub,
		client: pub.Connect(),
		done:   make(chan struct{}),
		trans:  make(chan common.MapStr, hwm),
		flows:  make(chan []common.MapStr, bulkHWM),
	}
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:9,代码来源:publish.go


示例2: NewPublisher

func NewPublisher(
	pub publisher.Publisher,
	hwm, bulkHWM int,
) (*PacketbeatPublisher, error) {
	topo, ok := pub.(TopologyProvider)
	if !ok {
		return nil, errors.New("Requires topology provider")
	}

	return &PacketbeatPublisher{
		pub:            pub,
		topo:           topo,
		geoLite:        topo.GeoLite(),
		ignoreOutgoing: topo.IgnoreOutgoing(),
		client:         pub.Connect(),
		done:           make(chan struct{}),
		trans:          make(chan common.MapStr, hwm),
		flows:          make(chan []common.MapStr, bulkHWM),
	}, nil
}
开发者ID:ChongFeng,项目名称:beats,代码行数:20,代码来源:publish.go


示例3: newModuleWrappers

// newModuleWrappers creates new Modules and their associated MetricSets based
// on the given configuration. It constructs the supporting filters and
// publisher client and stores it all in a moduleWrapper.
func newModuleWrappers(
	modulesConfig []*common.Config,
	r *mb.Register,
	publisher *publisher.Publisher,
) ([]*moduleWrapper, error) {
	modules, err := mb.NewModules(modulesConfig, r)
	if err != nil {
		return nil, err
	}

	// Wrap the Modules and MetricSet's.
	var wrappers []*moduleWrapper
	var errs multierror.Errors
	for k, v := range modules {
		debugf("initializing Module type %s, %T=%+v", k.Name(), k, k)
		f, err := filter.New(k.Config().Filters)
		if err != nil {
			errs = append(errs, errors.Wrapf(err, "module %s", k.Name()))
			continue
		}

		mw := &moduleWrapper{
			Module:    k,
			filters:   f,
			pubClient: publisher.Connect(),
		}
		wrappers = append(wrappers, mw)

		msws := make([]*metricSetWrapper, 0, len(v))
		for _, ms := range v {
			debugf("initializing MetricSet type %s/%s, %T=%+v",
				ms.Module().Name(), ms.Name(), ms, ms)
			msw := &metricSetWrapper{
				MetricSet: ms,
				module:    mw,
				stats:     new(expvar.Map).Init(),
			}
			msws = append(msws, msw)

			// Initialize expvar stats for this MetricSet.
			fetches.Set(fmt.Sprintf("%s-%s", mw.Name(), msw.Name()), msw.stats)
			msw.stats.Add(successesKey, 0)
			msw.stats.Add(failuresKey, 0)
			msw.stats.Add(eventsKey, 0)
		}
		mw.metricSets = msws
	}

	return wrappers, errs.Err()
}
开发者ID:yan2jared,项目名称:beats,代码行数:53,代码来源:module.go


示例4: normalizeTransAddr

func normalizeTransAddr(pub *publisher.Publisher, event common.MapStr) bool {
	debugf("normalize address for: %v", event)

	var srcServer, dstServer string
	src, ok := event["src"].(*common.Endpoint)
	debugf("has src: %v", ok)
	if ok {
		// check if it's outgoing transaction (as client)
		isOutgoing := pub.IsPublisherIP(src.Ip)
		if isOutgoing {
			if pub.IgnoreOutgoing {
				// duplicated transaction -> ignore it
				debugf("Ignore duplicated transaction on: %s -> %s", srcServer, dstServer)
				return false
			}

			//outgoing transaction
			event["direction"] = "out"
		}

		srcServer = pub.GetServerName(src.Ip)
		event["client_ip"] = src.Ip
		event["client_port"] = src.Port
		event["client_proc"] = src.Proc
		event["client_server"] = srcServer
		delete(event, "src")
	}

	dst, ok := event["dst"].(*common.Endpoint)
	debugf("has dst: %v", ok)
	if ok {
		dstServer = pub.GetServerName(dst.Ip)
		event["ip"] = dst.Ip
		event["port"] = dst.Port
		event["proc"] = dst.Proc
		event["server"] = dstServer
		delete(event, "dst")

		//check if it's incoming transaction (as server)
		if pub.IsPublisherIP(dst.Ip) {
			// incoming transaction
			event["direction"] = "in"
		}

	}

	if pub.GeoLite != nil {
		realIP, exists := event["real_ip"]
		if exists && len(realIP.(common.NetString)) > 0 {
			loc := pub.GeoLite.GetLocationByIP(string(realIP.(common.NetString)))
			if loc != nil && loc.Latitude != 0 && loc.Longitude != 0 {
				loc := fmt.Sprintf("%f, %f", loc.Latitude, loc.Longitude)
				event["client_location"] = loc
			}
		} else {
			if len(srcServer) == 0 && src != nil { // only for external IP addresses
				loc := pub.GeoLite.GetLocationByIP(src.Ip)
				if loc != nil && loc.Latitude != 0 && loc.Longitude != 0 {
					loc := fmt.Sprintf("%f, %f", loc.Latitude, loc.Longitude)
					event["client_location"] = loc
				}
			}
		}
	}

	return true
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:67,代码来源:publish.go



注:本文中的github.com/elastic/beats/libbeat/publisher.Publisher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mb.BaseMetricSet类代码示例发布时间:2022-05-23
下一篇:
Golang publisher.Client类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap