提交 6e10ab4b 编写于 作者: U Ulric Qin

mount ignore refactor

上级 04e6f36c
......@@ -2,6 +2,7 @@ logger:
dir: logs/collector
level: WARNING
keepHours: 2
identity:
specify: ""
shell: ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1
......@@ -18,12 +19,18 @@ sys:
timeout: 1000
interval: 20
plugin: ./plugin
# monitor nic which filtered by prefix
ifacePrefix:
- eth
- em
mountPoint: []
mountIgnorePrefix:
- /var/lib
# ignore disk mount point
mountIgnore:
prefix:
- /var/lib
# collect anyway
exclude: []
ignoreMetrics:
- cpu.core.idle
......
......@@ -28,7 +28,10 @@ import (
"github.com/toolkits/pkg/runner"
)
const version = 1
// changelog:
// 1: init project
// 2: mount ignore refactor
const version = 2
var (
vers *bool
......
package sys
type SysSection struct {
IfacePrefix []string `yaml:"ifacePrefix"`
MountPoint []string `yaml:"mountPoint"`
MountIgnorePrefix []string `yaml:"mountIgnorePrefix"`
IgnoreMetrics []string `yaml:"ignoreMetrics"`
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"`
IfacePrefix []string `yaml:"ifacePrefix"`
MountIgnore MountIgnoreSection `yaml:"mountIgnore"`
IgnoreMetrics []string `yaml:"ignoreMetrics"`
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"`
}
type MountIgnoreSection struct {
Prefix []string `yaml:"prefix"`
Exclude []string `yaml:"exclude"`
}
var Config SysSection
......
......@@ -9,6 +9,7 @@ import (
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/nux"
"github.com/toolkits/pkg/slice"
)
func DeviceMetrics() []*dataobj.MetricValue {
......@@ -21,26 +22,11 @@ func DeviceMetrics() []*dataobj.MetricValue {
return ret
}
var myMountPoints = make(map[string]bool)
if len(sys.Config.MountPoint) > 0 {
for _, mp := range sys.Config.MountPoint {
myMountPoints[mp] = true
}
}
ignoreMountPointsPrefix := sys.Config.MountIgnorePrefix
var diskTotal uint64 = 0
var diskUsed uint64 = 0
for idx := range mountPoints {
fsSpec, fsFile, fsVfstype := mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2]
if len(myMountPoints) > 0 {
if _, ok := myMountPoints[fsFile]; !ok {
logger.Debug("mount point not matched with config", fsFile, "ignored.")
continue
}
}
if _, exists := fsFileFilter[fsFile]; exists {
logger.Debugf("mount point %s was collected", fsFile)
......@@ -49,7 +35,9 @@ func DeviceMetrics() []*dataobj.MetricValue {
fsFileFilter[fsFile] = struct{}{}
}
if hasIgnorePrefix(fsFile, ignoreMountPointsPrefix) {
// 注意: 虽然前缀被忽略了,但是被忽略的这部分分区里边有些仍然是需要采集的
if hasIgnorePrefix(fsFile, sys.Config.MountIgnore.Prefix) &&
!slice.ContainsString(sys.Config.MountIgnore.Exclude, fsFile) {
continue
}
......
......@@ -13,6 +13,7 @@ import (
"github.com/toolkits/pkg/logger"
"github.com/toolkits/pkg/nux"
"github.com/toolkits/pkg/slice"
)
func FsRWMetrics() []*dataobj.MetricValue {
......@@ -26,8 +27,6 @@ func FsRWMetrics() []*dataobj.MetricValue {
fsFileFilter := make(map[string]struct{}) //过滤 /proc/mounts 出现重复的fsFile
ignoreMountPointsPrefix := sys.Config.MountIgnorePrefix
for idx := range mountPoints {
var du *nux.DeviceUsage
du, err = nux.BuildDeviceUsage(mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2])
......@@ -36,7 +35,8 @@ func FsRWMetrics() []*dataobj.MetricValue {
continue
}
if hasIgnorePrefix(mountPoints[idx][1], ignoreMountPointsPrefix) {
if hasIgnorePrefix(du.FsFile, sys.Config.MountIgnore.Prefix) &&
!slice.ContainsString(sys.Config.MountIgnore.Exclude, du.FsFile) {
continue
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册