mount ignore refactor
This commit is contained in:
parent
04e6f36cac
commit
6e10ab4b55
|
@ -2,6 +2,7 @@ logger:
|
||||||
dir: logs/collector
|
dir: logs/collector
|
||||||
level: WARNING
|
level: WARNING
|
||||||
keepHours: 2
|
keepHours: 2
|
||||||
|
|
||||||
identity:
|
identity:
|
||||||
specify: ""
|
specify: ""
|
||||||
shell: ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1
|
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
|
timeout: 1000
|
||||||
interval: 20
|
interval: 20
|
||||||
plugin: ./plugin
|
plugin: ./plugin
|
||||||
|
|
||||||
|
# monitor nic which filtered by prefix
|
||||||
ifacePrefix:
|
ifacePrefix:
|
||||||
- eth
|
- eth
|
||||||
- em
|
- em
|
||||||
mountPoint: []
|
|
||||||
mountIgnorePrefix:
|
# ignore disk mount point
|
||||||
|
mountIgnore:
|
||||||
|
prefix:
|
||||||
- /var/lib
|
- /var/lib
|
||||||
|
# collect anyway
|
||||||
|
exclude: []
|
||||||
|
|
||||||
ignoreMetrics:
|
ignoreMetrics:
|
||||||
- cpu.core.idle
|
- cpu.core.idle
|
||||||
|
|
|
@ -28,7 +28,10 @@ import (
|
||||||
"github.com/toolkits/pkg/runner"
|
"github.com/toolkits/pkg/runner"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = 1
|
// changelog:
|
||||||
|
// 1: init project
|
||||||
|
// 2: mount ignore refactor
|
||||||
|
const version = 2
|
||||||
|
|
||||||
var (
|
var (
|
||||||
vers *bool
|
vers *bool
|
||||||
|
|
|
@ -2,8 +2,7 @@ package sys
|
||||||
|
|
||||||
type SysSection struct {
|
type SysSection struct {
|
||||||
IfacePrefix []string `yaml:"ifacePrefix"`
|
IfacePrefix []string `yaml:"ifacePrefix"`
|
||||||
MountPoint []string `yaml:"mountPoint"`
|
MountIgnore MountIgnoreSection `yaml:"mountIgnore"`
|
||||||
MountIgnorePrefix []string `yaml:"mountIgnorePrefix"`
|
|
||||||
IgnoreMetrics []string `yaml:"ignoreMetrics"`
|
IgnoreMetrics []string `yaml:"ignoreMetrics"`
|
||||||
IgnoreMetricsMap map[string]struct{} `yaml:"-"`
|
IgnoreMetricsMap map[string]struct{} `yaml:"-"`
|
||||||
NtpServers []string `yaml:"ntpServers"`
|
NtpServers []string `yaml:"ntpServers"`
|
||||||
|
@ -13,6 +12,11 @@ type SysSection struct {
|
||||||
Timeout int `yaml:"timeout"`
|
Timeout int `yaml:"timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MountIgnoreSection struct {
|
||||||
|
Prefix []string `yaml:"prefix"`
|
||||||
|
Exclude []string `yaml:"exclude"`
|
||||||
|
}
|
||||||
|
|
||||||
var Config SysSection
|
var Config SysSection
|
||||||
|
|
||||||
func Init(s SysSection) {
|
func Init(s SysSection) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/toolkits/pkg/logger"
|
"github.com/toolkits/pkg/logger"
|
||||||
"github.com/toolkits/pkg/nux"
|
"github.com/toolkits/pkg/nux"
|
||||||
|
"github.com/toolkits/pkg/slice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeviceMetrics() []*dataobj.MetricValue {
|
func DeviceMetrics() []*dataobj.MetricValue {
|
||||||
|
@ -21,26 +22,11 @@ func DeviceMetrics() []*dataobj.MetricValue {
|
||||||
return ret
|
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 diskTotal uint64 = 0
|
||||||
var diskUsed uint64 = 0
|
var diskUsed uint64 = 0
|
||||||
|
|
||||||
for idx := range mountPoints {
|
for idx := range mountPoints {
|
||||||
fsSpec, fsFile, fsVfstype := mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2]
|
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 {
|
if _, exists := fsFileFilter[fsFile]; exists {
|
||||||
logger.Debugf("mount point %s was collected", fsFile)
|
logger.Debugf("mount point %s was collected", fsFile)
|
||||||
|
@ -49,7 +35,9 @@ func DeviceMetrics() []*dataobj.MetricValue {
|
||||||
fsFileFilter[fsFile] = struct{}{}
|
fsFileFilter[fsFile] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasIgnorePrefix(fsFile, ignoreMountPointsPrefix) {
|
// 注意: 虽然前缀被忽略了,但是被忽略的这部分分区里边有些仍然是需要采集的
|
||||||
|
if hasIgnorePrefix(fsFile, sys.Config.MountIgnore.Prefix) &&
|
||||||
|
!slice.ContainsString(sys.Config.MountIgnore.Exclude, fsFile) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/toolkits/pkg/logger"
|
"github.com/toolkits/pkg/logger"
|
||||||
"github.com/toolkits/pkg/nux"
|
"github.com/toolkits/pkg/nux"
|
||||||
|
"github.com/toolkits/pkg/slice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FsRWMetrics() []*dataobj.MetricValue {
|
func FsRWMetrics() []*dataobj.MetricValue {
|
||||||
|
@ -26,8 +27,6 @@ func FsRWMetrics() []*dataobj.MetricValue {
|
||||||
|
|
||||||
fsFileFilter := make(map[string]struct{}) //过滤 /proc/mounts 出现重复的fsFile
|
fsFileFilter := make(map[string]struct{}) //过滤 /proc/mounts 出现重复的fsFile
|
||||||
|
|
||||||
ignoreMountPointsPrefix := sys.Config.MountIgnorePrefix
|
|
||||||
|
|
||||||
for idx := range mountPoints {
|
for idx := range mountPoints {
|
||||||
var du *nux.DeviceUsage
|
var du *nux.DeviceUsage
|
||||||
du, err = nux.BuildDeviceUsage(mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2])
|
du, err = nux.BuildDeviceUsage(mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2])
|
||||||
|
@ -36,7 +35,8 @@ func FsRWMetrics() []*dataobj.MetricValue {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasIgnorePrefix(mountPoints[idx][1], ignoreMountPointsPrefix) {
|
if hasIgnorePrefix(du.FsFile, sys.Config.MountIgnore.Prefix) &&
|
||||||
|
!slice.ContainsString(sys.Config.MountIgnore.Exclude, du.FsFile) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue