aboutsummaryrefslogtreecommitdiffstats
path: root/listener/deal.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--listener/deal.go35
1 files changed, 4 insertions, 31 deletions
diff --git a/listener/deal.go b/listener/deal.go
index 70c2827..af65ff8 100644
--- a/listener/deal.go
+++ b/listener/deal.go
@@ -10,17 +10,8 @@ import (
10 "go.mongodb.org/mongo-driver/bson" 10 "go.mongodb.org/mongo-driver/bson"
11) 11)
12 12
13const (
14 dbName string = "test"
15 pidColName string = "pids"
16 fdColName string = "fds"
17 fileColName string = "files"
18)
19
20var pidCol, fdCol, fileCol mongoClient
21
22func initPidCol() (err error) { 13func initPidCol() (err error) {
23 // TODO: 这里是否需要补全一下进程信息? 14 // 这里是否需要补全一下进程信息?
24 dirs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", containerdPid)) 15 dirs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", containerdPid))
25 if err != nil { 16 if err != nil {
26 return err 17 return err
@@ -41,6 +32,9 @@ func initPidCol() (err error) {
41 process.Star = true 32 process.Star = true
42 } 33 }
43 err = pidCol.InsertOne(process) 34 err = pidCol.InsertOne(process)
35 if err != nil {
36 return err
37 }
44 } 38 }
45 return nil 39 return nil
46} 40}
@@ -49,27 +43,6 @@ func deal() {
49 defer wg.Done() 43 defer wg.Done()
50 var cooked Event 44 var cooked Event
51 var ok bool 45 var ok bool
52 var err error
53
54 if err = pidCol.init(dbName, pidColName); err != nil {
55 fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err)
56 return
57 }
58 if err = initPidCol(); err != nil {
59 fmt.Fprintf(os.Stderr, "Err while initing pidcol: %v\n", err)
60 }
61
62 if err = fdCol.init(dbName, fdColName); err != nil {
63 fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err)
64 return
65 }
66 if err = fileCol.init(dbName, fileColName); err != nil {
67 fmt.Fprintf(os.Stderr, "Error while initing the mongodb: %v\n", err)
68 }
69
70 defer pidCol.Disconnect()
71 defer fdCol.Disconnect()
72 defer fileCol.Disconnect()
73 46
74 for { 47 for {
75 cooked, ok = <-cookedChan 48 cooked, ok = <-cookedChan