Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
2dc31e98
N
nightingale
项目概览
DiDi
/
nightingale
8 个月 前同步成功
通知
45
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2dc31e98
编写于
7月 25, 2023
作者:
N
ning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support markdown api and downtime select
上级
60b76b9c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
13 deletion
+43
-13
center/router/router.go
center/router/router.go
+1
-0
center/router/router_builtin.go
center/router/router_builtin.go
+23
-0
center/router/router_target.go
center/router/router_target.go
+9
-8
models/target.go
models/target.go
+9
-5
prom/client.go
prom/client.go
+1
-0
未找到文件。
center/router/router.go
浏览文件 @
2dc31e98
...
...
@@ -243,6 +243,7 @@ func (rt *Router) Config(r *gin.Engine) {
pages
.
GET
(
"/builtin-boards-cates"
,
rt
.
auth
(),
rt
.
user
(),
rt
.
builtinBoardCateGets
)
pages
.
POST
(
"/builtin-boards-detail"
,
rt
.
auth
(),
rt
.
user
(),
rt
.
builtinBoardDetailGets
)
pages
.
GET
(
"/integrations/icon/:cate/:name"
,
rt
.
builtinIcon
)
pages
.
GET
(
"/integrations/makedown/:cate"
,
rt
.
builtinMarkdown
)
pages
.
GET
(
"/busi-group/:id/boards"
,
rt
.
auth
(),
rt
.
user
(),
rt
.
perm
(
"/dashboards"
),
rt
.
bgro
(),
rt
.
boardGets
)
pages
.
POST
(
"/busi-group/:id/boards"
,
rt
.
auth
(),
rt
.
user
(),
rt
.
perm
(
"/dashboards/add"
),
rt
.
bgrw
(),
rt
.
boardAdd
)
...
...
center/router/router_builtin.go
浏览文件 @
2dc31e98
...
...
@@ -315,3 +315,26 @@ func (rt *Router) builtinIcon(c *gin.Context) {
iconPath
:=
fp
+
"/"
+
cate
+
"/icon/"
+
ginx
.
UrlParamStr
(
c
,
"name"
)
c
.
File
(
path
.
Join
(
iconPath
))
}
func
(
rt
*
Router
)
builtinMarkdown
(
c
*
gin
.
Context
)
{
fp
:=
rt
.
Center
.
BuiltinIntegrationsDir
if
fp
==
""
{
fp
=
path
.
Join
(
runner
.
Cwd
,
"integrations"
)
}
cate
:=
ginx
.
UrlParamStr
(
c
,
"cate"
)
var
markdown
[]
byte
markdownDir
:=
fp
+
"/"
+
cate
+
"/markdown"
markdownFiles
,
err
:=
file
.
FilesUnder
(
markdownDir
)
if
err
!=
nil
{
logger
.
Warningf
(
"get markdown fail: %v"
,
err
)
}
else
if
len
(
markdownFiles
)
>
0
{
f
:=
markdownFiles
[
0
]
fn
:=
markdownDir
+
"/"
+
f
markdown
,
err
=
file
.
ReadBytes
(
fn
)
if
err
!=
nil
{
logger
.
Warningf
(
"get collect fail: %v"
,
err
)
}
}
ginx
.
NewRender
(
c
)
.
Data
(
string
(
markdown
),
nil
)
}
center/router/router_target.go
浏览文件 @
2dc31e98
...
...
@@ -45,6 +45,7 @@ func (rt *Router) targetGets(c *gin.Context) {
bgid
:=
ginx
.
QueryInt64
(
c
,
"bgid"
,
-
1
)
query
:=
ginx
.
QueryStr
(
c
,
"query"
,
""
)
limit
:=
ginx
.
QueryInt
(
c
,
"limit"
,
30
)
downtime
:=
ginx
.
QueryInt64
(
c
,
"downtime"
,
0
)
dsIds
:=
queryDatasourceIds
(
c
)
var
bgids
[]
int64
...
...
@@ -64,10 +65,10 @@ func (rt *Router) targetGets(c *gin.Context) {
bgids
=
append
(
bgids
,
bgid
)
}
total
,
err
:=
models
.
TargetTotal
(
rt
.
Ctx
,
bgids
,
dsIds
,
query
)
total
,
err
:=
models
.
TargetTotal
(
rt
.
Ctx
,
bgids
,
dsIds
,
query
,
downtime
)
ginx
.
Dangerous
(
err
)
list
,
err
:=
models
.
TargetGets
(
rt
.
Ctx
,
bgids
,
dsIds
,
query
,
limit
,
ginx
.
Offset
(
c
,
limit
))
list
,
err
:=
models
.
TargetGets
(
rt
.
Ctx
,
bgids
,
dsIds
,
query
,
downtime
,
limit
,
ginx
.
Offset
(
c
,
limit
))
ginx
.
Dangerous
(
err
)
if
err
==
nil
{
...
...
@@ -78,6 +79,12 @@ func (rt *Router) targetGets(c *gin.Context) {
for
i
:=
0
;
i
<
len
(
list
);
i
++
{
ginx
.
Dangerous
(
list
[
i
]
.
FillGroup
(
rt
.
Ctx
,
cache
))
keys
=
append
(
keys
,
models
.
WrapIdent
(
list
[
i
]
.
Ident
))
if
now
.
Unix
()
-
list
[
i
]
.
UpdateAt
<
60
{
list
[
i
]
.
TargetUp
=
2
}
else
if
now
.
Unix
()
-
list
[
i
]
.
UpdateAt
<
180
{
list
[
i
]
.
TargetUp
=
1
}
}
if
len
(
keys
)
>
0
{
...
...
@@ -103,12 +110,6 @@ func (rt *Router) targetGets(c *gin.Context) {
// 未上报过元数据的主机,cpuNum默认为-1, 用于前端展示 unknown
list
[
i
]
.
CpuNum
=
-
1
}
if
now
.
Unix
()
-
list
[
i
]
.
UnixTime
/
1000
<
60
{
list
[
i
]
.
TargetUp
=
2
}
else
if
now
.
Unix
()
-
list
[
i
]
.
UnixTime
/
1000
<
180
{
list
[
i
]
.
TargetUp
=
1
}
}
}
...
...
models/target.go
浏览文件 @
2dc31e98
...
...
@@ -85,7 +85,7 @@ func TargetDel(ctx *ctx.Context, idents []string) error {
return
DB
(
ctx
)
.
Where
(
"ident in ?"
,
idents
)
.
Delete
(
new
(
Target
))
.
Error
}
func
buildTargetWhere
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
)
*
gorm
.
DB
{
func
buildTargetWhere
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
,
downtime
int64
)
*
gorm
.
DB
{
session
:=
DB
(
ctx
)
.
Model
(
&
Target
{})
if
len
(
bgids
)
>
0
{
...
...
@@ -96,6 +96,10 @@ func buildTargetWhere(ctx *ctx.Context, bgids []int64, dsIds []int64, query stri
session
=
session
.
Where
(
"datasource_id in (?)"
,
dsIds
)
}
if
downtime
>
0
{
session
=
session
.
Where
(
"update_at < ?"
,
time
.
Now
()
.
Unix
()
-
downtime
)
}
if
query
!=
""
{
arr
:=
strings
.
Fields
(
query
)
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
...
...
@@ -111,13 +115,13 @@ func TargetTotalCount(ctx *ctx.Context) (int64, error) {
return
Count
(
DB
(
ctx
)
.
Model
(
new
(
Target
)))
}
func
TargetTotal
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
)
(
int64
,
error
)
{
return
Count
(
buildTargetWhere
(
ctx
,
bgids
,
dsIds
,
query
))
func
TargetTotal
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
,
downtime
int64
)
(
int64
,
error
)
{
return
Count
(
buildTargetWhere
(
ctx
,
bgids
,
dsIds
,
query
,
downtime
))
}
func
TargetGets
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
,
limit
,
offset
int
)
([]
*
Target
,
error
)
{
func
TargetGets
(
ctx
*
ctx
.
Context
,
bgids
[]
int64
,
dsIds
[]
int64
,
query
string
,
downtime
int64
,
limit
,
offset
int
)
([]
*
Target
,
error
)
{
var
lst
[]
*
Target
err
:=
buildTargetWhere
(
ctx
,
bgids
,
dsIds
,
query
)
.
Order
(
"ident"
)
.
Limit
(
limit
)
.
Offset
(
offset
)
.
Find
(
&
lst
)
.
Error
err
:=
buildTargetWhere
(
ctx
,
bgids
,
dsIds
,
query
,
downtime
)
.
Order
(
"ident"
)
.
Limit
(
limit
)
.
Offset
(
offset
)
.
Find
(
&
lst
)
.
Error
if
err
==
nil
{
for
i
:=
0
;
i
<
len
(
lst
);
i
++
{
lst
[
i
]
.
TagsJSON
=
strings
.
Fields
(
lst
[
i
]
.
Tags
)
...
...
prom/client.go
浏览文件 @
2dc31e98
...
...
@@ -99,4 +99,5 @@ func (pc *PromClientMap) Del(datasourceId int64) {
pc
.
Lock
()
defer
pc
.
Unlock
()
delete
(
pc
.
ReaderClients
,
datasourceId
)
delete
(
pc
.
WriterClients
,
datasourceId
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录