Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
a6de4d35
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,发现更多精彩内容 >>
提交
a6de4d35
编写于
5月 12, 2020
作者:
7
710leo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support operating plugin collection by web
上级
9264aa62
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
201 addition
and
34 deletion
+201
-34
README.md
README.md
+4
-0
README_ZH.md
README_ZH.md
+3
-0
control
control
+1
-1
sql/n9e_mon.sql
sql/n9e_mon.sql
+18
-0
src/model/collect.go
src/model/collect.go
+50
-13
src/modules/collector/config/config.go
src/modules/collector/config/config.go
+4
-3
src/modules/collector/stra/port.go
src/modules/collector/stra/port.go
+11
-2
src/modules/collector/stra/proc.go
src/modules/collector/stra/proc.go
+11
-2
src/modules/collector/sys/plugins/reader.go
src/modules/collector/sys/plugins/reader.go
+3
-3
src/modules/collector/sys/ports/port.go
src/modules/collector/sys/ports/port.go
+0
-9
src/modules/monapi/http/routes/collect.go
src/modules/monapi/http/routes/collect.go
+65
-1
src/modules/monapi/scache/init.go
src/modules/monapi/scache/init.go
+31
-0
未找到文件。
README.md
浏览文件 @
a6de4d35
...
...
@@ -34,6 +34,10 @@ $ docker-compose up -d
![
dashboard
](
https://user-images.githubusercontent.com/19553554/78956965-8b9c6180-7b16-11ea-9747-6ed5e62b068d.png
)
## Upgrading
If upgrade
`version<1.4.0`
to
`v1.4.0`
, follow the operating instructions in
[
v1.4.0
](
https://github.com/didi/nightingale/releases/tag/v1.4.0
)
release
## Team
[
ulricqin
](
https://github.com/ulricqin
)
[
710leo
]
(https://github.com/710leo)
[
jsers
](
https://github.com/jsers
)
[
hujter
]
(https://github.com/hujter)
[
n4mine
](
https://github.com/n4mine
)
[
heli567
]
(https://github.com/heli567)
...
...
README_ZH.md
浏览文件 @
a6de4d35
...
...
@@ -34,6 +34,9 @@ $ docker-compose up -d
![
dashboard
](
https://user-images.githubusercontent.com/19553554/78956965-8b9c6180-7b16-11ea-9747-6ed5e62b068d.png
)
## 版本升级
如果需要从
`v1.4.0`
之前的版本升级到
`v1.4.0`
, 按照
[
v1.4.0
](
https://github.com/didi/nightingale/releases/tag/v1.4.0
)
release 说明操作即可
## 团队
[
ulricqin
](
https://github.com/ulricqin
)
[
710leo
]
(https://github.com/710leo)
[
jsers
](
https://github.com/jsers
)
[
hujter
]
(https://github.com/hujter)
[
n4mine
](
https://github.com/n4mine
)
[
heli567
]
(https://github.com/heli567)
...
...
control
浏览文件 @
a6de4d35
#!/bin/bash
# release version
version
=
1.
3.3
version
=
1.
4.0
CWD
=
$(
cd
$(
dirname
$0
)
/
;
pwd
)
cd
$CWD
...
...
sql/n9e_mon.sql
浏览文件 @
a6de4d35
...
...
@@ -255,6 +255,24 @@ CREATE TABLE `log_collect` (
KEY
`idx_collect_type`
(
`collect_type`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COMMENT
'log collect'
;
CREATE
TABLE
`plugin_collect`
(
`id`
bigint
(
20
)
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'id'
,
`nid`
bigint
(
20
)
unsigned
NOT
NULL
DEFAULT
'0'
COMMENT
'nid'
,
`name`
varchar
(
255
)
NOT
NULL
DEFAULT
''
COMMENT
'name'
,
`collect_type`
varchar
(
64
)
NOT
NULL
DEFAULT
'PROC'
COMMENT
'type'
,
`step`
int
(
11
)
NOT
NULL
DEFAULT
'0'
COMMENT
'采集周期'
,
`file_path`
varchar
(
255
)
NOT
NULL
COMMENT
'file_path'
,
`params`
varchar
(
255
)
NOT
NULL
COMMENT
'params'
,
`comment`
varchar
(
512
)
NOT
NULL
DEFAULT
''
COMMENT
'comment'
,
`creator`
varchar
(
255
)
NOT
NULL
DEFAULT
''
COMMENT
'creator'
,
`created`
datetime
NOT
NULL
COMMENT
'created'
,
`last_updator`
varchar
(
128
)
NOT
NULL
DEFAULT
''
COMMENT
'last_updator'
,
`last_updated`
timestamp
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
`id`
),
KEY
`idx_nid`
(
`nid`
),
KEY
`idx_collect_type`
(
`collect_type`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COMMENT
'plugin collect'
;
CREATE
TABLE
`collect_hist`
(
`id`
bigint
(
20
)
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'id'
,
`cid`
bigint
(
20
)
NOT
NULL
DEFAULT
'0'
COMMENT
'collect id'
,
...
...
src/model/collect.go
浏览文件 @
a6de4d35
...
...
@@ -323,6 +323,44 @@ func (l *LogCollect) Update() error {
return
err
}
func
GetPluginCollects
()
([]
*
PluginCollect
,
error
)
{
collects
:=
[]
*
PluginCollect
{}
err
:=
DB
[
"mon"
]
.
Find
(
&
collects
)
return
collects
,
err
}
func
(
p
*
PluginCollect
)
Update
()
error
{
session
:=
DB
[
"mon"
]
.
NewSession
()
defer
session
.
Close
()
err
:=
session
.
Begin
()
if
err
!=
nil
{
return
err
}
if
_
,
err
=
session
.
Id
(
p
.
Id
)
.
AllCols
()
.
Update
(
p
);
err
!=
nil
{
session
.
Rollback
()
return
err
}
b
,
err
:=
json
.
Marshal
(
p
)
if
err
!=
nil
{
session
.
Rollback
()
return
err
}
if
err
:=
saveHist
(
p
.
Id
,
"plugin"
,
"update"
,
p
.
Creator
,
string
(
b
),
session
);
err
!=
nil
{
session
.
Rollback
()
return
err
}
if
err
=
session
.
Commit
();
err
!=
nil
{
return
err
}
return
err
}
func
CreateCollect
(
collectType
,
creator
string
,
collect
interface
{})
error
{
session
:=
DB
[
"mon"
]
.
NewSession
()
defer
session
.
Close
()
...
...
@@ -379,6 +417,14 @@ func GetCollectByNid(collectType string, nids []int64) ([]interface{}, error) {
}
return
res
,
err
case
"plugin"
:
collects
:=
[]
PluginCollect
{}
err
:=
DB
[
"mon"
]
.
In
(
"nid"
,
nids
)
.
Find
(
&
collects
)
for
_
,
c
:=
range
collects
{
res
=
append
(
res
,
c
)
}
return
res
,
err
default
:
return
nil
,
fmt
.
Errorf
(
"illegal collectType"
)
}
...
...
@@ -400,6 +446,10 @@ func GetCollectById(collectType string, cid int64) (interface{}, error) {
_
,
err
:=
DB
[
"mon"
]
.
Where
(
"id = ?"
,
cid
)
.
Get
(
collect
)
collect
.
Decode
()
return
collect
,
err
case
"plugin"
:
collect
:=
new
(
PluginCollect
)
_
,
err
:=
DB
[
"mon"
]
.
Where
(
"id = ?"
,
cid
)
.
Get
(
collect
)
return
collect
,
err
default
:
return
nil
,
fmt
.
Errorf
(
"illegal collectType"
)
...
...
@@ -448,16 +498,3 @@ func saveHist(id int64, tp string, action, username, body string, session *xorm.
return
err
}
func
GetCollectsModel
(
t
string
)
(
interface
{},
error
)
{
collects
:=
make
([]
*
PortCollect
,
0
)
switch
t
{
case
"port"
:
return
collects
,
nil
case
"proc"
:
return
collects
,
nil
default
:
return
nil
,
fmt
.
Errorf
(
"illegal collectType"
)
}
}
src/modules/collector/config/config.go
浏览文件 @
a6de4d35
...
...
@@ -69,9 +69,10 @@ func Parse(conf string) error {
})
viper
.
SetDefault
(
"sys"
,
map
[
string
]
interface
{}{
"timeout"
:
1000
,
//请求超时时间
"interval"
:
10
,
//基础指标上报周期
"plugin"
:
"./plugin"
,
"timeout"
:
1000
,
//请求超时时间
"interval"
:
10
,
//基础指标上报周期
"pluginRemote"
:
true
,
//从monapi获取插件采集配置
"plugin"
:
"./plugin"
,
})
err
=
viper
.
Unmarshal
(
&
Config
)
...
...
src/modules/collector/stra/port.go
浏览文件 @
a6de4d35
...
...
@@ -2,8 +2,10 @@ package stra
import
(
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/didi/nightingale/src/model"
"github.com/didi/nightingale/src/toolkits/str"
...
...
@@ -12,12 +14,13 @@ import (
"github.com/toolkits/pkg/logger"
)
func
NewPortCollect
(
port
,
step
int
,
tags
string
)
*
model
.
PortCollect
{
func
NewPortCollect
(
port
,
step
int
,
tags
string
,
modTime
time
.
Time
)
*
model
.
PortCollect
{
return
&
model
.
PortCollect
{
CollectType
:
"port"
,
Port
:
port
,
Step
:
step
,
Tags
:
tags
,
LastUpdated
:
modTime
,
}
}
...
...
@@ -54,8 +57,14 @@ func GetPortCollects() map[int]*model.PortCollect {
continue
}
info
,
err
:=
os
.
Stat
(
f
)
if
err
!=
nil
{
logger
.
Warning
(
err
)
continue
}
tags
:=
fmt
.
Sprintf
(
"port=%s,service=%s"
,
strconv
.
Itoa
(
port
),
service
)
p
:=
NewPortCollect
(
port
,
step
,
tags
)
p
:=
NewPortCollect
(
port
,
step
,
tags
,
info
.
ModTime
()
)
ports
[
p
.
Port
]
=
p
}
...
...
src/modules/collector/stra/proc.go
浏览文件 @
a6de4d35
...
...
@@ -2,8 +2,10 @@ package stra
import
(
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/didi/nightingale/src/model"
"github.com/didi/nightingale/src/toolkits/str"
...
...
@@ -12,13 +14,14 @@ import (
"github.com/toolkits/pkg/logger"
)
func
NewProcCollect
(
method
,
name
,
tags
string
,
step
int
)
*
model
.
ProcCollect
{
func
NewProcCollect
(
method
,
name
,
tags
string
,
step
int
,
modTime
time
.
Time
)
*
model
.
ProcCollect
{
return
&
model
.
ProcCollect
{
CollectType
:
"proc"
,
CollectMethod
:
method
,
Target
:
name
,
Step
:
step
,
Tags
:
tags
,
LastUpdated
:
modTime
,
}
}
...
...
@@ -54,8 +57,14 @@ func GetProcCollects() map[string]*model.ProcCollect {
continue
}
info
,
err
:=
os
.
Stat
(
f
)
if
err
!=
nil
{
logger
.
Warning
(
err
)
continue
}
tags
:=
fmt
.
Sprintf
(
"target=%s,service=%s"
,
name
,
service
)
p
:=
NewProcCollect
(
method
,
name
,
tags
,
step
)
p
:=
NewProcCollect
(
method
,
name
,
tags
,
step
,
info
.
ModTime
()
)
procs
[
name
]
=
p
}
...
...
src/modules/collector/sys/plugins/reader.go
浏览文件 @
a6de4d35
...
...
@@ -73,7 +73,7 @@ func ListPluginsFromLocal() map[string]*Plugin {
filename
:=
f
.
Name
()
arr
:=
strings
.
Split
(
filename
,
"_"
)
if
len
(
arr
)
<
2
{
logger
.
Warnin
gf
(
"plugin:%s name illegal, should be: $cycle_$xx"
,
filename
)
logger
.
Debu
gf
(
"plugin:%s name illegal, should be: $cycle_$xx"
,
filename
)
continue
}
...
...
@@ -81,13 +81,13 @@ func ListPluginsFromLocal() map[string]*Plugin {
var
cycle
int
cycle
,
err
=
strconv
.
Atoi
(
arr
[
0
])
if
err
!=
nil
{
logger
.
Warnin
gf
(
"plugin:%s name illegal, should be: $cycle_$xx %v"
,
filename
,
err
)
logger
.
Debu
gf
(
"plugin:%s name illegal, should be: $cycle_$xx %v"
,
filename
,
err
)
continue
}
fpath
,
err
:=
filepath
.
Abs
(
filepath
.
Join
(
dir
,
filename
))
if
err
!=
nil
{
logger
.
Warnin
gf
(
"plugin:%s absolute path get err:%v"
,
filename
,
err
)
logger
.
Debu
gf
(
"plugin:%s absolute path get err:%v"
,
filename
,
err
)
continue
}
...
...
src/modules/collector/sys/ports/port.go
浏览文件 @
a6de4d35
...
...
@@ -39,12 +39,3 @@ func deletePort(key int) {
}
delete
(
Ports
,
key
)
}
func
NewPortCollect
(
port
,
step
int
,
tags
string
)
*
model
.
PortCollect
{
return
&
model
.
PortCollect
{
CollectType
:
"port"
,
Port
:
port
,
Step
:
step
,
Tags
:
tags
,
}
}
src/modules/monapi/http/routes/collect.go
浏览文件 @
a6de4d35
...
...
@@ -104,6 +104,31 @@ func collectPost(c *gin.Context) {
}
errors
.
Dangerous
(
model
.
CreateCollect
(
obj
.
Type
,
creator
,
collect
))
case
"plugin"
:
collect
:=
new
(
model
.
PluginCollect
)
b
,
err
:=
json
.
Marshal
(
obj
.
Data
)
if
err
!=
nil
{
errors
.
Bomb
(
"marshal body %s err:%v"
,
obj
,
err
)
}
err
=
json
.
Unmarshal
(
b
,
collect
)
if
err
!=
nil
{
errors
.
Bomb
(
"unmarshal body %s err:%v"
,
string
(
b
),
err
)
}
collect
.
Creator
=
creator
collect
.
LastUpdator
=
creator
nid
:=
collect
.
Nid
name
:=
collect
.
Name
old
,
_
:=
model
.
GetCollectByName
(
obj
.
Type
,
name
)
if
old
!=
nil
&&
int64
(
old
.
(
map
[
string
]
interface
{})[
"nid"
]
.
(
float64
))
==
nid
{
errors
.
Bomb
(
"同节点下策略名称 %s 已存在"
,
name
)
}
errors
.
Dangerous
(
model
.
CreateCollect
(
obj
.
Type
,
creator
,
collect
))
default
:
errors
.
Bomb
(
"采集类型不合法"
)
}
...
...
@@ -131,7 +156,7 @@ func collectsGet(c *gin.Context) {
var
resp
[]
interface
{}
nids
:=
[]
int64
{
nid
}
types
:=
[]
string
{
"port"
,
"proc"
,
"log"
}
types
:=
[]
string
{
"port"
,
"proc"
,
"log"
,
"plugin"
}
for
_
,
t
:=
range
types
{
collects
,
err
:=
model
.
GetCollectByNid
(
t
,
nids
)
...
...
@@ -268,6 +293,45 @@ func collectPut(c *gin.Context) {
errors
.
Bomb
(
"同节点下策略名称 %s 已存在"
,
name
)
}
errors
.
Dangerous
(
collect
.
Update
())
renderData
(
c
,
"ok"
,
nil
)
return
case
"plugin"
:
collect
:=
new
(
model
.
PluginCollect
)
b
,
err
:=
json
.
Marshal
(
recv
.
Data
)
if
err
!=
nil
{
errors
.
Bomb
(
"marshal body %s err:%v"
,
recv
,
err
)
}
err
=
json
.
Unmarshal
(
b
,
collect
)
if
err
!=
nil
{
errors
.
Bomb
(
"unmarshal body %s err:%v"
,
string
(
b
),
err
)
}
nid
:=
collect
.
Nid
name
:=
collect
.
Name
//校验采集是否存在
obj
,
err
:=
model
.
GetCollectById
(
recv
.
Type
,
collect
.
Id
)
//id找不到的情况
if
err
!=
nil
{
errors
.
Bomb
(
"采集不存在 type:%s id:%d"
,
recv
.
Type
,
collect
.
Id
)
}
tmpId
:=
obj
.
(
*
model
.
PluginCollect
)
.
Id
if
tmpId
==
0
{
errors
.
Bomb
(
"采集不存在 type:%s id:%d"
,
recv
.
Type
,
collect
.
Id
)
}
collect
.
Creator
=
creator
collect
.
LastUpdator
=
creator
old
,
_
:=
model
.
GetCollectByName
(
recv
.
Type
,
name
)
if
old
!=
nil
&&
int64
(
old
.
(
map
[
string
]
interface
{})[
"nid"
]
.
(
float64
))
==
nid
&&
tmpId
!=
collect
.
Id
{
errors
.
Bomb
(
"同节点下策略名称 %s 已存在"
,
name
)
}
errors
.
Dangerous
(
collect
.
Update
())
renderData
(
c
,
"ok"
,
nil
)
return
...
...
src/modules/monapi/scache/init.go
浏览文件 @
a6de4d35
...
...
@@ -177,6 +177,37 @@ func syncCollects() {
}
}
pluginConfigs
,
err
:=
model
.
GetPluginCollects
()
if
err
!=
nil
{
logger
.
Warningf
(
"get log collects err:%v"
,
err
)
}
for
_
,
p
:=
range
pluginConfigs
{
leafNids
,
err
:=
GetLeafNids
(
p
.
Nid
,
[]
int64
{})
if
err
!=
nil
{
logger
.
Warningf
(
"get LeafNids err:%v %v"
,
err
,
p
)
continue
}
Endpoints
,
err
:=
model
.
EndpointUnderLeafs
(
leafNids
)
if
err
!=
nil
{
logger
.
Warningf
(
"get endpoints err:%v %v"
,
err
,
p
)
continue
}
for
_
,
endpoint
:=
range
Endpoints
{
name
:=
endpoint
.
Ident
c
,
exists
:=
collectMap
[
name
]
if
!
exists
{
c
=
model
.
NewCollect
()
}
key
:=
fmt
.
Sprintf
(
"%s-%d"
,
p
.
Name
,
p
.
Nid
)
c
.
Plugins
[
key
]
=
p
collectMap
[
name
]
=
c
}
}
CollectCache
.
SetAll
(
collectMap
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录