Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
45fe14b4
N
nightingale
项目概览
DiDi
/
nightingale
11 个月 前同步成功
通知
46
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,发现更多精彩内容 >>
提交
45fe14b4
编写于
4月 20, 2020
作者:
7
710leo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get plugin collect from monapi
上级
0d496f71
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
11 deletion
+88
-11
src/model/collect.go
src/model/collect.go
+40
-6
src/modules/collector/sys/config.go
src/modules/collector/sys/config.go
+1
-0
src/modules/collector/sys/plugins/cron.go
src/modules/collector/sys/plugins/cron.go
+1
-3
src/modules/collector/sys/plugins/plugin.go
src/modules/collector/sys/plugins/plugin.go
+1
-0
src/modules/collector/sys/plugins/reader.go
src/modules/collector/sys/plugins/reader.go
+42
-1
src/modules/collector/sys/plugins/scheduler.go
src/modules/collector/sys/plugins/scheduler.go
+3
-1
未找到文件。
src/model/collect.go
浏览文件 @
45fe14b4
...
...
@@ -12,16 +12,18 @@ import (
type
Collect
struct
{
sync
.
RWMutex
Ports
map
[
int
]
*
PortCollect
`json:"ports"`
Procs
map
[
string
]
*
ProcCollect
`json:"procs"`
Logs
map
[
string
]
*
LogCollect
`json:"logs"`
Ports
map
[
int
]
*
PortCollect
`json:"ports"`
Procs
map
[
string
]
*
ProcCollect
`json:"procs"`
Logs
map
[
string
]
*
LogCollect
`json:"logs"`
Plugins
map
[
string
]
*
PluginCollect
`json:"plugins"`
}
func
NewCollect
()
*
Collect
{
return
&
Collect
{
Ports
:
make
(
map
[
int
]
*
PortCollect
),
Procs
:
make
(
map
[
string
]
*
ProcCollect
),
Logs
:
make
(
map
[
string
]
*
LogCollect
),
Ports
:
make
(
map
[
int
]
*
PortCollect
),
Procs
:
make
(
map
[
string
]
*
ProcCollect
),
Logs
:
make
(
map
[
string
]
*
LogCollect
),
Plugins
:
make
(
map
[
string
]
*
PluginCollect
),
}
}
...
...
@@ -45,6 +47,12 @@ func (c *Collect) Update(cc *Collect) {
for
k
,
v
:=
range
cc
.
Logs
{
c
.
Logs
[
k
]
=
v
}
//更新plugin采集配置
c
.
Plugins
=
make
(
map
[
string
]
*
PluginCollect
)
for
k
,
v
:=
range
cc
.
Plugins
{
c
.
Plugins
[
k
]
=
v
}
}
func
(
c
*
Collect
)
GetPorts
()
map
[
int
]
*
PortCollect
{
...
...
@@ -80,6 +88,17 @@ func (c *Collect) GetLogConfig() map[string]*LogCollect {
return
tmp
}
func
(
c
*
Collect
)
GetPlugin
()
map
[
string
]
*
PluginCollect
{
c
.
RLock
()
defer
c
.
RUnlock
()
tmp
:=
make
(
map
[
string
]
*
PluginCollect
)
for
k
,
v
:=
range
c
.
Plugins
{
tmp
[
k
]
=
v
}
return
tmp
}
type
PortCollect
struct
{
Id
int64
`json:"id"`
Nid
int64
`json:"nid"`
...
...
@@ -114,6 +133,21 @@ type ProcCollect struct {
CollectMethod
string
`json:"collect_method"`
}
type
PluginCollect
struct
{
Id
int64
`json:"id"`
Nid
int64
`json:"nid"`
CollectType
string
`json:"collect_type"`
Name
string
`json:"name"`
Step
int
`json:"step"`
FilePath
string
`json:"file_path"`
Params
string
`json:"params"`
Comment
string
`json:"comment"`
Creator
string
`json:"creator"`
Created
time
.
Time
`xorm:"updated" json:"created"`
LastUpdator
string
`xorm:"last_updator" json:"last_updator"`
LastUpdated
time
.
Time
`xorm:"updated" json:"last_updated"`
}
type
LogCollect
struct
{
Id
int64
`json:"id"`
Nid
int64
`json:"nid"`
...
...
src/modules/collector/sys/config.go
浏览文件 @
45fe14b4
...
...
@@ -8,6 +8,7 @@ type SysSection struct {
IgnoreMetricsMap
map
[
string
]
struct
{}
`yaml:"-"`
NtpServers
[]
string
`yaml:"ntpServers"`
Plugin
string
`yaml:"plugin"`
PluginRemote
bool
`yaml:"pluginRemote"`
Interval
int
`yaml:"interval"`
Timeout
int
`yaml:"timeout"`
}
...
...
src/modules/collector/sys/plugins/cron.go
浏览文件 @
45fe14b4
...
...
@@ -2,8 +2,6 @@ package plugins
import
(
"time"
"github.com/didi/nightingale/src/modules/collector/sys"
)
func
Detect
()
{
...
...
@@ -19,7 +17,7 @@ func loopDetect() {
}
func
detect
()
{
ps
:=
ListPlugins
(
sys
.
Config
.
Plugin
)
ps
:=
ListPlugins
()
DelNoUsePlugins
(
ps
)
AddNewPlugins
(
ps
)
}
src/modules/collector/sys/plugins/plugin.go
浏览文件 @
45fe14b4
...
...
@@ -2,6 +2,7 @@ package plugins
type
Plugin
struct
{
FilePath
string
Params
string
MTime
int64
Cycle
int
}
...
...
src/modules/collector/sys/plugins/reader.go
浏览文件 @
45fe14b4
...
...
@@ -2,16 +2,57 @@ package plugins
import
(
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/didi/nightingale/src/modules/collector/stra"
"github.com/didi/nightingale/src/modules/collector/sys"
"github.com/toolkits/pkg/file"
"github.com/toolkits/pkg/logger"
)
// key: 60_ntp.py
func
ListPlugins
(
dir
string
)
map
[
string
]
*
Plugin
{
func
ListPlugins
()
map
[
string
]
*
Plugin
{
plugins
:=
make
(
map
[
string
]
*
Plugin
)
if
sys
.
Config
.
PluginRemote
{
plugins
=
ListPluginsFromMonapi
()
}
else
{
plugins
=
ListPluginsFromLocal
()
}
return
plugins
}
func
ListPluginsFromMonapi
()
map
[
string
]
*
Plugin
{
ret
:=
make
(
map
[
string
]
*
Plugin
)
plugins
:=
stra
.
Collect
.
GetPlugin
()
for
_
,
p
:=
range
plugins
{
fpath
:=
p
.
FilePath
fileInfo
,
err
:=
os
.
Stat
(
fpath
)
if
err
!=
nil
{
logger
.
Warningf
(
"plugin:%s get info err:%v"
,
p
.
FilePath
,
err
)
continue
}
plugin
:=
&
Plugin
{
FilePath
:
fpath
,
MTime
:
fileInfo
.
ModTime
()
.
Unix
(),
Cycle
:
p
.
Step
,
Params
:
p
.
Params
,
}
ret
[
fpath
]
=
plugin
}
return
ret
}
func
ListPluginsFromLocal
()
map
[
string
]
*
Plugin
{
dir
:=
sys
.
Config
.
Plugin
ret
:=
make
(
map
[
string
]
*
Plugin
)
if
dir
==
""
||
!
file
.
IsExist
(
dir
)
||
file
.
IsFile
(
dir
)
{
...
...
src/modules/collector/sys/plugins/scheduler.go
浏览文件 @
45fe14b4
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/toolkits/pkg/file"
...
...
@@ -57,7 +58,8 @@ func PluginRun(plugin *Plugin) {
}
logger
.
Debug
(
fpath
,
" running"
)
cmd
:=
exec
.
Command
(
fpath
)
params
:=
strings
.
Split
(
plugin
.
Params
,
" "
)
cmd
:=
exec
.
Command
(
fpath
,
params
...
)
cmd
.
Dir
=
filepath
.
Dir
(
fpath
)
var
stdout
bytes
.
Buffer
cmd
.
Stdout
=
&
stdout
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录