Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
c5ba127b
N
Nightingale
项目概览
jobily
/
Nightingale
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c5ba127b
编写于
1月 18, 2021
作者:
7
710leo
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/didi/nightingale
上级
d2be5626
a4c86384
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
177 addition
and
17 deletion
+177
-17
src/models/resource.go
src/models/resource.go
+13
-1
src/modules/ams/http/router.go
src/modules/ams/http/router.go
+1
-0
src/modules/ams/http/router_host.go
src/modules/ams/http/router_host.go
+72
-0
src/modules/judge/judge.go
src/modules/judge/judge.go
+1
-1
src/modules/monapi/config/yaml.go
src/modules/monapi/config/yaml.go
+11
-0
src/modules/monapi/http/router.go
src/modules/monapi/http/router.go
+6
-0
src/modules/monapi/http/router_tpl.go
src/modules/monapi/http/router_tpl.go
+49
-0
src/modules/transfer/backend/m3db/m3db.go
src/modules/transfer/backend/m3db/m3db.go
+24
-15
未找到文件。
src/models/resource.go
浏览文件 @
c5ba127b
...
@@ -292,6 +292,17 @@ func ResourceRegister(hosts []Host, tenant string) error {
...
@@ -292,6 +292,17 @@ func ResourceRegister(hosts []Host, tenant string) error {
return
err
return
err
}
}
// ident agent修改ident带来重复问题
if
res
==
nil
{
ident
:=
hosts
[
i
]
.
Ident
if
ident
!=
""
{
res
,
err
=
ResourceGet
(
"ident=?"
,
ident
)
if
err
!=
nil
{
return
err
}
}
}
if
res
==
nil
{
if
res
==
nil
{
res
=
&
Resource
{
res
=
&
Resource
{
UUID
:
uuid
,
UUID
:
uuid
,
...
@@ -326,6 +337,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
...
@@ -326,6 +337,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
return
err
return
err
}
}
}
}
res
.
UUID
=
uuid
res
.
Ident
=
hosts
[
i
]
.
Ident
res
.
Ident
=
hosts
[
i
]
.
Ident
res
.
Name
=
hosts
[
i
]
.
Name
res
.
Name
=
hosts
[
i
]
.
Name
res
.
Cate
=
hosts
[
i
]
.
Cate
res
.
Cate
=
hosts
[
i
]
.
Cate
...
@@ -343,7 +355,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
...
@@ -343,7 +355,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
}
}
res
.
Extend
=
string
(
js
)
res
.
Extend
=
string
(
js
)
err
=
res
.
Update
(
"ident"
,
"name"
,
"cate"
,
"extend"
,
"tenant"
)
err
=
res
.
Update
(
"
uuid"
,
"
ident"
,
"name"
,
"cate"
,
"extend"
,
"tenant"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
src/modules/ams/http/router.go
浏览文件 @
c5ba127b
...
@@ -14,6 +14,7 @@ func Config(r *gin.Engine) {
...
@@ -14,6 +14,7 @@ func Config(r *gin.Engine) {
userLogin
.
POST
(
"/hosts"
,
hostPost
)
userLogin
.
POST
(
"/hosts"
,
hostPost
)
userLogin
.
GET
(
"/host/:id"
,
hostGet
)
userLogin
.
GET
(
"/host/:id"
,
hostGet
)
userLogin
.
PUT
(
"/hosts/tenant"
,
hostTenantPut
)
userLogin
.
PUT
(
"/hosts/tenant"
,
hostTenantPut
)
userLogin
.
PUT
(
"/hosts/node"
,
hostNodePut
)
userLogin
.
PUT
(
"/hosts/back"
,
hostBackPut
)
userLogin
.
PUT
(
"/hosts/back"
,
hostBackPut
)
userLogin
.
PUT
(
"/hosts/note"
,
hostNotePut
)
userLogin
.
PUT
(
"/hosts/note"
,
hostNotePut
)
userLogin
.
PUT
(
"/hosts/cate"
,
hostCatePut
)
userLogin
.
PUT
(
"/hosts/cate"
,
hostCatePut
)
...
...
src/modules/ams/http/router_host.go
浏览文件 @
c5ba127b
...
@@ -146,6 +146,78 @@ func hostTenantPut(c *gin.Context) {
...
@@ -146,6 +146,78 @@ func hostTenantPut(c *gin.Context) {
renderMessage
(
c
,
err
)
renderMessage
(
c
,
err
)
}
}
type
hostNodeForm
struct
{
Ids
[]
int64
`json:"ids"`
NodeId
int64
`json:"nodeid"`
}
func
(
f
*
hostNodeForm
)
Validate
()
{
if
len
(
f
.
Ids
)
==
0
{
bomb
(
"ids is empty"
)
}
if
f
.
NodeId
==
0
{
bomb
(
"nodeid is blank"
)
}
if
f
.
NodeId
<
0
{
bomb
(
"nodeid is illegal"
)
}
}
// 管理员修改主机设备的节点,相当于挂载设备到节点
func
hostNodePut
(
c
*
gin
.
Context
)
{
var
f
hostNodeForm
bind
(
c
,
&
f
)
f
.
Validate
()
loginUser
(
c
)
.
CheckPermGlobal
(
"ams_host_modify"
)
node
,
err
:=
models
.
NodeGet
(
"id=?"
,
f
.
NodeId
)
dangerous
(
err
)
if
node
==
nil
{
bomb
(
"node is nil"
)
}
if
node
.
Leaf
!=
1
{
bomb
(
"node is not leaf"
)
}
hosts
,
err
:=
models
.
HostByIds
(
f
.
Ids
)
dangerous
(
err
)
if
len
(
hosts
)
==
0
{
bomb
(
"hosts is empty"
)
}
for
_
,
h
:=
range
hosts
{
if
h
.
Tenant
!=
""
{
bomb
(
"%s already belongs to %s"
,
h
.
Name
,
h
.
Tenant
)
}
}
// 绑定租户
tenant
:=
node
.
Tenant
()
err
=
models
.
HostUpdateTenant
(
f
.
Ids
,
tenant
)
dangerous
(
err
)
dangerous
(
models
.
ResourceRegister
(
hosts
,
tenant
))
// 绑定到节点
var
resUuids
[]
string
for
_
,
id
:=
range
f
.
Ids
{
idStr
:=
fmt
.
Sprintf
(
"host-%d"
,
id
)
resUuids
=
append
(
resUuids
,
idStr
)
}
if
len
(
resUuids
)
==
0
{
bomb
(
"res is empty"
)
}
resIds
,
err
:=
models
.
ResourceIdsByUUIDs
(
resUuids
)
dangerous
(
err
)
if
len
(
resIds
)
==
0
{
bomb
(
"res ids is empty"
)
}
renderMessage
(
c
,
node
.
Bind
(
resIds
))
}
type
hostNoteForm
struct
{
type
hostNoteForm
struct
{
Ids
[]
int64
`json:"ids"`
Ids
[]
int64
`json:"ids"`
Note
string
`json:"note"`
Note
string
`json:"note"`
...
...
src/modules/judge/judge.go
浏览文件 @
c5ba127b
...
@@ -117,7 +117,7 @@ func pconf() {
...
@@ -117,7 +117,7 @@ func pconf() {
func
start
()
{
func
start
()
{
runner
.
Init
()
runner
.
Init
()
fmt
.
Println
(
"
transfer
start, use configuration file:"
,
*
conf
)
fmt
.
Println
(
"
judge
start, use configuration file:"
,
*
conf
)
fmt
.
Println
(
"runner.Cwd:"
,
runner
.
Cwd
)
fmt
.
Println
(
"runner.Cwd:"
,
runner
.
Cwd
)
fmt
.
Println
(
"runner.Hostname:"
,
runner
.
Hostname
)
fmt
.
Println
(
"runner.Hostname:"
,
runner
.
Hostname
)
}
}
...
...
src/modules/monapi/config/yaml.go
浏览文件 @
c5ba127b
...
@@ -29,6 +29,12 @@ type ConfYaml struct {
...
@@ -29,6 +29,12 @@ type ConfYaml struct {
Link
linkSection
`yaml:"link"`
Link
linkSection
`yaml:"link"`
IndexMod
string
`yaml:"indexMod"`
IndexMod
string
`yaml:"indexMod"`
I18n
i18n
.
I18nSection
`yaml:"i18n"`
I18n
i18n
.
I18nSection
`yaml:"i18n"`
Tpl
tplSection
`yaml:"tpl"`
}
type
tplSection
struct
{
AlertPath
string
`yaml:"alertPath"`
ScreenPath
string
`yaml:"screenPath"`
}
}
type
mergeSection
struct
{
type
mergeSection
struct
{
...
@@ -175,6 +181,11 @@ func Parse(ymlfile string) error {
...
@@ -175,6 +181,11 @@ func Parse(ymlfile string) error {
"converge"
:
true
,
// 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多
"converge"
:
true
,
// 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多
})
})
viper
.
SetDefault
(
"tpl"
,
map
[
string
]
string
{
"alertPath"
:
"./etc/alert"
,
"screenPath"
:
"./etc/screen"
,
})
err
=
viper
.
Unmarshal
(
&
yaml
)
err
=
viper
.
Unmarshal
(
&
yaml
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unmarshal %v"
,
err
)
return
fmt
.
Errorf
(
"Unmarshal %v"
,
err
)
...
...
src/modules/monapi/http/router.go
浏览文件 @
c5ba127b
...
@@ -144,6 +144,12 @@ func Config(r *gin.Engine) {
...
@@ -144,6 +144,12 @@ func Config(r *gin.Engine) {
aggr
.
GET
(
"/:id"
,
aggrCalcGet
)
aggr
.
GET
(
"/:id"
,
aggrCalcGet
)
}
}
tpl
:=
r
.
Group
(
"/api/mon/tpl"
)
{
tpl
.
GET
(
""
,
tplNameGets
)
tpl
.
GET
(
"/content"
,
tplGet
)
}
aggrs
:=
r
.
Group
(
"/api/mon/aggrs"
)
.
Use
()
aggrs
:=
r
.
Group
(
"/api/mon/aggrs"
)
.
Use
()
{
{
aggrs
.
GET
(
""
,
aggrCalcsWithEndpointGet
)
aggrs
.
GET
(
""
,
aggrCalcsWithEndpointGet
)
...
...
src/modules/monapi/http/router_tpl.go
0 → 100644
浏览文件 @
c5ba127b
package
http
import
(
"github.com/didi/nightingale/src/modules/monapi/config"
"github.com/gin-gonic/gin"
"github.com/toolkits/pkg/file"
)
func
tplNameGets
(
c
*
gin
.
Context
)
{
tplType
:=
mustQueryStr
(
c
,
"tplType"
)
var
files
[]
string
var
err
error
switch
tplType
{
case
"alert"
:
files
,
err
=
file
.
FilesUnder
(
config
.
Get
()
.
Tpl
.
AlertPath
)
dangerous
(
err
)
case
"screen"
:
files
,
err
=
file
.
FilesUnder
(
config
.
Get
()
.
Tpl
.
ScreenPath
)
dangerous
(
err
)
default
:
bomb
(
"tpl type not found"
)
}
renderData
(
c
,
files
,
err
)
}
func
tplGet
(
c
*
gin
.
Context
)
{
tplName
:=
mustQueryStr
(
c
,
"tplName"
)
tplType
:=
mustQueryStr
(
c
,
"tplType"
)
var
filePath
string
switch
tplType
{
case
"alert"
:
filePath
=
config
.
Get
()
.
Tpl
.
AlertPath
+
"/"
+
tplName
case
"screen"
:
filePath
=
config
.
Get
()
.
Tpl
.
ScreenPath
+
"/"
+
tplName
default
:
bomb
(
"tpl type not found"
)
}
if
!
file
.
IsExist
(
filePath
)
{
bomb
(
"tpl not found"
)
}
content
,
err
:=
file
.
ToString
(
filePath
)
renderData
(
c
,
content
,
err
)
}
src/modules/transfer/backend/m3db/m3db.go
浏览文件 @
c5ba127b
...
@@ -3,6 +3,7 @@ package m3db
...
@@ -3,6 +3,7 @@ package m3db
import
(
import
(
"fmt"
"fmt"
"sync"
"sync"
"sync/atomic"
"time"
"time"
"github.com/didi/nightingale/src/common/dataobj"
"github.com/didi/nightingale/src/common/dataobj"
...
@@ -89,23 +90,31 @@ func (p *Client) Push2Queue(items []*dataobj.MetricValue) {
...
@@ -89,23 +90,31 @@ func (p *Client) Push2Queue(items []*dataobj.MetricValue) {
logger
.
Errorf
(
"unable to get m3db session: %s"
,
err
)
logger
.
Errorf
(
"unable to get m3db session: %s"
,
err
)
return
return
}
}
var
errCnt
int32
errCnt
:=
0
var
(
wg
sync
.
WaitGroup
)
for
_
,
item
:=
range
items
{
for
_
,
item
:=
range
items
{
if
err
:=
session
.
WriteTagged
(
wg
.
Add
(
1
)
p
.
namespaceID
,
go
func
(
dm
*
dataobj
.
MetricValue
)
{
mvID
(
item
),
err
:=
session
.
WriteTagged
(
ident
.
NewTagsIterator
(
mvTags
(
item
)),
p
.
namespaceID
,
time
.
Unix
(
item
.
Timestamp
,
0
),
mvID
(
dm
),
item
.
Value
,
ident
.
NewTagsIterator
(
mvTags
(
dm
)),
xtime
.
Second
,
time
.
Unix
(
dm
.
Timestamp
,
0
),
nil
,
dm
.
Value
,
);
err
!=
nil
{
xtime
.
Second
,
logger
.
Errorf
(
"unable to writeTagged: %s"
,
err
)
nil
)
errCnt
++
if
err
!=
nil
{
}
logger
.
Errorf
(
"unable to writeTagged: %s"
,
err
)
atomic
.
AddInt32
(
&
errCnt
,
1
)
}
wg
.
Done
()
}(
item
)
}
}
stats
.
Counter
.
Set
(
"m3db.queue.err"
,
errCnt
)
wg
.
Wait
()
stats
.
Counter
.
Set
(
"m3db.queue.err"
,
int
(
errCnt
))
}
}
// QueryData: || (|| endpoints...) (&& tags...)
// QueryData: || (|| endpoints...) (&& tags...)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录