-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from jeremyje/osversion
Add support for basic system metrics for Windows.
- Loading branch information
Showing
19 changed files
with
660 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"cpu": { | ||
"metricsConfigs": { | ||
"cpu/load_15m": { | ||
"displayName": "cpu/load_15m" | ||
}, | ||
"cpu/load_1m": { | ||
"displayName": "cpu/load_1m" | ||
}, | ||
"cpu/load_5m": { | ||
"displayName": "cpu/load_5m" | ||
}, | ||
"cpu/runnable_task_count": { | ||
"displayName": "cpu/runnable_task_count" | ||
}, | ||
"cpu/usage_time": { | ||
"displayName": "cpu/usage_time" | ||
}, | ||
"system/cpu_stat": { | ||
"displayName": "system/cpu_stat" | ||
}, | ||
"system/interrupts_total": { | ||
"displayName": "system/interrupts_total" | ||
}, | ||
"system/processes_total": { | ||
"displayName": "system/processes_total" | ||
}, | ||
"system/procs_blocked": { | ||
"displayName": "system/procs_blocked" | ||
}, | ||
"system/procs_running": { | ||
"displayName": "system/procs_running" | ||
} | ||
} | ||
}, | ||
"disk": { | ||
"includeAllAttachedBlk": false, | ||
"includeRootBlk": false, | ||
"lsblkTimeout": "60s", | ||
"metricsConfigs": { | ||
"disk/avg_queue_len": { | ||
"displayName": "disk/avg_queue_len" | ||
}, | ||
"disk/bytes_used": { | ||
"displayName": "disk/bytes_used" | ||
}, | ||
"disk/io_time": { | ||
"displayName": "disk/io_time" | ||
}, | ||
"disk/merged_operation_count": { | ||
"displayName": "disk/merged_operation_count" | ||
}, | ||
"disk/operation_bytes_count": { | ||
"displayName": "disk/operation_bytes_count" | ||
}, | ||
"disk/operation_count": { | ||
"displayName": "disk/operation_count" | ||
}, | ||
"disk/operation_time": { | ||
"displayName": "disk/operation_time" | ||
}, | ||
"disk/weighted_io": { | ||
"displayName": "disk/weighted_io" | ||
} | ||
} | ||
}, | ||
"host": { | ||
"metricsConfigs": { | ||
"host/uptime": { | ||
"displayName": "host/uptime" | ||
} | ||
} | ||
}, | ||
"invokeInterval": "60s", | ||
"memory": { | ||
"metricsConfigs": { | ||
"memory/anonymous_used": { | ||
"displayName": "memory/anonymous_used" | ||
}, | ||
"memory/bytes_used": { | ||
"displayName": "memory/bytes_used" | ||
}, | ||
"memory/dirty_used": { | ||
"displayName": "memory/dirty_used" | ||
}, | ||
"memory/page_cache_used": { | ||
"displayName": "memory/page_cache_used" | ||
}, | ||
"memory/unevictable_used": { | ||
"displayName": "memory/unevictable_used" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package systemstatsmonitor | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
"github.com/prometheus/procfs" | ||
"github.com/shirou/gopsutil/load" | ||
) | ||
|
||
func (cc *cpuCollector) recordLoad() { | ||
if cc.mRunnableTaskCount == nil { | ||
return | ||
} | ||
|
||
loadAvg, err := load.Avg() | ||
if err != nil { | ||
glog.Errorf("Failed to retrieve average CPU load: %v", err) | ||
return | ||
} | ||
|
||
cc.mRunnableTaskCount.Record(map[string]string{}, loadAvg.Load1) | ||
|
||
cc.mCpuLoad1m.Record(map[string]string{}, loadAvg.Load1) | ||
cc.mCpuLoad5m.Record(map[string]string{}, loadAvg.Load5) | ||
cc.mCpuLoad15m.Record(map[string]string{}, loadAvg.Load15) | ||
} | ||
|
||
func (cc *cpuCollector) recordSystemStats() { | ||
fs, err := procfs.NewFS("/proc") | ||
stats, err := fs.Stat() | ||
if err != nil { | ||
glog.Errorf("Failed to retrieve cpu/process stats: %v", err) | ||
return | ||
} | ||
|
||
cc.mSystemProcessesTotal.Record(map[string]string{}, int64(stats.ProcessCreated)) | ||
cc.mSystemProcsRunning.Record(map[string]string{}, int64(stats.ProcessesRunning)) | ||
cc.mSystemProcsBlocked.Record(map[string]string{}, int64(stats.ProcessesBlocked)) | ||
cc.mSystemInterruptsTotal.Record(map[string]string{}, int64(stats.IRQTotal)) | ||
|
||
for i, c := range stats.CPU { | ||
tags := map[string]string{} | ||
tags[cpuLabel] = fmt.Sprintf("cpu%d", i) | ||
|
||
tags[stageLabel] = "user" | ||
cc.mSystemCPUStat.Record(tags, c.User) | ||
tags[stageLabel] = "nice" | ||
cc.mSystemCPUStat.Record(tags, c.Nice) | ||
tags[stageLabel] = "system" | ||
cc.mSystemCPUStat.Record(tags, c.System) | ||
tags[stageLabel] = "idle" | ||
cc.mSystemCPUStat.Record(tags, c.Idle) | ||
tags[stageLabel] = "iowait" | ||
cc.mSystemCPUStat.Record(tags, c.Iowait) | ||
tags[stageLabel] = "iRQ" | ||
cc.mSystemCPUStat.Record(tags, c.IRQ) | ||
tags[stageLabel] = "softIRQ" | ||
cc.mSystemCPUStat.Record(tags, c.SoftIRQ) | ||
tags[stageLabel] = "steal" | ||
cc.mSystemCPUStat.Record(tags, c.Steal) | ||
tags[stageLabel] = "guest" | ||
cc.mSystemCPUStat.Record(tags, c.Guest) | ||
tags[stageLabel] = "guestNice" | ||
cc.mSystemCPUStat.Record(tags, c.GuestNice) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package systemstatsmonitor | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" | ||
) | ||
|
||
const ( | ||
fakeCPUConfig = ` | ||
{ | ||
"metricsConfigs": { | ||
"cpu/load_15m": { | ||
"displayName": "cpu/load_15m" | ||
}, | ||
"cpu/load_1m": { | ||
"displayName": "cpu/load_1m" | ||
}, | ||
"cpu/load_5m": { | ||
"displayName": "cpu/load_5m" | ||
}, | ||
"cpu/runnable_task_count": { | ||
"displayName": "cpu/runnable_task_count" | ||
}, | ||
"cpu/usage_time": { | ||
"displayName": "cpu/usage_time" | ||
}, | ||
"system/cpu_stat": { | ||
"displayName": "system/cpu_stat" | ||
}, | ||
"system/interrupts_total": { | ||
"displayName": "system/interrupts_total" | ||
}, | ||
"system/processes_total": { | ||
"displayName": "system/processes_total" | ||
}, | ||
"system/procs_blocked": { | ||
"displayName": "system/procs_blocked" | ||
}, | ||
"system/procs_running": { | ||
"displayName": "system/procs_running" | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
func TestCpuCollector(t *testing.T) { | ||
cfg := &ssmtypes.CPUStatsConfig{} | ||
if err := json.Unmarshal([]byte(fakeCPUConfig), cfg); err != nil { | ||
t.Fatalf("cannot load cpu config: %s", err) | ||
} | ||
mc := NewCPUCollectorOrDie(cfg) | ||
mc.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package systemstatsmonitor | ||
|
||
func (cc *cpuCollector) recordLoad() { | ||
// not supported | ||
} | ||
|
||
func (cc *cpuCollector) recordSystemStats() { | ||
// not supported | ||
} |
Oops, something went wrong.