mount ignore refactor
This commit is contained in:
parent
04e6f36cac
commit
6e10ab4b55
|
@ -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:
|
||||
|
||||
# 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
|
||||
|
|
|
@ -2,8 +2,7 @@ package sys
|
|||
|
||||
type SysSection struct {
|
||||
IfacePrefix []string `yaml:"ifacePrefix"`
|
||||
MountPoint []string `yaml:"mountPoint"`
|
||||
MountIgnorePrefix []string `yaml:"mountIgnorePrefix"`
|
||||
MountIgnore MountIgnoreSection `yaml:"mountIgnore"`
|
||||
IgnoreMetrics []string `yaml:"ignoreMetrics"`
|
||||
IgnoreMetricsMap map[string]struct{} `yaml:"-"`
|
||||
NtpServers []string `yaml:"ntpServers"`
|
||||
|
@ -13,6 +12,11 @@ type SysSection struct {
|
|||
Timeout int `yaml:"timeout"`
|
||||
}
|
||||
|
||||
type MountIgnoreSection struct {
|
||||
Prefix []string `yaml:"prefix"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
}
|
||||
|
||||
var Config SysSection
|
||||
|
||||
func Init(s 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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue