Skip to content

Commit

Permalink
server: feature, add clear hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskaliX committed Mar 3, 2024
1 parent c5b3d58 commit f3bb46c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 217 deletions.
27 changes: 22 additions & 5 deletions server/webconsole/api/grpc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ func AgentBasic(c *gin.Context) {
continue
}
detail := as.AgentDetail
var cpu, rss float64
cpu = detail["cpu"].(float64)
rss = detail["rss"].(float64)
cpu, ok1 := detail["cpu"].(float64)
rss, ok2 := detail["rss"].(float64)
if !ok1 || !ok2 {
continue
}

tmp := AgentBasicResp{
AgentID: as.AgentID,
Expand All @@ -144,5 +146,20 @@ func AgentBasic(c *gin.Context) {

// clear the agent plugins
func AgentClear(c *gin.Context) {

}
filter := bson.M{}
// delete specific agent id
if agentId, ok := c.GetQuery("agent_id"); ok {
filter["agent_id"] = agentId
} else {
// clear the agent by it's heartbeat
filter["last_heartbeat_time"] = bson.M{
"$lt": time.Now().AddDate(0, 0, -7).Unix(),
}
}
deleteResult, err := mongo.MongoProxyImpl.StatusC.DeleteMany(context.TODO(), filter)
if err != nil {
common.Response(c, common.ErrorCode, err)
}
fmt.Printf("Deleted %d documents\n", deleteResult.DeletedCount)
common.Response(c, common.SuccessCode, deleteResult.DeletedCount)
}
14 changes: 9 additions & 5 deletions server/webconsole/api/host/application/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ func ContainerTop(c *gin.Context) {
if req.State == "" {
match = bson.M{"$match": bson.M{
"$and": []bson.M{
bson.M{"data_type": 3018},
bson.M{"update_time": bson.M{"$gt": time.Now().Unix() - 24*60*60}},
{"data_type": 3018},
{"update_time": bson.M{"$gt": time.Now().Unix() - 24*60*60}},
},
}}
} else {
match = bson.M{"$match": bson.M{
"$and": []bson.M{
bson.M{"data_type": 3018},
bson.M{"state": req.State},
bson.M{"update_time": bson.M{"$gt": time.Now().Unix() - 24*60*60}},
{"data_type": 3018},
{"state": req.State},
{"update_time": bson.M{"$gt": time.Now().Unix() - 24*60*60}},
},
}}
}
Expand All @@ -90,6 +90,10 @@ func ContainerTop(c *gin.Context) {
cur.Decode(&temp)
resp.Top = append(resp.Top, temp)
}
// fullfill the top
if len(resp.Top) < 3 {
resp.Top = append(resp.Top, make([]top, 3-len(resp.Top))...)
}

common.Response(c, common.SuccessCode, resp)
}
1 change: 1 addition & 0 deletions server/webconsole/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func RunGrpcServer(port int) {
rGroup.GET("/conn/count", gApi.AgentCount)
rGroup.GET("/conn/stat", gApi.AgentStat)
rGroup.GET("/conn/basic", gApi.AgentBasic)
rGroup.GET("/conn/delete", gApi.AgentClear)
}
{
gGroup := apiv1Router.Group("/plugin")
Expand Down
2 changes: 1 addition & 1 deletion server/webconsole/api/static/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body>
<div id="root"></div>
<script src="/umi.c652ca09.js"></script>
<script src="/umi.c02565f4.js"></script>

</body></html>

This file was deleted.

This file was deleted.

This file was deleted.

197 changes: 0 additions & 197 deletions server/webconsole/api/static/frontend/umi.c652ca09.js

This file was deleted.

13 changes: 7 additions & 6 deletions server/webconsole/grpc/transfer/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
type TransferHandler struct{}

func (h *TransferHandler) Transfer(stream pb.Transfer_TransferServer) (err error) {
var agentID string
var addr string
var agentID, addr string
var data *pb.RawData

// Receive the very first package once grpc established
data, err := stream.Recv()
if err != nil {
// receive the very first package once grpc established
if data, err = stream.Recv(); err != nil {
return err
}

Expand All @@ -40,7 +39,7 @@ func (h *TransferHandler) Transfer(stream pb.Transfer_TransferServer) (err error
addr = p.Addr.String()
fmt.Printf("Get connection %s from %s\n", agentID, addr)

// Initialize the connection
// initialize the connection
ctx, cancelFunc := context.WithCancel(context.Background())
conn := pool.Connection{
AgentID: agentID,
Expand All @@ -50,6 +49,8 @@ func (h *TransferHandler) Transfer(stream pb.Transfer_TransferServer) (err error
Ctx: ctx,
CancelFunc: cancelFunc,
}

// add into the grpc pool
if err = pool.GlobalGRPCPool.Add(agentID, &conn); err != nil {
return err
}
Expand Down

0 comments on commit f3bb46c

Please sign in to comment.