Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize netcollector implementation and custom /proc mount path #594

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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