Skip to content

Commit 88f75de

Browse files
committed
Merge branch 'master' of github.com:YLonely/sysdig-monitor
2 parents 6ade885 + 5a32f45 commit 88f75de

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

server/controller/container/container.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ type ContainerController struct {
3333
}
3434

3535
type container struct {
36-
imageConfig types.ImageInspect
37-
m sync.RWMutex
36+
imageConfig *types.ImageInspect
37+
m sync.RWMutex
3838
*model.Container
3939
}
4040

41-
func newContainer(id, name string) *container {
41+
func newContainer(id, name string, imageConfig *types.ImageInspect) *container {
4242
c := model.NewContainer(id, name)
43-
return &container{Container: c}
43+
return &container{Container: c, imageConfig: imageConfig}
4444
}
4545

4646
const eventBufferLen = 512
@@ -104,7 +104,12 @@ func (cc *ContainerController) start(ctx context.Context) error {
104104
}
105105
log.L.Debug(ce)
106106
if _, exists := cc.containers[containerID]; !exists {
107-
container := newcontainer(ce.containerID, containerName)
107+
config, err := cc.imageConfig(ctx, ce.image)
108+
if err != nil {
109+
log.L.WithError(err).WithField("container-id", containerID).Error("cant fetch image config")
110+
continue
111+
}
112+
container := newContainer(ce.containerID, containerName, config)
108113
ch := make(chan containerEvent, eventBufferLen)
109114
cc.cm.Lock()
110115
cc.containers[containerID] = container
@@ -131,6 +136,14 @@ func (cc *ContainerController) start(ctx context.Context) error {
131136
return nil
132137
}
133138

139+
func (cc *ContainerController) imageConfig(ctx context.Context, id string) (*types.ImageInspect, error) {
140+
imageConfig, _, err := cc.dockerCli.ImageInspectWithRaw(ctx, id)
141+
if err != nil {
142+
return nil, err
143+
}
144+
return &imageConfig, nil
145+
}
146+
134147
func convert(e sysdig.Event) containerEvent {
135148
res := containerEvent{}
136149
res.containerID = e.ContainerID
@@ -146,5 +159,6 @@ func convert(e sysdig.Event) containerEvent {
146159
res.rawRes = e.RawRes
147160
res.syscallType = e.SyscallType
148161
res.virtualtid = e.ThreadVirtualID
162+
res.image = e.ContainerImage
149163
return res
150164
}

server/controller/container/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type containerEvent struct {
2929
rawRes int
3030
syscallType string
3131
virtualtid int
32+
image string
3233
}
3334

3435
func processLoop(ctx context.Context, c *container, ch chan containerEvent) error {

sysdig/event.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "time"
66
type Event struct {
77
ContainerID string `json:"container.id"`
88
ContainerName string `json:"container.name"`
9+
ContainerImage string `json:"container.image"`
910
EventCPU int `json:"evt.cpu"`
1011
EventDir string `json:"evt.dir"`
1112
EventInfo string `json:"evt.info"`

0 commit comments

Comments
 (0)