forked from skydive-project/skydive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopology_probes.go
178 lines (158 loc) · 4.93 KB
/
topology_probes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy ofthe License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specificlanguage governing permissions and
* limitations under the License.
*
*/
package agent
import (
"fmt"
"runtime"
"github.com/skydive-project/skydive/config"
"github.com/skydive-project/skydive/graffiti/graph"
"github.com/skydive-project/skydive/graffiti/logging"
"github.com/skydive-project/skydive/plugin"
"github.com/skydive-project/skydive/probe"
"github.com/skydive-project/skydive/topology"
tp "github.com/skydive-project/skydive/topology/probes"
"github.com/skydive-project/skydive/topology/probes/bess"
"github.com/skydive-project/skydive/topology/probes/blockdev"
"github.com/skydive-project/skydive/topology/probes/docker"
"github.com/skydive-project/skydive/topology/probes/hardware"
"github.com/skydive-project/skydive/topology/probes/libvirt"
"github.com/skydive-project/skydive/topology/probes/lldp"
"github.com/skydive-project/skydive/topology/probes/lxd"
"github.com/skydive-project/skydive/topology/probes/netlink"
"github.com/skydive-project/skydive/topology/probes/netns"
"github.com/skydive-project/skydive/topology/probes/neutron"
"github.com/skydive-project/skydive/topology/probes/opencontrail"
"github.com/skydive-project/skydive/topology/probes/ovn"
"github.com/skydive-project/skydive/topology/probes/ovsdb"
"github.com/skydive-project/skydive/topology/probes/runc"
"github.com/skydive-project/skydive/topology/probes/socketinfo"
"github.com/skydive-project/skydive/topology/probes/vpp"
)
func registerStaticProbes() {
blockdev.Register()
netlink.Register()
topology.RegisterContainer()
lldp.Register()
lxd.Register()
neutron.Register()
opencontrail.Register()
ovsdb.Register()
libvirt.Register()
ovn.Register()
hardware.Register()
}
// NewTopologyProbe creates a new topology probe
func NewTopologyProbe(name string, ctx tp.Context, bundle *probe.Bundle) (probe.Handler, error) {
switch name {
case "blockdev":
return blockdev.NewProbe(ctx, bundle)
case "netlink":
return netlink.NewProbe(ctx, bundle)
case "netns":
return netns.NewProbe(ctx, bundle)
case "ovsdb":
return ovsdb.NewProbe(ctx, bundle)
case "lxd":
return lxd.NewProbe(ctx, bundle)
case "docker":
return docker.NewProbe(ctx, bundle)
case "lldp":
return lldp.NewProbe(ctx, bundle)
case "neutron":
return neutron.NewProbe(ctx, bundle)
case "opencontrail":
return opencontrail.NewProbe(ctx, bundle)
case "socketinfo":
return socketinfo.NewProbe(ctx, bundle)
case "libvirt":
return libvirt.NewProbe(ctx, bundle)
case "runc":
return runc.NewProbe(ctx, bundle)
case "vpp":
return vpp.NewProbe(ctx, bundle)
case "bess":
return bess.NewProbe(ctx, bundle)
case "hardware":
return hardware.NewProbe(ctx, bundle)
default:
return nil, fmt.Errorf("unsupported probe %s", name)
}
}
func loadPluginProbes(ctx tp.Context, bundle *probe.Bundle) error {
plugins, err := plugin.LoadTopologyPlugins()
if err != nil {
return err
}
for _, p := range plugins {
p.Register()
}
// then register agent plugins
for _, p := range plugins {
if p.AgentCtor != nil {
handler, err := p.AgentCtor(ctx, bundle)
if err != nil {
return fmt.Errorf("Failed to instantiate plugin %s: %s", p.Name, err)
}
bundle.AddHandler(p.Name, handler)
}
}
return nil
}
// NewTopologyProbeBundle creates a new topology probe.Bundle based on the configuration
func NewTopologyProbeBundle(g *graph.Graph, hostNode *graph.Node) (*probe.Bundle, error) {
registerStaticProbes()
ctx := tp.Context{
Logger: logging.GetLogger(),
Config: config.GetConfig(),
Graph: g,
RootNode: hostNode,
}
bundle := probe.NewBundle()
if err := loadPluginProbes(ctx, bundle); err != nil {
return nil, err
}
probeList := []string{"hardware"}
if runtime.GOOS == "linux" {
probeList = append(probeList, "netlink", "netns")
}
probeList = append(probeList, config.GetStringSlice("agent.topology.probes")...)
logging.GetLogger().Infof("Topology probes: %v", probeList)
if runtime.GOOS == "linux" {
nlHandler, err := NewTopologyProbe("netlink", ctx, bundle)
if err != nil {
return nil, err
}
bundle.AddHandler("netlink", nlHandler)
nsHandler, err := NewTopologyProbe("netns", ctx, bundle)
if err != nil {
return nil, err
}
bundle.AddHandler("netns", nsHandler)
}
for _, t := range probeList {
if bundle.GetHandler(t) != nil {
continue
}
handler, err := NewTopologyProbe(t, ctx, bundle)
if err != nil {
return nil, err
} else if handler != nil {
bundle.AddHandler(t, handler)
}
}
return bundle, nil
}