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 {
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
{
res
=
&
Resource
{
UUID
:
uuid
,
...
...
@@ -326,6 +337,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
return
err
}
}
res
.
UUID
=
uuid
res
.
Ident
=
hosts
[
i
]
.
Ident
res
.
Name
=
hosts
[
i
]
.
Name
res
.
Cate
=
hosts
[
i
]
.
Cate
...
...
@@ -343,7 +355,7 @@ func ResourceRegister(hosts []Host, tenant string) error {
}
res
.
Extend
=
string
(
js
)
err
=
res
.
Update
(
"ident"
,
"name"
,
"cate"
,
"extend"
,
"tenant"
)
err
=
res
.
Update
(
"
uuid"
,
"
ident"
,
"name"
,
"cate"
,
"extend"
,
"tenant"
)
if
err
!=
nil
{
return
err
}
...
...
src/modules/ams/http/router.go
浏览文件 @
c5ba127b
...
...
@@ -14,6 +14,7 @@ func Config(r *gin.Engine) {
userLogin
.
POST
(
"/hosts"
,
hostPost
)
userLogin
.
GET
(
"/host/:id"
,
hostGet
)
userLogin
.
PUT
(
"/hosts/tenant"
,
hostTenantPut
)
userLogin
.
PUT
(
"/hosts/node"
,
hostNodePut
)
userLogin
.
PUT
(
"/hosts/back"
,
hostBackPut
)
userLogin
.
PUT
(
"/hosts/note"
,
hostNotePut
)
userLogin
.
PUT
(
"/hosts/cate"
,
hostCatePut
)
...
...
src/modules/ams/http/router_host.go
浏览文件 @
c5ba127b
...
...
@@ -146,6 +146,78 @@ func hostTenantPut(c *gin.Context) {
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
{
Ids
[]
int64
`json:"ids"`
Note
string
`json:"note"`
...
...
src/modules/judge/judge.go
浏览文件 @
c5ba127b
...
...
@@ -117,7 +117,7 @@ func pconf() {
func
start
()
{
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.Hostname:"
,
runner
.
Hostname
)
}
...
...
src/modules/monapi/config/yaml.go
浏览文件 @
c5ba127b
...
...
@@ -29,6 +29,12 @@ type ConfYaml struct {
Link
linkSection
`yaml:"link"`
IndexMod
string
`yaml:"indexMod"`
I18n
i18n
.
I18nSection
`yaml:"i18n"`
Tpl
tplSection
`yaml:"tpl"`
}
type
tplSection
struct
{
AlertPath
string
`yaml:"alertPath"`
ScreenPath
string
`yaml:"screenPath"`
}
type
mergeSection
struct
{
...
...
@@ -175,6 +181,11 @@ func Parse(ymlfile string) error {
"converge"
:
true
,
// 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多
})
viper
.
SetDefault
(
"tpl"
,
map
[
string
]
string
{
"alertPath"
:
"./etc/alert"
,
"screenPath"
:
"./etc/screen"
,
})
err
=
viper
.
Unmarshal
(
&
yaml
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unmarshal %v"
,
err
)
...
...
src/modules/monapi/http/router.go
浏览文件 @
c5ba127b
...
...
@@ -144,6 +144,12 @@ func Config(r *gin.Engine) {
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
.
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
import
(
"fmt"
"sync"
"sync/atomic"
"time"
"github.com/didi/nightingale/src/common/dataobj"
...
...
@@ -89,23 +90,31 @@ func (p *Client) Push2Queue(items []*dataobj.MetricValue) {
logger
.
Errorf
(
"unable to get m3db session: %s"
,
err
)
return
}
errCnt
:=
0
var
errCnt
int32
var
(
wg
sync
.
WaitGroup
)
for
_
,
item
:=
range
items
{
if
err
:=
session
.
WriteTagged
(
p
.
namespaceID
,
mvID
(
item
),
ident
.
NewTagsIterator
(
mvTags
(
item
)),
time
.
Unix
(
item
.
Timestamp
,
0
),
item
.
Value
,
xtime
.
Second
,
nil
,
);
err
!=
nil
{
logger
.
Errorf
(
"unable to writeTagged: %s"
,
err
)
errCnt
++
}
wg
.
Add
(
1
)
go
func
(
dm
*
dataobj
.
MetricValue
)
{
err
:=
session
.
WriteTagged
(
p
.
namespaceID
,
mvID
(
dm
),
ident
.
NewTagsIterator
(
mvTags
(
dm
)),
time
.
Unix
(
dm
.
Timestamp
,
0
),
dm
.
Value
,
xtime
.
Second
,
nil
)
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...)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录