當前位置: 首頁>>代碼示例>>Golang>>正文


Golang report.ExtractHostID函數代碼示例

本文整理匯總了Golang中github.com/weaveworks/scope/report.ExtractHostID函數的典型用法代碼示例。如果您正苦於以下問題:Golang ExtractHostID函數的具體用法?Golang ExtractHostID怎麽用?Golang ExtractHostID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ExtractHostID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MapAddressIdentity

// MapAddressIdentity maps an address topology node to an address renderable
// node. As it is only ever run on address topology nodes, we expect that
// certain keys are present.
func MapAddressIdentity(m RenderableNode, local report.Networks) RenderableNodes {
	addr, ok := m.Metadata[endpoint.Addr]
	if !ok {
		return RenderableNodes{}
	}

	// Nodes without a hostid are treated as psuedo nodes
	_, ok = m.Metadata[report.HostNodeID]
	if !ok {
		// If the addr is not in a network local to this report, we emit an
		// internet node
		if !local.Contains(net.ParseIP(addr)) {
			return RenderableNodes{TheInternetID: newDerivedPseudoNode(TheInternetID, TheInternetMajor, m)}
		}

		// Otherwise generate a pseudo node for every
		outputID := MakePseudoNodeID(addr, "")
		if len(m.Adjacency) > 0 {
			_, dstAddr, _ := report.ParseAddressNodeID(m.Adjacency[0])
			outputID = MakePseudoNodeID(addr, dstAddr)
		}
		return RenderableNodes{outputID: newDerivedPseudoNode(outputID, addr, m)}
	}

	var (
		id    = MakeAddressID(report.ExtractHostID(m.Node), addr)
		major = addr
		minor = report.ExtractHostID(m.Node)
		rank  = major
	)

	return RenderableNodes{id: NewRenderableNodeWith(id, major, minor, rank, m)}
}
開發者ID:philipz,項目名稱:scope,代碼行數:36,代碼來源:mapping.go

示例2: MapEndpointIdentity

// MapEndpointIdentity maps an endpoint topology node to a single endpoint
// renderable node. As it is only ever run on endpoint topology nodes, we
// expect that certain keys are present.
func MapEndpointIdentity(m RenderableNode, local report.Networks) RenderableNodes {
	addr, ok := m.Metadata[endpoint.Addr]
	if !ok {
		return RenderableNodes{}
	}

	port, ok := m.Metadata[endpoint.Port]
	if !ok {
		return RenderableNodes{}
	}

	// We only show nodes found through procspy in this view.
	_, procspied := m.Metadata[endpoint.Procspied]
	if !procspied {
		return RenderableNodes{}
	}

	// Nodes without a hostid are treated as psuedo nodes
	if _, ok = m.Metadata[report.HostNodeID]; !ok {
		// If the dstNodeAddr is not in a network local to this report, we emit an
		// internet node
		if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
			return RenderableNodes{TheInternetID: newDerivedPseudoNode(TheInternetID, TheInternetMajor, m)}
		}

		// We are a 'client' pseudo node if the port is in the ephemeral port range.
		// Linux uses 32768 to 61000, IANA suggests 49152 to 65535.
		if p, err := strconv.Atoi(port); err == nil && len(m.Adjacency) > 0 && p >= 32768 && p < 65535 {
			// We only exist if there is something in our adjacency
			// Generate a single pseudo node for every (client ip, server ip, server port)
			dstNodeID := m.Adjacency[0]
			serverIP, serverPort := trySplitAddr(dstNodeID)
			outputID := MakePseudoNodeID(addr, serverIP, serverPort)
			return RenderableNodes{outputID: newDerivedPseudoNode(outputID, addr, m)}
		}

		// Otherwise (the server node is missing), generate a pseudo node for every (server ip, server port)
		outputID := MakePseudoNodeID(addr, port)
		if port != "" {
			return RenderableNodes{outputID: newDerivedPseudoNode(outputID, addr+":"+port, m)}
		}
		return RenderableNodes{outputID: newDerivedPseudoNode(outputID, addr, m)}
	}

	var (
		id    = MakeEndpointID(report.ExtractHostID(m.Node), addr, port)
		major = fmt.Sprintf("%s:%s", addr, port)
		minor = report.ExtractHostID(m.Node)
		rank  = major
	)

	pid, pidOK := m.Metadata[process.PID]
	if pidOK {
		minor = fmt.Sprintf("%s (%s)", minor, pid)
	}

	return RenderableNodes{id: NewRenderableNodeWith(id, major, minor, rank, m)}
}
開發者ID:webwurst,項目名稱:scope,代碼行數:61,代碼來源:mapping.go

示例3: MapProcessIdentity

// MapProcessIdentity maps a process topology node to process RenderableNode node.
// As it is only ever run on process topology nodes, we can safely assume the
// presence of certain keys.
func MapProcessIdentity(m report.NodeMetadata) (RenderableNode, bool) {
	var (
		id    = MakeProcessID(report.ExtractHostID(m), m["pid"])
		major = m["comm"]
		minor = fmt.Sprintf("%s (%s)", report.ExtractHostID(m), m["pid"])
		rank  = m["pid"]
	)

	return NewRenderableNode(id, major, minor, rank, m), true
}
開發者ID:davkal,項目名稱:scope,代碼行數:13,代碼來源:mapping.go

示例4: MapAddressIdentity

// MapAddressIdentity maps a address topology node to address RenderableNode
// node. As it is only ever run on address topology nodes, we can safely
// assume the presence of certain keys.
func MapAddressIdentity(m report.NodeMetadata) (RenderableNode, bool) {
	var (
		id    = MakeAddressID(report.ExtractHostID(m), m["addr"])
		major = m["addr"]
		minor = report.ExtractHostID(m)
		rank  = major
	)

	return NewRenderableNode(id, major, minor, rank, m), true
}
開發者ID:davkal,項目名稱:scope,代碼行數:13,代碼來源:mapping.go

示例5: MapAddressIdentity

// MapAddressIdentity maps an address topology node to an address renderable
// node. As it is only ever run on address topology nodes, we expect that
// certain keys are present.
func MapAddressIdentity(m report.NodeMetadata) (RenderableNode, bool) {
	addr, ok := m.Metadata[endpoint.Addr]
	if !ok {
		return RenderableNode{}, false
	}

	var (
		id    = MakeAddressID(report.ExtractHostID(m), addr)
		major = addr
		minor = report.ExtractHostID(m)
		rank  = major
	)

	return NewRenderableNode(id, major, minor, rank, m), true
}
開發者ID:barravi,項目名稱:scope,代碼行數:18,代碼來源:mapping.go

示例6: MapProcessIdentity

// MapProcessIdentity maps a process topology node to a process renderable
// node. As it is only ever run on process topology nodes, we expect that
// certain keys are present.
func MapProcessIdentity(m RenderableNode, _ report.Networks) RenderableNodes {
	pid, ok := m.Latest.Lookup(process.PID)
	if !ok {
		return RenderableNodes{}
	}

	var (
		id       = MakeProcessID(report.ExtractHostID(m.Node), pid)
		major, _ = m.Latest.Lookup(process.Name)
		minor    = fmt.Sprintf("%s (%s)", report.ExtractHostID(m.Node), pid)
		rank, _  = m.Latest.Lookup(process.Name)
	)

	return RenderableNodes{id: NewRenderableNodeWith(id, major, minor, rank, m)}
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:18,代碼來源:mapping.go

示例7: MapEndpointIdentity

// MapEndpointIdentity maps a endpoint topology node to endpoint RenderableNode
// node. As it is only ever run on endpoint topology nodes, we can safely
// assume the presence of certain keys.
func MapEndpointIdentity(m report.NodeMetadata) (RenderableNode, bool) {
	var (
		id      = MakeEndpointID(report.ExtractHostID(m), m["addr"], m["port"])
		major   = fmt.Sprintf("%s:%s", m["addr"], m["port"])
		pid, ok = m["pid"]
		minor   = report.ExtractHostID(m)
		rank    = major
	)

	if ok {
		minor = fmt.Sprintf("%s (%s)", report.ExtractHostID(m), pid)
	}

	return NewRenderableNode(id, major, minor, rank, m), true
}
開發者ID:davkal,項目名稱:scope,代碼行數:18,代碼來源:mapping.go

示例8: MapProcessIdentity

// MapProcessIdentity maps a process topology node to a process renderable
// node. As it is only ever run on process topology nodes, we expect that
// certain keys are present.
func MapProcessIdentity(m RenderableNode, _ report.Networks) RenderableNodes {
	pid, ok := m.Metadata[process.PID]
	if !ok {
		return RenderableNodes{}
	}

	var (
		id    = MakeProcessID(report.ExtractHostID(m.Node), pid)
		major = m.Metadata["comm"]
		minor = fmt.Sprintf("%s (%s)", report.ExtractHostID(m.Node), pid)
		rank  = m.Metadata["comm"]
	)

	return RenderableNodes{id: NewRenderableNodeWith(id, major, minor, rank, m)}
}
開發者ID:webwurst,項目名稱:scope,代碼行數:18,代碼來源:mapping.go

示例9: MapProcessIdentity

// MapProcessIdentity maps a process topology node to a process renderable
// node. As it is only ever run on process topology nodes, we expect that
// certain keys are present.
func MapProcessIdentity(m report.NodeMetadata) (RenderableNode, bool) {
	pid, ok := m.Metadata[process.PID]
	if !ok {
		return RenderableNode{}, false
	}

	var (
		id    = MakeProcessID(report.ExtractHostID(m), pid)
		major = m.Metadata["comm"]
		minor = fmt.Sprintf("%s (%s)", report.ExtractHostID(m), pid)
		rank  = m.Metadata["comm"]
	)

	return NewRenderableNode(id, major, minor, rank, m), true
}
開發者ID:barravi,項目名稱:scope,代碼行數:18,代碼來源:mapping.go

示例10: Render

func (r processWithContainerNameRenderer) Render(rpt report.Report) RenderableNodes {
	processes := r.Renderer.Render(rpt)
	containers := Map{
		MapFunc:  MapContainerIdentity,
		Renderer: SelectContainer,
	}.Render(rpt)

	for id, p := range processes {
		pid, ok := p.Node.Metadata[process.PID]
		if !ok {
			continue
		}
		containerID, ok := p.Node.Metadata[docker.ContainerID]
		if !ok {
			continue
		}
		container, ok := containers[MakeContainerID(containerID)]
		if !ok {
			continue
		}
		p.LabelMinor = fmt.Sprintf("%s (%s:%s)", report.ExtractHostID(p.Node), container.LabelMajor, pid)
		processes[id] = p
	}

	return processes
}
開發者ID:rnd-ua,項目名稱:scope,代碼行數:26,代碼來源:topologies.go

示例11: Render

// Render produces a process graph where the minor labels contain the
// container name, if found.
func (r ProcessWithContainerNameRenderer) Render(rpt report.Report) RenderableNodes {
	processes := ProcessRenderer.Render(rpt)
	containers := LeafMap{
		Selector: report.SelectContainer,
		Mapper:   MapContainerIdentity,
		Pseudo:   PanicPseudoNode,
	}.Render(rpt)

	for id, p := range processes {
		pid, ok := p.NodeMetadata.Metadata[process.PID]
		if !ok {
			continue
		}
		containerID, ok := p.NodeMetadata.Metadata[docker.ContainerID]
		if !ok {
			continue
		}
		container, ok := containers[containerID]
		if !ok {
			continue
		}
		p.LabelMinor = fmt.Sprintf("%s (%s:%s)", report.ExtractHostID(p.NodeMetadata), container.LabelMajor, pid)
		processes[id] = p
	}

	return processes
}
開發者ID:cgvarela,項目名稱:scope,代碼行數:29,代碼來源:topologies.go

示例12: MapProcess2Container

// MapProcess2Container maps process Nodes to container
// Nodes.
//
// If this function is given a node without a docker_container_id
// (including other pseudo nodes), it will produce an "Uncontained"
// pseudo node.
//
// Otherwise, this function will produce a node with the correct ID
// format for a container, but without any Major or Minor labels.
// It does not have enough info to do that, and the resulting graph
// must be merged with a container graph to get that info.
func MapProcess2Container(n report.Node, _ report.Networks) report.Nodes {
	// Propagate pseudo nodes
	if n.Topology == Pseudo {
		return report.Nodes{n.ID: n}
	}

	// Otherwise, if the process is not in a container, group it
	// into an per-host "Uncontained" node.  If for whatever reason
	// this node doesn't have a host id in their nodemetadata, it'll
	// all get grouped into a single uncontained node.
	var (
		id   string
		node report.Node
	)
	if containerID, ok := n.Latest.Lookup(docker.ContainerID); ok {
		id = report.MakeContainerNodeID(containerID)
		node = NewDerivedNode(id, n).WithTopology(report.Container)
	} else {
		id = MakePseudoNodeID(UncontainedID, report.ExtractHostID(n))
		node = NewDerivedPseudoNode(id, n)
		node = propagateLatest(report.HostNodeID, n, node)
		node = propagateLatest(IsConnected, n, node)
	}
	return report.Nodes{id: node}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:36,代碼來源:container.go

示例13: MapProcess2Container

// MapProcess2Container maps process RenderableNodes to container
// RenderableNodes.
//
// If this function is given a node without a docker_container_id
// (including other pseudo nodes), it will produce an "Uncontained"
// pseudo node.
//
// Otherwise, this function will produce a node with the correct ID
// format for a container, but without any Major or Minor labels.
// It does not have enough info to do that, and the resulting graph
// must be merged with a container graph to get that info.
func MapProcess2Container(n RenderableNode, _ report.Networks) RenderableNodes {
	// Propogate the internet pseudo node
	if n.ID == TheInternetID {
		return RenderableNodes{n.ID: n}
	}

	// Don't propogate non-internet pseudo nodes
	if n.Pseudo {
		return RenderableNodes{}
	}

	// Otherwise, if the process is not in a container, group it
	// into an per-host "Uncontained" node.  If for whatever reason
	// this node doesn't have a host id in their nodemetadata, it'll
	// all get grouped into a single uncontained node.
	id, ok := n.Node.Metadata[docker.ContainerID]
	if !ok {
		hostID := report.ExtractHostID(n.Node)
		id = MakePseudoNodeID(UncontainedID, hostID)
		node := newDerivedPseudoNode(id, UncontainedMajor, n)
		node.LabelMinor = hostID
		return RenderableNodes{id: node}
	}

	return RenderableNodes{id: NewDerivedNode(id, n)}
}
開發者ID:webwurst,項目名稱:scope,代碼行數:37,代碼來源:mapping.go

示例14: MapProcess2Container

// MapProcess2Container maps process RenderableNodes to container
// RenderableNodes.
//
// If this function is given a node without a docker_container_id
// (including other pseudo nodes), it will produce an "Uncontained"
// pseudo node.
//
// Otherwise, this function will produce a node with the correct ID
// format for a container, but without any Major or Minor labels.
// It does not have enough info to do that, and the resulting graph
// must be merged with a container graph to get that info.
func MapProcess2Container(n RenderableNode, _ report.Networks) RenderableNodes {
	// Propogate the internet pseudo node
	if n.ID == TheInternetID {
		return RenderableNodes{n.ID: n}
	}

	// Don't propogate non-internet pseudo nodes
	if n.Pseudo {
		return RenderableNodes{}
	}

	// Otherwise, if the process is not in a container, group it
	// into an per-host "Uncontained" node.  If for whatever reason
	// this node doesn't have a host id in their nodemetadata, it'll
	// all get grouped into a single uncontained node.
	var (
		id     string
		node   RenderableNode
		hostID = report.ExtractHostID(n.Node)
	)
	n = n.WithParents(report.EmptySets)
	if containerID, ok := n.Node.Latest.Lookup(docker.ContainerID); ok {
		id = MakeContainerID(containerID)
		node = NewDerivedNode(id, n)
	} else {
		nCopy := n.Copy()
		nCopy.Node = nCopy.Node.WithID("").WithTopology("") // Wipe the ID so it cannot be rendered.
		id = MakePseudoNodeID(UncontainedID, hostID)
		node = newDerivedPseudoNode(id, UncontainedMajor, nCopy)
		node.LabelMinor = hostID
	}

	node.Children = node.Children.Add(n.Node)
	return RenderableNodes{id: node}
}
開發者ID:pauloheck,項目名稱:scope,代碼行數:46,代碼來源:mapping.go

示例15: MapAddress2Host

// MapAddress2Host maps address RenderableNodes to host RenderableNodes.
//
// Otherthan pseudo nodes, we can assume all nodes have a HostID
func MapAddress2Host(n RenderableNode) (RenderableNode, bool) {
	if n.Pseudo {
		return n, true
	}

	id := MakeHostID(report.ExtractHostID(n.NodeMetadata))
	return newDerivedNode(id, n), true
}
開發者ID:barravi,項目名稱:scope,代碼行數:11,代碼來源:mapping.go


注:本文中的github.com/weaveworks/scope/report.ExtractHostID函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。