示例#1
0
// OverlayTopology produces an overlay topology from the Weave router.
func (t WeaveTagger) OverlayTopology() report.Topology {
	topology := report.NewTopology()

	resp, err := http.Get(t.url)
	if err != nil {
		log.Printf("Weave Tagger: %v", err)
		return topology
	}
	defer resp.Body.Close()

	var status struct {
		Peers []struct {
			Name     string `json:"Name"`
			NickName string `json:"NickName"`
		} `json:"Peers"`
	}
	if err := json.NewDecoder(resp.Body).Decode(&status); err != nil {
		log.Printf("Weave Tagger: %v", err)
		return topology
	}

	for _, peer := range status.Peers {
		topology.NodeMetadatas[report.MakeOverlayNodeID(peer.Name)] = report.NodeMetadata{
			WeavePeerName:     peer.Name,
			WeavePeerNickName: peer.NickName,
		}
	}

	return topology
}
示例#2
0
文件: reporter.go 项目: davkal/scope
func (r *Reporter) containerTopology() report.Topology {
	result := report.NewTopology()

	r.registry.WalkContainers(func(c Container) {
		nodeID := report.MakeContainerNodeID(r.scope, c.ID())
		result.NodeMetadatas[nodeID] = c.GetNodeMetadata()
	})

	return result
}
示例#3
0
// Make sure we don't add a topology and miss it in the Topologies method.
func TestReportTopologies(t *testing.T) {
	var (
		reportType   = reflect.TypeOf(report.MakeReport())
		topologyType = reflect.TypeOf(report.NewTopology())
	)

	var want int
	for i := 0; i < reportType.NumField(); i++ {
		if reportType.Field(i).Type == topologyType {
			want++
		}
	}

	if have := len(report.MakeReport().Topologies()); want != have {
		t.Errorf("want %d, have %d", want, have)
	}
}
示例#4
0
文件: reporter.go 项目: davkal/scope
func (r *Reporter) containerImageTopology() report.Topology {
	result := report.NewTopology()

	r.registry.WalkImages(func(image *docker_client.APIImages) {
		nmd := report.NodeMetadata{
			ImageID: image.ID,
		}

		if len(image.RepoTags) > 0 {
			nmd[ImageName] = image.RepoTags[0]
		}

		nodeID := report.MakeContainerNodeID(r.scope, image.ID)
		result.NodeMetadatas[nodeID] = nmd
	})

	return result
}
示例#5
0
文件: reporter.go 项目: barravi/scope
func (r *Reporter) processTopology() (report.Topology, error) {
	t := report.NewTopology()
	err := r.walker.Walk(func(p Process) {
		pidstr := strconv.Itoa(p.PID)
		nodeID := report.MakeProcessNodeID(r.scope, pidstr)
		t.NodeMetadatas[nodeID] = report.MakeNodeMetadataWith(map[string]string{
			PID:     pidstr,
			Comm:    p.Comm,
			Cmdline: p.Cmdline,
			Threads: strconv.Itoa(p.Threads),
		})
		if p.PPID > 0 {
			t.NodeMetadatas[nodeID].Metadata[PPID] = strconv.Itoa(p.PPID)
		}
	})

	return t, err
}
示例#6
0
文件: reporter.go 项目: davkal/scope
func (r *reporter) processTopology() (report.Topology, error) {
	t := report.NewTopology()
	err := Walk(r.procRoot, func(p *Process) {
		pidstr := strconv.Itoa(p.PID)
		nodeID := report.MakeProcessNodeID(r.scope, pidstr)
		t.NodeMetadatas[nodeID] = report.NodeMetadata{
			PID:     pidstr,
			Comm:    p.Comm,
			Cmdline: p.Cmdline,
			Threads: strconv.Itoa(p.Threads),
		}
		if p.PPID > 0 {
			t.NodeMetadatas[nodeID][PPID] = strconv.Itoa(p.PPID)
		}
	})

	return t, err
}