Skip to content

Commit 5d7d2f6

Browse files
committed
Add container controller
Add container model
1 parent cc0ac8a commit 5d7d2f6

File tree

6 files changed

+140
-47
lines changed

6 files changed

+140
-47
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package container
2+
3+
import (
4+
"github.com/YLonely/sysdig-monitor/server/controller"
5+
"github.com/YLonely/sysdig-monitor/server/model"
6+
"github.com/YLonely/sysdig-monitor/server/router"
7+
"github.com/YLonely/sysdig-monitor/sysdig"
8+
)
9+
10+
// Container represents a top level controller for container
11+
type ContainerController struct {
12+
containerRouter router.Router
13+
// event chan
14+
ec chan sysdig.Event
15+
16+
// containers
17+
containers map[string]model.Container
18+
}
19+
20+
func NewController(ec chan sysdig.Event) controller.Controller {
21+
r := router.NewGroupRouter("/container")
22+
23+
}
24+
25+
func (cc *ContainerController) initRouter() {
26+
27+
}

server/controller/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package controller
2+
3+
import (
4+
"github.com/YLonely/sysdig-monitor/server/router"
5+
)
6+
7+
type Controller interface {
8+
BindedRoutes() []router.Route
9+
}

server/model/container.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package model
2+
3+
import "time"
4+
5+
type Container struct {
6+
ID string
7+
8+
SystemCalls
9+
10+
FileSystem
11+
12+
Network
13+
}
14+
15+
type SystemCalls struct {
16+
// map system call name to SystemCall
17+
IndividualCalls map[string]SystemCall
18+
TotalCalls int64
19+
}
20+
21+
type FileSystem struct {
22+
// map file name to file
23+
AccessedFiles map[string]File
24+
// io calls whose latency is bigger than 1ms
25+
IOCalls1 []IOCall
26+
// io calls whose latency is bigger than 10ms
27+
IOCalls10 []IOCall
28+
// io calls whose latency is bigger than 100ms
29+
IOCalls100 []IOCall
30+
TotalReadIn int64
31+
TotalWriteOut int64
32+
}
33+
34+
type Network struct {
35+
ActiveConnections map[ConnectionMeta]Connection
36+
TotalReadIn, TotalWriteOut int64
37+
}
38+
39+
type SystemCall struct {
40+
Name string
41+
// total number of times it is invoked
42+
Calls int64
43+
TotalTime time.Duration
44+
}
45+
46+
type File struct {
47+
Name string
48+
WriteOut int64
49+
ReadIn int64
50+
}
51+
52+
type Connection struct {
53+
Type string
54+
ConnectionMeta
55+
WriteOut int64
56+
ReadIn int64
57+
}
58+
59+
type ConnectionMeta struct {
60+
SourceIP string
61+
DestIP string
62+
SourcePort int
63+
DestPort int
64+
}
65+
66+
type IOCall struct {
67+
FileName string
68+
Latency time.Duration
69+
}

server/router/container/container.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

server/router/local.go

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
11
package router
22

3-
type localRoute struct {
4-
method string
5-
path string
6-
handler HandlerType
3+
type router struct {
4+
routes []Route
75
}
86

9-
var _ Route = localRoute{}
7+
var _ Router = &router{}
108

11-
func (l localRoute) Method() string {
12-
return l.method
9+
func NewRouter() Router {
10+
return &router{}
1311
}
1412

15-
func (l localRoute) Path() string {
16-
return l.path
13+
func (r *router) Routes() []Route {
14+
return r.routes
1715
}
1816

19-
func (l localRoute) Handler() HandlerType {
20-
return l.handler
17+
func (r *router) AddRoute(path, method string, handler HandlerType) {
18+
r.routes = append(r.routes, route{method: method, path: path, handler: handler})
19+
}
20+
21+
type groupRouter struct {
22+
router
23+
prefix string
24+
}
25+
26+
var _ Router = &groupRouter{}
27+
28+
func NewGroupRouter(prefix string) Router {
29+
return &groupRouter{prefix: prefix}
2130
}
2231

23-
func NewRoute(method, path string, handler HandlerType) Route {
24-
return localRoute{method: method, path: path, handler: handler}
32+
func (gr *groupRouter) AddRoute(path, method string, handler HandlerType) {
33+
gr.routes = append(gr.routes, route{path: gr.prefix + path, method: method, handler: handler})
2534
}
2635

27-
func NewGetRoute(method, path string, handler HandlerType) Route {
28-
return NewRoute(MethodGet, path, handler)
36+
type route struct {
37+
method string
38+
path string
39+
handler HandlerType
2940
}
3041

31-
func NewPostRoute(method, path string, handler HandlerType) Route {
32-
return NewRoute(MethodPost, path, handler)
42+
var _ Route = &route{}
43+
44+
func (l route) Method() string {
45+
return l.method
3346
}
3447

35-
func NewPutRoute(method, path string, handler HandlerType) Route {
36-
return NewRoute(MethodPut, path, handler)
48+
func (l route) Path() string {
49+
return l.path
3750
}
3851

39-
func NewDeleteRoute(method, path string, handler HandlerType) Route {
40-
return NewRoute(MethodDelete, path, handler)
52+
func (l route) Handler() HandlerType {
53+
return l.handler
4154
}

server/router/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type HandlerType func(c *gin.Context)
99
// Router defines an interface to specify a group of routes ot add to the server
1010
type Router interface {
1111
Routes() []Route
12+
AddRoute(path, method string, handler HandlerType)
1213
}
1314

1415
// Route defines an individual API route in the sysdig-monitor server

0 commit comments

Comments
 (0)