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

Golang logs.Info函数代码示例

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

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



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

示例1: 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:CMGS,项目名称:eru-agent,代码行数:28,代码来源:status.go


示例2: ListenAndServe

func ListenAndServe() error {
	svrConfig := InitSSHConfig()
	listener, err := net.Listen("tcp", g.Config.Bind)
	if err != nil {
		logs.Assert(err, "net.Listen failed")
	}
	defer listener.Close()

	for {
		conn, err := listener.Accept()
		if err != nil {
			logs.Assert(err, "listen.Accept failed")
		}

		sshConn := &SSHConn{conn, svrConfig}

		go func() {
			if err := sshConn.serve(); err != nil {
				logs.Info("Error occured while serving", err)
				return
			}
			logs.Info("Connection closed.")
		}()
	}
}
开发者ID:projecteru,项目名称:eru-ssh,代码行数:25,代码来源:proxy.go


示例3: setDefaultRoute

func setDefaultRoute(cid, gateway string, pid int) bool {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	origins, err := netns.Get()
	if err != nil {
		logs.Info("Get orignal namespace failed", err)
		return false
	}
	defer origins.Close()

	ns, err := netns.GetFromPid(pid)
	if err != nil {
		logs.Info("Get container namespace failed", err)
		return false
	}

	netns.Set(ns)
	defer ns.Close()
	defer netns.Set(origins)

	if err := delDefaultRoute(); err != nil {
		logs.Info("Delete default routing table failed", err)
		return false
	}

	if err := addDefaultRoute(gateway); err != nil {
		logs.Info("Add default route failed", err)
		return false
	}

	logs.Info("Set default route success", cid[:12], gateway)
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:34,代码来源:route_linux.go


示例4: getContainerMeta

func getContainerMeta(cid string) map[string]interface{} {
	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)

	containersKey := fmt.Sprintf("eru:agent:%s:containers:meta", g.Config.HostName)
	rep, err := gore.NewCommand("HGET", containersKey, cid).Run(conn)
	if err != nil {
		logs.Info("Status get meta", err)
		return nil
	}
	var result map[string]interface{}
	if rep.IsNil() {
		return nil
	}
	if b, err := rep.Bytes(); err != nil {
		logs.Info("Status get meta", err)
		return nil
	} else {
		if err := json.Unmarshal(b, &result); err != nil {
			logs.Info("Status unmarshal meta", err)
			return nil
		}
	}
	return result
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:25,代码来源:status.go


示例5: addNewContainer

// URL /api/container/add/
func addNewContainer(req *Request) (int, interface{}) {
	type Data struct {
		Control     string                 `json:"control"`
		ContainerID string                 `json:"container_id"`
		Meta        map[string]interface{} `json:"meta"`
	}

	data := &Data{}
	decoder := json.NewDecoder(req.Body)
	err := decoder.Decode(data)
	if err != nil {
		return http.StatusBadRequest, JSON{"message": "wrong JSON format"}
	}

	switch data.Control {
	case "+":
		if app.Valid(data.ContainerID) {
			break
		}
		logs.Info("API status watch", data.ContainerID)
		container, err := g.Docker.InspectContainer(data.ContainerID)
		if err != nil {
			logs.Info("API status inspect docker failed", err)
			break
		}
		if eruApp := app.NewEruApp(container, data.Meta); eruApp != nil {
			lenz.Attacher.Attach(&eruApp.Meta)
			app.Add(eruApp)
		}
	}
	return http.StatusOK, JSON{"message": "ok"}
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:33,代码来源:http.go


示例6: addRoute

func addRoute(cid, CIDR, ifc string, pid int) bool {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	origins, err := netns.Get()
	if err != nil {
		logs.Info("Get orignal namespace failed", err)
		return false
	}
	defer origins.Close()

	ns, err := netns.GetFromPid(pid)
	if err != nil {
		logs.Info("Get container namespace failed", err)
		return false
	}

	netns.Set(ns)
	defer ns.Close()
	defer netns.Set(origins)

	if err := addRouteByLink(CIDR, ifc); err != nil {
		logs.Info("Add route failed", err)
		return false
	}

	logs.Info("Add route success", cid[:12], CIDR, ifc)
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:29,代码来源:route_linux.go


示例7: Report

func (self *EruApp) Report() {
	t := time.NewTicker(self.Step)
	defer t.Stop()
	defer self.Client.Close()
	defer logs.Info(self.Name, self.EntryPoint, self.ID[:12], "metrics report stop")
	logs.Info(self.Name, self.EntryPoint, self.ID[:12], "metrics report start")
	for {
		select {
		case now := <-t.C:
			go func() {
				if info, err := self.UpdateStats(self.ID); err == nil {
					if isLimit {
						limitChan <- SoftLimit{self.ID, info}
					}
					rate := self.CalcRate(info, now)
					self.SaveLast(info)
					go self.Send(rate)
				} else {
					logs.Info("Update mertic failed", self.ID[:12])
				}
			}()
		case <-self.Stop:
			return
		}
	}
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:26,代码来源:metrics.go


示例8: setUpVLan

func setUpVLan(cid, ips string, pid int, veth netlink.Link) bool {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	origns, err := netns.Get()
	if err != nil {
		logs.Info("Get orignal namespace failed", err)
		return false
	}
	defer origns.Close()

	ns, err := netns.GetFromPid(pid)
	if err != nil {
		logs.Info("Get container namespace failed", err)
		return false
	}

	netns.Set(ns)
	defer ns.Close()
	defer netns.Set(origns)

	if err := BindAndSetup(veth, ips); err != nil {
		logs.Info("Bind and setup NIC failed", err)
		DelVlan(veth)
		return false
	}

	logs.Info("Add vlan device success", cid[:12])
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:30,代码来源:vlan_linux.go


示例9: SetDefaultRoute

func SetDefaultRoute(cid, gateway string) bool {
	_, err := g.Docker.InspectContainer(cid)
	if err != nil {
		logs.Info("VLanSetter inspect docker failed", err)
		return false
	}
	logs.Info("Set default route success", cid, gateway)
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:9,代码来源:route_darwin.go


示例10: AddRoute

func AddRoute(cid, CIDR string, ifc string) bool {
	_, err := g.Docker.InspectContainer(cid)
	if err != nil {
		logs.Info("VLanSetter inspect docker failed", err)
		return false
	}
	logs.Info("Add route success", cid, CIDR, ifc)
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:9,代码来源:route_darwin.go


示例11: AddVlan

func AddVlan(vethName, ips, cid string) bool {
	_, err := g.Docker.InspectContainer(cid)
	if err != nil {
		logs.Info("VLanSetter inspect docker failed", err)
		return false
	}
	logs.Info("Add VLAN device success", cid, vethName)
	return true
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:9,代码来源:vlan_darwin.go


示例12: 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:CMGS,项目名称:eru-agent,代码行数:55,代码来源:status.go


示例13: CloseLenz

func CloseLenz() {
	logs.Info("Close all lenz streamer")
	routes, err := Router.GetAll()
	if err != nil {
		logs.Info("Get all lenz route failed", err)
		return
	}
	for _, route := range routes {
		if !Router.Remove(route.ID) {
			logs.Info("Close lenz route failed", route.ID)
		}
	}
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:13,代码来源:lenz.go


示例14: addCalicoForContainer

// URL /api/container/:container_id/addcalico/
func addCalicoForContainer(req *Request) (int, interface{}) {
	type Endpoint struct {
		Nid     int    `json:"nid"`
		Profile string `json:"profile"`
		IP      string `json:"ip"`
		Append  bool   `json:"append"`
	}
	type Result struct {
		Succ        int    `json:"succ"`
		ContainerID string `json:"container_id"`
		IP          string `json:"ip"`
		Err         string `json:"err"`
	}

	if g.Config.VLan.Calico == "" {
		return http.StatusBadRequest, JSON{"message": "Agent not enable calico support"}
	}

	cid := req.URL.Query().Get(":container_id")
	env := os.Environ()
	env = append(env, fmt.Sprintf("ETCD_AUTHORITY=%s", g.Config.VLan.Calico))

	endpoints := []Endpoint{}
	decoder := json.NewDecoder(req.Body)
	if err := decoder.Decode(&endpoints); err != nil {
		return http.StatusBadRequest, JSON{"message": "wrong JSON format"}
	}

	rv := []Result{}
	for seq, endpoint := range endpoints {
		vethName := fmt.Sprintf("%s%d.%d", common.VLAN_PREFIX, endpoint.Nid, seq)
		if err := network.AddCalico(env, endpoint.Append, cid, vethName, endpoint.IP); err != nil {
			rv = append(rv, Result{Succ: 0, ContainerID: cid, IP: endpoint.IP, Err: err.Error()})
			logs.Info("API calico add interface failed", err)
			continue
		}

		//TODO remove when eru-core support ACL
		// currently only one profile is used
		if err := network.BindCalicoProfile(env, cid, endpoint.Profile); err != nil {
			rv = append(rv, Result{Succ: 0, ContainerID: cid, IP: endpoint.IP, Err: err.Error()})
			logs.Info("API calico add profile failed", err)
			continue
		}

		rv = append(rv, Result{Succ: 1, ContainerID: cid, IP: endpoint.IP})
	}
	return http.StatusOK, rv
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:50,代码来源:http.go


示例15: softOOMKill

func softOOMKill(cid string, rate float64) {
	logs.Debug("OOM killed", cid[:12])
	conn := g.GetRedisConn()
	defer g.ReleaseRedisConn(conn)

	key := fmt.Sprintf("eru:agent:%s:container:reason", cid)
	if _, err := gore.NewCommand("SET", key, common.OOM_KILLED).Run(conn); err != nil {
		logs.Info("OOM killed set flag", err)
	}
	if err := g.Docker.StopContainer(cid, 10); err != nil {
		logs.Info("OOM killed failed", cid[:12])
		return
	}
	logs.Info("OOM killed success", cid[:12])
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:15,代码来源:limit.go


示例16: Limit

func Limit() {
	if g.Config.Limit.Memory != 0 {
		logs.Info("App memory soft limit start")
		isLimit = true
		go calcMemoryUsage()
	}
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:7,代码来源:limit.go


示例17: HTTPServe

func HTTPServe() {
	restfulAPIServer := pat.New()

	handlers := map[string]map[string]func(*Request) (int, interface{}){
		"GET": {
			"/profile/":      profile,
			"/version/":      version,
			"/api/app/list/": listEruApps,
		},
		"POST": {
			"/api/container/add/":                     addNewContainer,
			"/api/container/:container_id/addvlan/":   addVlanForContainer,
			"/api/container/:container_id/addcalico/": addCalicoForContainer,
			"/api/container/:container_id/setroute/":  setRouteForContainer,
			"/api/container/:container_id/addroute/":  addRouteForContainer,
			"/api/eip/bind/":                          bindEIP,
			"/api/eip/release/":                       releaseEIP,
			"/api/container/publish/":                 publishContainer,
			"/api/container/unpublish/":               unpublishContainer,
		},
	}

	for method, routes := range handlers {
		for route, handler := range routes {
			restfulAPIServer.Add(method, route, http.HandlerFunc(JSONWrapper(handler)))
		}
	}

	http.Handle("/", restfulAPIServer)
	logs.Info("API http server start at", g.Config.API.Addr)
	err := http.ListenAndServe(g.Config.API.Addr, nil)
	if err != nil {
		logs.Assert(err, "ListenAndServe: ")
	}
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:35,代码来源:http.go


示例18: SetDefaultRoute

func SetDefaultRoute(cid, gateway string) bool {
	lock.Lock()
	defer lock.Unlock()

	logs.Info("Set", cid[:12], "default route", gateway)

	container, err := g.Docker.InspectContainer(cid)
	if err != nil {
		logs.Info("RouteSetter inspect docker failed", err)
		return false
	}

	pid := container.State.Pid

	return setDefaultRoute(cid, gateway, pid)
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:16,代码来源:route_linux.go


示例19: AddRoute

func AddRoute(cid, CIDR, ifc string) bool {
	lock.Lock()
	defer lock.Unlock()

	logs.Info("Add", cid[:12], "route", CIDR, ifc)

	container, err := g.Docker.InspectContainer(cid)
	if err != nil {
		logs.Info("RouteSetter inspect docker failed", err)
		return false
	}

	pid := container.State.Pid

	return addRoute(cid, CIDR, ifc, pid)
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:16,代码来源:route_linux.go


示例20: releaseEIP

// URL /api/eip/release/
func releaseEIP(req *Request) (int, interface{}) {
	type EIP struct {
		ID int `json:"id"`
	}
	type Result struct {
		Succ int    `json:"succ"`
		Err  string `json:"err"`
		Veth string `json:"id"`
	}

	eips := []EIP{}
	decoder := json.NewDecoder(req.Body)
	if err := decoder.Decode(&eips); err != nil {
		return http.StatusBadRequest, JSON{"message": "wrong JSON format"}
	}

	rv := []Result{}
	for _, eip := range eips {
		vethName := fmt.Sprintf("%s%d", common.VLAN_PREFIX, eip.ID)
		if err := network.DelMacVlanDevice(vethName); err != nil {
			rv = append(rv, Result{Succ: 0, Veth: vethName, Err: err.Error()})
			logs.Info("Release EIP failed", err, vethName)
			continue
		}
		rv = append(rv, Result{Succ: 1, Veth: vethName})
	}

	return http.StatusOK, rv
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:30,代码来源:http.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang generated.FlowdockConfig类代码示例发布时间:2022-05-28
下一篇:
Golang util.StartTestMaster函数代码示例发布时间: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