Skip to content

Commit

Permalink
Merge pull request #594 from oif/chore/optimize-netcollector-implemen…
Browse files Browse the repository at this point in the history
…tation

optimize netcollector implementation and custom `/proc` mount path
  • Loading branch information
k8s-ci-robot authored Apr 11, 2022
2 parents 4412a2b + 11ddb5e commit 285516d
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 226 deletions.
10 changes: 7 additions & 3 deletions pkg/systemstatsmonitor/cpu_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ type cpuCollector struct {
mSystemInterruptsTotal *metrics.Int64Metric
mSystemCPUStat *metrics.Float64Metric // per-cpu time from /proc/stats

config *ssmtypes.CPUStatsConfig
config *ssmtypes.CPUStatsConfig
procPath string

lastUsageTime map[string]float64
}

func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
cc := cpuCollector{config: cpuConfig}
func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *cpuCollector {
cc := cpuCollector{
config: cpuConfig,
procPath: procPath,
}

var err error
cc.mRunnableTaskCount, err = metrics.NewFloat64Metric(
Expand Down
3 changes: 1 addition & 2 deletions pkg/systemstatsmonitor/cpu_collector_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ func (cc *cpuCollector) recordLoad() {
}

func (cc *cpuCollector) recordSystemStats() {

// don't collect the load metrics if the configs are not present.
if cc.mSystemCPUStat == nil && cc.mSystemInterruptsTotal == nil &&
cc.mSystemProcessesTotal == nil && cc.mSystemProcsBlocked == nil &&
cc.mSystemProcsRunning == nil {
return
}

fs, err := procfs.NewFS("/proc")
fs, err := procfs.NewFS(cc.procPath)
stats, err := fs.Stat()
if err != nil {
glog.Errorf("Failed to retrieve cpu/process stats: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemstatsmonitor/cpu_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func TestCpuCollector(t *testing.T) {
if err := json.Unmarshal([]byte(fakeCPUConfig), cfg); err != nil {
t.Fatalf("cannot load cpu config: %s", err)
}
mc := NewCPUCollectorOrDie(cfg)
mc := NewCPUCollectorOrDie(cfg, "/proc")
mc.collect()
}
Loading

0 comments on commit 285516d

Please sign in to comment.