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

Golang logs.Debug函数代码示例

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

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



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

示例1: Attach

func (m *AttachManager) Attach(app *defines.Meta) {
	// Not Thread Safe
	if m.Attached(app.ID) {
		return
	}
	outrd, outwr := io.Pipe()
	errrd, errwr := io.Pipe()
	go func() {
		err := g.Docker.AttachToContainer(docker.AttachToContainerOptions{
			Container:    app.ID,
			OutputStream: outwr,
			ErrorStream:  errwr,
			Stdin:        false,
			Stdout:       true,
			Stderr:       true,
			Stream:       true,
		})
		outwr.Close()
		errwr.Close()
		logs.Debug("Lenz Attach", app.ID[:12], "finished")
		if err != nil {
			logs.Debug("Lenz Attach", app.ID, "failure:", err)
		}
		m.send(&defines.AttachEvent{Type: "detach", App: app})
		m.Lock()
		defer m.Unlock()
		delete(m.attached, app.ID)
	}()
	m.Lock()
	m.attached[app.ID] = NewLogPump(outrd, errrd, app)
	m.Unlock()
	m.send(&defines.AttachEvent{Type: "attach", App: app})
	logs.Debug("Lenz Attach", app.ID[:12], "success")
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:34,代码来源:attacher.go


示例2: routeWatcher

func routeWatcher() {
	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)

	subs := gore.NewSubscriptions(conn)
	defer subs.Close()
	subKey := fmt.Sprintf("eru:agent:%s:route", g.Config.HostName)
	logs.Debug("API route subscribe", subKey)
	subs.Subscribe(subKey)

	for message := range subs.Message() {
		if message == nil {
			logs.Info("API route watcher shutdown")
			break
		}
		command := string(message.Message)
		logs.Debug("API route watcher get", command)
		parser := strings.Split(command, "|")
		if len(parser) != 2 {
			logs.Info("API route watcher command invaild", command)
			continue
		}
		cid, gateway := parser[0], parser[1]
		if !network.SetDefaultRoute(cid, gateway) {
			logs.Info("Set default route failed")
		}
	}
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:28,代码来源:pubsub.go


示例3: monitor

func monitor() {
	for event := range events {
		switch event.Status {
		case common.STATUS_DIE:
			logs.Debug("Status", event.Status, event.ID[:12], event.From)
			app.Remove(event.ID)
			reportContainerDeath(event.ID)
		case common.STATUS_START:
			logs.Debug("Status", event.Status, event.ID[:12], event.From)
			// if not in watching list, just ignore it
			if meta := getContainerMeta(event.ID); meta != nil && !app.Valid(event.ID) {
				container, err := g.Docker.InspectContainer(event.ID)
				if err != nil {
					logs.Info("Status inspect docker failed", err)
					break
				}
				eruApp := app.NewEruApp(container, meta)
				if eruApp == nil {
					logs.Info("Create EruApp failed")
					break
				}
				lenz.Attacher.Attach(&eruApp.Meta)
				app.Add(eruApp)
				reportContainerCure(event.ID)
			}
		}
	}
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:28,代码来源:status.go


示例4: load

func load() {
	containers, err := g.Docker.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		logs.Assert(err, "List containers")
	}

	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)
	containersKey := fmt.Sprintf("eru:agent:%s:containers:meta", g.Config.HostName)
	logs.Debug("Status get targets from", containersKey)
	rep, err := gore.NewCommand("HGETALL", containersKey).Run(conn)
	if err != nil {
		logs.Assert(err, "Status get targets")
	}

	if rep.IsNil() {
		return
	}

	targets, err := rep.Map()
	if err != nil {
		logs.Assert(err, "Status load targets")
	}

	logs.Debug("Status targets:", targets)
	logs.Info("Status load container")
	for _, container := range containers {
		if _, ok := targets[container.ID]; !ok {
			continue
		}

		status := getStatus(container.Status)
		if status != common.STATUS_START {
			reportContainerDeath(container.ID)
			continue
		}
		var meta map[string]interface{}
		if err := json.Unmarshal([]byte(targets[container.ID]), &meta); err != nil {
			logs.Info("Status load failed", err)
			continue
		}

		c, err := g.Docker.InspectContainer(container.ID)
		if err != nil {
			logs.Info("Status inspect docker failed", err)
			continue
		}

		if eruApp := app.NewEruApp(c, meta); eruApp != nil {
			lenz.Attacher.Attach(&eruApp.Meta)
			app.Add(eruApp)
			reportContainerCure(container.ID)
		}
	}
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:55,代码来源:status.go


示例5: send

func (self *EruApp) send(rate map[string]float64) {
	data := []*model.MetricValue{}
	for k, d := range rate {
		data = append(data, self.newMetricValue(k, d))
	}
	var resp model.TransferResponse
	if err := self.Client.Call("Transfer.Update", data, &resp); err != nil {
		logs.Debug("Metrics call Transfer.Update fail", err, self.Name, self.EntryPoint)
		return
	}
	logs.Debug(self.Endpoint, self.Last, &resp)
}
开发者ID:sdgdsffdsfff,项目名称:eru-agent,代码行数:12,代码来源:metric.go


示例6: NewEruApp

func NewEruApp(container *docker.Container, extend map[string]interface{}) *EruApp {
	name, entrypoint, ident := utils.GetAppInfo(container.Name)
	if name == "" {
		logs.Info("Container name invaild", container.Name)
		return nil
	}
	logs.Debug("Eru App", name, entrypoint, ident)

	transfer, _ := g.Transfers.Get(container.ID, 0)
	client := falcon.CreateFalconClient(
		transfer,
		time.Duration(g.Config.Metrics.Timeout)*time.Millisecond,
	)

	step := time.Duration(g.Config.Metrics.Step) * time.Second
	extend["hostname"] = g.Config.HostName
	extend["cid"] = container.ID[:12]
	extend["ident"] = ident
	tag := []string{}
	for k, v := range extend {
		tag = append(tag, fmt.Sprintf("%s=%v", k, v))
	}
	endpoint := fmt.Sprintf("%s-%s", name, entrypoint)

	meta := defines.Meta{container.ID, container.State.Pid, name, entrypoint, ident, extend}
	metric := metric.CreateMetric(step, client, strings.Join(tag, ","), endpoint)
	eruApp := &EruApp{meta, metric}
	return eruApp
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:29,代码来源:eru.go


示例7: getNetStats

func (self *Metric) getNetStats(result map[string]uint64) (err error) {
	s := bufio.NewScanner(self.statFile)
	defer self.statFile.Seek(0, 0)
	var d uint64
	for s.Scan() {
		var name string
		var n [8]uint64
		text := s.Text()
		if strings.Index(text, ":") < 1 {
			continue
		}
		ts := strings.Split(text, ":")
		fmt.Sscanf(ts[0], "%s", &name)
		if !strings.HasPrefix(name, g.vlanPrefix) && name != g.defaultVlan {
			continue
		}
		fmt.Sscanf(ts[1],
			"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
			&n[0], &n[1], &n[2], &n[3], &d, &d, &d, &d,
			&n[4], &n[5], &n[6], &n[7], &d, &d, &d, &d,
		)
		result[name+".inbytes"] = n[0]
		result[name+".inpackets"] = n[1]
		result[name+".inerrs"] = n[2]
		result[name+".indrop"] = n[3]
		result[name+".outbytes"] = n[4]
		result[name+".outpackets"] = n[5]
		result[name+".outerrs"] = n[6]
		result[name+".outdrop"] = n[7]
	}
	logs.Debug("Container net status", result)
	return
}
开发者ID:freelingchang,项目名称:eru-metric,代码行数:33,代码来源:stats_linux.go


示例8: NewEruApp

func NewEruApp(container *docker.Container, extend map[string]interface{}) *EruApp {
	name, entrypoint, ident := utils.GetAppInfo(container.Name)
	if name == "" {
		logs.Info("Container name invaild", container.Name)
		return nil
	}
	logs.Debug("Eru App", name, entrypoint, ident)

	transfer, _ := g.Transfers.Get(container.ID, 0)
	client := defines.SingleConnRpcClient{
		RpcServer: transfer,
		Timeout:   time.Duration(g.Config.Metrics.Timeout) * time.Millisecond,
	}
	step := time.Duration(g.Config.Metrics.Step) * time.Second

	extend["hostname"] = g.Config.HostName
	extend["cid"] = container.ID[:12]
	extend["ident"] = ident
	tag := []string{}
	for k, v := range extend {
		tag = append(tag, fmt.Sprintf("%s=%v", k, v))
	}
	endpoint := fmt.Sprintf("%s-%s", name, entrypoint)

	eruApp := &EruApp{
		defines.Meta{container.ID, container.State.Pid, name, entrypoint, ident, extend},
		defines.Metric{Step: step, Client: client, Tag: strings.Join(tag, ","), Endpoint: endpoint},
		nil,
	}

	eruApp.Stop = make(chan bool)
	return eruApp
}
开发者ID:liumuqi,项目名称:eru-agent,代码行数:33,代码来源:eru.go


示例9: NewLogPump

func NewLogPump(stdout, stderr io.Reader, app *defines.Meta) *LogPump {
	obj := &LogPump{
		app:      app,
		channels: make(map[chan *defines.Log]struct{}),
	}
	pump := func(typ string, source io.Reader) {
		buf := bufio.NewReader(source)
		for {
			data, err := buf.ReadBytes('\n')
			if err != nil {
				if err != io.EOF {
					logs.Debug("Lenz Pump:", app.ID, typ, err)
				}
				return
			}
			obj.send(&defines.Log{
				Data:       strings.TrimSuffix(string(data), "\n"),
				ID:         app.ID,
				Name:       app.Name,
				EntryPoint: app.EntryPoint,
				Ident:      app.Ident,
				Type:       typ,
				Datetime:   time.Now().Format(common.DATETIME_FORMAT),
			})
		}
	}
	go pump("stdout", stdout)
	go pump("stderr", stderr)
	return obj
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:30,代码来源:attacher.go


示例10: tcpStreamer

func tcpStreamer(logline *defines.Log, addr string) error {
	tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
	if err != nil {
		logs.Debug("Resolve tcp failed", err)
		return err
	}

	conn, err := net.DialTCP("tcp", nil, tcpAddr)
	if err != nil {
		logs.Debug("Connect backend failed", err)
		return err
	}
	defer conn.Close()
	writeJSON(conn, logline)
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:eru-agent,代码行数:16,代码来源:streamer.go


示例11: udpStreamer

func udpStreamer(logline *defines.Log, addr string) error {
	udpAddr, err := net.ResolveUDPAddr("udp", addr)
	if err != nil {
		logs.Debug("Resolve udp failed", err)
		return err
	}

	conn, err := net.DialUDP("udp", nil, udpAddr)
	if err != nil {
		logs.Debug("Connect backend failed", err)
		return err
	}
	defer conn.Close()
	writeJSON(conn, logline)
	return nil
}
开发者ID:sdgdsffdsfff,项目名称:eru-agent,代码行数:16,代码来源:streamer.go


示例12: GetNetStats

func GetNetStats(statFile *os.File, result map[string]uint64) (err error) {
	s := bufio.NewScanner(statFile)
	defer statFile.Seek(0, 0)
	var d uint64
	for s.Scan() {
		var name string
		var n [8]uint64
		text := s.Text()
		if strings.Index(text, ":") < 1 {
			continue
		}
		ts := strings.Split(text, ":")
		fmt.Sscanf(ts[0], "%s", &name)
		if !strings.HasPrefix(name, common.VLAN_PREFIX) &&
			name != common.DEFAULT_BR {
			continue
		}
		fmt.Sscanf(ts[1],
			"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
			&n[0], &n[1], &n[2], &n[3], &d, &d, &d, &d,
			&n[4], &n[5], &n[6], &n[7], &d, &d, &d, &d,
		)
		result[name+".inbytes"] = n[0]
		result[name+".inpackets"] = n[1]
		result[name+".inerrs"] = n[2]
		result[name+".indrop"] = n[3]
		result[name+".outbytes"] = n[4]
		result[name+".outpackets"] = n[5]
		result[name+".outerrs"] = n[6]
		result[name+".outdrop"] = n[7]
	}
	logs.Debug("Container net status", result)
	return
}
开发者ID:liumuqi,项目名称:eru-agent,代码行数:34,代码来源:stats_linux.go


示例13: statusWatcher

func statusWatcher() {
	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)

	subs := gore.NewSubscriptions(conn)
	defer subs.Close()
	subKey := fmt.Sprintf("eru:agent:%s:watcher", g.Config.HostName)
	logs.Debug("API status subscribe", subKey)
	subs.Subscribe(subKey)

	for message := range subs.Message() {
		if message == nil {
			logs.Info("API status watcher shutdown")
			break
		}
		command := string(message.Message)
		logs.Debug("API status watcher get", command)
		parser := strings.Split(command, "|")
		if len(parser) != 3 {
			logs.Info("API status watcher command invaild", command)
			continue
		}
		control, cid, metaString := parser[0], parser[1], parser[2]
		switch control {
		case "+":
			if app.Valid(cid) {
				break
			}
			logs.Info("API status watch", cid[:12])
			container, err := g.Docker.InspectContainer(cid)
			if err != nil {
				logs.Info("API status inspect docker failed", err)
				break
			}
			var meta map[string]interface{}
			if err := json.Unmarshal([]byte(metaString), &meta); err != nil {
				logs.Info("API status load failed", err)
				break
			}
			if eruApp := app.NewEruApp(container, meta); eruApp != nil {
				lenz.Attacher.Attach(&eruApp.Meta)
				app.Add(eruApp)
			}
		}
	}
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:46,代码来源:pubsub.go


示例14: InitLenz

func InitLenz() {
	Attacher = NewAttachManager(g.Docker)
	Router = NewRouteManager(Attacher, g.Config.Lenz.Stdout)
	Routefs = RouteFileStore(g.Config.Lenz.Routes)
	if len(g.Config.Lenz.Forwards) > 0 {
		logs.Debug("Lenz Routing all to", g.Config.Lenz.Forwards)
		target := defines.Target{Addrs: g.Config.Lenz.Forwards}
		route := defines.Route{ID: "lenz_default", Target: &target}
		route.LoadBackends()
		Router.Add(&route)
	}
	if _, err := os.Stat(g.Config.Lenz.Routes); err == nil {
		logs.Debug("Loading and persisting routes in", g.Config.Lenz.Routes)
		logs.Assert(Router.Load(Routefs), "persistor")
	}
	logs.Info("Lenz initiated")
}
开发者ID:ninjadq,项目名称:eru-agent,代码行数:17,代码来源:lenz.go


示例15: GetNetStats

func GetNetStats(exec *docker.Exec) (result map[string]uint64, err error) {
	outr, outw := io.Pipe()
	defer outr.Close()

	success := make(chan struct{})
	failure := make(chan error)
	go func() {
		// TODO: 防止被err流block, 删掉先, 之后记得补上
		err = g.Docker.StartExec(
			exec.ID,
			docker.StartExecOptions{
				OutputStream: outw,
				Success:      success,
			},
		)
		outw.Close()
		if err != nil {
			close(success)
			failure <- err
		}
	}()
	if _, ok := <-success; ok {
		success <- struct{}{}
		result = map[string]uint64{}
		s := bufio.NewScanner(outr)
		var d uint64
		for s.Scan() {
			var name string
			var n [8]uint64
			text := s.Text()
			if strings.Index(text, ":") < 1 {
				continue
			}
			ts := strings.Split(text, ":")
			fmt.Sscanf(ts[0], "%s", &name)
			if !strings.HasPrefix(name, common.VLAN_PREFIX) {
				continue
			}
			fmt.Sscanf(ts[1],
				"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
				&n[0], &n[1], &n[2], &n[3], &d, &d, &d, &d,
				&n[4], &n[5], &n[6], &n[7], &d, &d, &d, &d,
			)
			result[name+".inbytes"] = n[0]
			result[name+".inpackets"] = n[1]
			result[name+".inerrs"] = n[2]
			result[name+".indrop"] = n[3]
			result[name+".outbytes"] = n[4]
			result[name+".outpackets"] = n[5]
			result[name+".outerrs"] = n[6]
			result[name+".outdrop"] = n[7]
		}
		logs.Debug("Container net status", result)
		return
	}
	err = <-failure
	return nil, err
}
开发者ID:sdgdsffdsfff,项目名称:eru-agent,代码行数:58,代码来源:metric.go


示例16: Attach

func (m *AttachManager) Attach(app *defines.Meta) {
	// Not Thread Safe
	if m.Attached(app.ID) {
		return
	}
	success := make(chan struct{})
	failure := make(chan error)
	outrd, outwr := io.Pipe()
	errrd, errwr := io.Pipe()
	go func() {
		err := m.client.AttachToContainer(docker.AttachToContainerOptions{
			Container:    app.ID,
			OutputStream: outwr,
			ErrorStream:  errwr,
			Stdin:        false,
			Stdout:       true,
			Stderr:       true,
			Stream:       true,
			Success:      success,
		})
		outwr.Close()
		errwr.Close()
		logs.Debug("Lenz Attach", app.ID[:12], "finished")
		if err != nil {
			close(success)
			failure <- err
		}
		m.send(&defines.AttachEvent{Type: "detach", App: app})
		m.Lock()
		defer m.Unlock()
		delete(m.attached, app.ID)
	}()
	_, ok := <-success
	if ok {
		m.Lock()
		m.attached[app.ID] = NewLogPump(outrd, errrd, app)
		m.Unlock()
		success <- struct{}{}
		m.send(&defines.AttachEvent{Type: "attach", App: app})
		logs.Debug("Lenz Attach", app.ID[:12], "success")
		return
	}
	logs.Debug("Lenz Attach", app.ID, "failure:", <-failure)
}
开发者ID:ninjadq,项目名称:eru-agent,代码行数:44,代码来源:attacher.go


示例17: DoPut

func DoPut(url string) {
	req, err := http.NewRequest("PUT", url, nil)
	if err != nil {
		logs.Debug("Gen request failed", err)
		return
	}
	response, err := httpClient.Do(req)
	if err != nil {
		logs.Debug("Do request failed", err)
		return
	}
	defer response.Body.Close()
	data, err := ioutil.ReadAll(response.Body)
	if err != nil {
		logs.Debug("Read response failed", err)
		return
	}
	logs.Debug("Response:", string(data))
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:19,代码来源:utils.go


示例18: vlanWatcher

func vlanWatcher() {
	conn := g.GetRedisConn()
	report := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)
	defer g.ReleaseRedisConn(report)

	subs := gore.NewSubscriptions(conn)
	defer subs.Close()
	subKey := fmt.Sprintf("eru:agent:%s:vlan", g.Config.HostName)
	logs.Debug("API vlan subscribe", subKey)
	subs.Subscribe(subKey)

	for message := range subs.Message() {
		if message == nil {
			logs.Info("API vLan watcher shutdown")
			break
		}
		command := string(message.Message)
		logs.Debug("API vlan watcher get", command)
		parser := strings.Split(command, "|")
		if len(parser) <= 2 {
			logs.Info("API vlan watcher command invaild", command)
			continue
		}
		taskID, cid := parser[0], parser[1]
		feedKey := fmt.Sprintf("eru:agent:%s:feedback", taskID)
		for seq, content := range parser[2:] {
			p := strings.Split(content, ":")
			if len(p) != 2 {
				logs.Info("API vlan watcher ips invaild", content)
				continue
			}
			nid, ips := p[0], p[1]
			vethName := fmt.Sprintf("%s%s.%d", common.VLAN_PREFIX, nid, seq)
			if network.AddVLan(vethName, ips, cid) {
				gore.NewCommand("LPUSH", feedKey, fmt.Sprintf("1|%s|%s|%s", cid, vethName, ips)).Run(report)
				continue
			}
			gore.NewCommand("LPUSH", feedKey, "0|||").Run(report)
		}
	}
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:42,代码来源:pubsub.go


示例19: reportContainerDeath

func reportContainerDeath(cid string) {
	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)

	flagKey := fmt.Sprintf("eru:agent:%s:container:flag", cid)
	rep, err := gore.NewCommand("GET", flagKey).Run(conn)
	if err != nil {
		logs.Info("Status failed in get flag", err)
		return
	}
	if !rep.IsNil() {
		gore.NewCommand("DEL", flagKey).Run(conn)
		logs.Debug(cid[:12], "Status flag set, ignore")
		return
	}

	url := fmt.Sprintf("%s/api/container/%s/kill", g.Config.Eru.Endpoint, cid)
	utils.DoPut(url)
	logs.Debug(cid[:12], "dead, remove from watching list")
}
开发者ID:kevinsu1989,项目名称:eru-agent,代码行数:20,代码来源:status.go


示例20: Send

func (self *FalconClient) Send(data map[string]float64, endpoint, tag string, timestamp, step int64) error {
	metrics := []*model.MetricValue{}
	var metric *model.MetricValue
	for k, v := range data {
		metric = &model.MetricValue{
			Endpoint:  endpoint,
			Metric:    k,
			Value:     v,
			Step:      step,
			Type:      "GAUGE",
			Tags:      tag,
			Timestamp: timestamp,
		}
		metrics = append(metrics, metric)
	}
	logs.Debug(metrics)
	var resp model.TransferResponse
	if err := self.call("Transfer.Update", metrics, &resp); err != nil {
		return err
	}
	logs.Debug(endpoint, timestamp, &resp)
	return nil
}
开发者ID:freelingchang,项目名称:eru-metric,代码行数:23,代码来源:falcon.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang logs.Info函数代码示例发布时间:2022-05-28
下一篇:
Golang nbt.ITag类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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