From 41194140796caf5d8509367e3266767b9e240010 Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Thu, 21 Jan 2021 20:18:16 +0800 Subject: [PATCH 1/2] add tree search by user --- src/modules/rdb/http/router.go | 1 + src/modules/rdb/http/router_tree.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/modules/rdb/http/router.go b/src/modules/rdb/http/router.go index 17aebdfe..2e77ca94 100644 --- a/src/modules/rdb/http/router.go +++ b/src/modules/rdb/http/router.go @@ -172,6 +172,7 @@ func Config(r *gin.Engine) { v1.GET("/node/:id", nodeGet) v1.GET("/node/:id/projs", v1treeUntilProjectGetsByNid) v1.GET("/tree/projs", v1TreeUntilProjectGets) + v1.GET("/tree", v1TreeUntilTypGets) // 外部系统推送一些操作日志过来,RDB统一存储,实际用MQ会更好一些 v1.POST("/resoplogs", v1OperationLogResPost) diff --git a/src/modules/rdb/http/router_tree.go b/src/modules/rdb/http/router_tree.go index b2684264..fee286e4 100644 --- a/src/modules/rdb/http/router_tree.go +++ b/src/modules/rdb/http/router_tree.go @@ -160,6 +160,35 @@ func v1TreeUntilProjectGets(c *gin.Context) { renderData(c, oks, err) } +func v1TreeUntilTypGets(c *gin.Context) { + username := queryStr(c, "username") + cate := queryStr(c, "cate") + onlyCate := queryInt(c, "onlyCate", 0) + pid := queryInt64(c, "pid", -1) + user, err := models.UserGet("username=?", username) + dangerous(err) + + oks, err := models.TreeUntilTypGetByUser(user, cate) + dangerous(err) + + var ret []models.Node + for _, node := range oks { + //指定了父节点,不是想要的父节点 + if pid != -1 && node.Pid != pid { + continue + } + + //指定了节点类型,不是想要的节点类型 + if onlyCate != 0 && node.Cate != cate { + continue + } + + ret = append(ret, node) + } + + renderData(c, ret, err) +} + // 这个方法,展示的树只到organization func treeUntilOrganizationGets(c *gin.Context) { me := loginUser(c) From 2f87121e272fbb7cc781920329ba51d0ea7e8760 Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Thu, 21 Jan 2021 20:23:13 +0800 Subject: [PATCH 2/2] fix typo --- src/modules/agent/sys/procs/scheduler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/agent/sys/procs/scheduler.go b/src/modules/agent/sys/procs/scheduler.go index 85136834..182f9d48 100644 --- a/src/modules/agent/sys/procs/scheduler.go +++ b/src/modules/agent/sys/procs/scheduler.go @@ -107,8 +107,8 @@ func ProcCollect(p *models.ProcCollect) { } procNumItem := core.GaugeValue("proc.num", cnt, p.Tags) - procFdItem := core.GaugeValue("proc.uptime", uptime, p.Tags) - procUptimeItem := core.GaugeValue("proc.fdnum", fdNum, p.Tags) + procUptimeItem := core.GaugeValue("proc.uptime", uptime, p.Tags) + procFdItem := core.GaugeValue("proc.fdnum", fdNum, p.Tags) memUsedItem := core.GaugeValue("proc.mem.used", memory*1024, p.Tags) ioReadItem := core.GaugeValue("proc.io.read.bytes", ioRead, p.Tags) ioWriteItem := core.GaugeValue("proc.io.write.bytes", ioWrite, p.Tags)