Skip to content

Commit 306ba3a

Browse files
committed
1. modify event
2. start process loop
1 parent 5d7d2f6 commit 306ba3a

File tree

110 files changed

+7941
-1933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+7941
-1933
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.12
44

55
require (
66
github.com/gin-gonic/gin v1.4.0
7+
github.com/sirupsen/logrus v1.4.2
78
github.com/urfave/cli v1.22.1
89
)

go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
22
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
33
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
4+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
45
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
58
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g=
69
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
710
github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=
@@ -10,30 +13,43 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
1013
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1114
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
1215
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
16+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
17+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
1318
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
1419
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
1520
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
1621
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
1722
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
1823
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
24+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1925
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2026
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
2127
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
2228
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
2329
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
30+
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
31+
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
2432
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
33+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
34+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
35+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
2536
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2637
github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
2738
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
2839
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
2940
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
3041
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
42+
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c h1:uOCk1iQW6Vc18bnC13MfzScl+wdKBmM9Y9kU7Z83/lw=
3143
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3244
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3345
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
3446
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
47+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
48+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3549
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3651
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
52+
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
3753
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
3854
gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=
3955
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=

log/log.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package log
2+
3+
import (
4+
"os"
5+
6+
"github.com/sirupsen/logrus"
7+
)
8+
9+
// L is the overall logger
10+
var L = logrus.New()
11+
12+
func init() {
13+
L.SetOutput(os.Stdout)
14+
L.SetLevel(logrus.InfoLevel)
15+
}

server/controller/container/container.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ type ContainerController struct {
1414
ec chan sysdig.Event
1515

1616
// containers
17-
containers map[string]model.Container
17+
containers map[string]*model.Container
18+
// container process channels
19+
containerCh map[string]chan sysdig.Event
1820
}
1921

2022
func NewController(ec chan sysdig.Event) controller.Controller {
2123
r := router.NewGroupRouter("/container")
24+
res := &ContainerController{containerRouter: r, ec: ec, containers: map[string]*model.Container{}}
25+
res.initRouter()
26+
return res
27+
}
28+
29+
var _ controller.Controller = &ContainerController{}
2230

31+
func (cc *ContainerController) BindedRoutes() []router.Route {
32+
return cc.containerRouter.Routes()
2333
}
2434

2535
func (cc *ContainerController) initRouter() {
26-
36+
// TODO
2737
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package container
2+
3+
import (
4+
"context"
5+
6+
"github.com/YLonely/sysdig-monitor/log"
7+
"github.com/YLonely/sysdig-monitor/server/model"
8+
"github.com/YLonely/sysdig-monitor/sysdig"
9+
)
10+
11+
func processLoop(ctx context.Context, c *model.Container, ch chan sysdig.Event) {
12+
log.L.WithField("container-id", c.ID).Info("process loop start.")
13+
for e := range ch {
14+
15+
}
16+
log.L.WithField("container-id", c.ID).Error("process loop unexpected exited.")
17+
}

sysdig/event.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ package sysdig
22

33
// Event represents a container event in sysdig
44
type Event struct {
5-
ID string `json:"container.id"`
6-
Name string `json:"container.name"`
7-
CPUId int `json:"evt.cpu"`
8-
Dir string `json:"evt.dir"`
9-
Info string `json:"evt.info"`
10-
Num int `json:"evt.num"`
11-
TimeStamp int64 `json:"evt.outputtime"`
12-
Type string `json:"evt.type"`
5+
ContainerID string `json:"container.id"`
6+
ContainerName string `json:"container.name"`
7+
EventCPU int `json:"evt.cpu"`
8+
EventDir string `json:"evt.dir"`
9+
EventInfo string `json:"evt.info"`
10+
EventNum int `json:"evt.num"`
11+
EventOutputTime int64 `json:"evt.outputtime"`
12+
EventType string `json:"evt.type"`
13+
FdName string `json:"fd.name"`
14+
FdType string `json:"fd.type"`
15+
EventIsIORead bool `json:"evt.is_io_read"`
16+
EventIsIOWrite bool `json:"evt.is_io_write"`
17+
EventBuffer string `json:"evt.buffer"`
18+
EventBuflen int `json:"evt.buflen"`
1319
ProcName string `json:"proc.name"`
1420
ThreadID int `json:"thread.tid"`
1521
ThreadVirtualID int `json:"thread.vid"`
22+
EventLatency int `json:"evt.latency"`
1623
}
1724

1825
type subscriber struct {
@@ -27,4 +34,4 @@ func (s *subscriber) close() {
2734
close(s.c)
2835
s.closed = true
2936
return
30-
}
37+
}

sysdig/sysdig.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ import (
66
"errors"
77
"io"
88
"os/exec"
9+
10+
"github.com/YLonely/sysdig-monitor/log"
911
)
1012

1113
const binaryName = "sysdig"
1214
const bufferSize = 1024
15+
const formatString = "\"%evt.num %evt.outputtime %evt.cpu %thread.tid %thread.vtid %proc.name %evt.dir %evt.type %evt.info " +
16+
//container parts
17+
"%container.name %container.id " +
18+
//file or network parts
19+
"%fd.name %fd.type %evt.is_io_write %evt.is_io_read %evt.buffer %evt.buflen " +
20+
//performance
21+
"%evt.latency\""
1322

1423
// Server starts sysdig and dispatch events
1524
type Server interface {
@@ -35,11 +44,11 @@ func (ls *localServer) Subscribe() chan Event {
3544
}
3645

3746
func (ls *localServer) Start(ctx context.Context) error {
38-
if err := ls.preRrequestCheck(); err != nil {
47+
if err := ls.preRrequestCheck(ctx); err != nil {
48+
log.L.WithError(err).Error("sysdig server pre check failed.")
3949
return err
4050
}
41-
args := []string{"-pc", "-j", "container.id!=host"}
42-
cmd := exec.CommandContext(ctx, binaryName, args...)
51+
cmd := exec.CommandContext(ctx, binaryName, "-p", formatString, "-j")
4352
rd, err := cmd.StdoutPipe()
4453
if err != nil {
4554
return err
@@ -78,9 +87,9 @@ func (ls *localServer) Start(ctx context.Context) error {
7887
return nil
7988
}
8089

81-
func (ls *localServer) preRrequestCheck() error {
90+
func (ls *localServer) preRrequestCheck(ctx context.Context) error {
8291
//try run sysdig
83-
ctx, cancel := context.WithCancel(context.Background())
92+
ctx, cancel := context.WithCancel(ctx)
8493
cmd := exec.CommandContext(ctx, binaryName)
8594
var (
8695
ec chan Exit
@@ -91,9 +100,7 @@ func (ls *localServer) preRrequestCheck() error {
91100
cancel()
92101
return errors.New("can not start sysdig")
93102
}
94-
95103
cancel()
96-
97104
Monitor.Wait(cmd, ec)
98105

99106
return nil

vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/konsorten/go-windows-terminal-sequences/README.md

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/konsorten/go-windows-terminal-sequences/go.mod

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)