mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-28 01:47:20 +00:00
Add support for basic system metrics for Windows.
This commit is contained in:
@@ -116,3 +116,14 @@ Below metrics are collected from `net` component:
|
||||
* `net/tx_compressed`: Cumulative count of compressed packets transmitted by the device driver.
|
||||
|
||||
All of the above have `interface_name` label for the net interface.
|
||||
|
||||
## Windows Support
|
||||
|
||||
NPD has preliminary support for system stats monitor. The following modules are supported:
|
||||
|
||||
* CPU - Idle, System, and User metrics.
|
||||
* Memory - Used and available.
|
||||
* Disk - Space used and free.
|
||||
* Uptime - within kernel version and product name.
|
||||
|
||||
All the data is currently retried from the `github.com/shirou/gopsutil` library. Any data parsed directly from `/proc` from Linux is not supported on Windows. There will be later integration to use WMI (Windows Management Instrumentation) to gather node metrics.
|
||||
|
||||
@@ -17,12 +17,8 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
@@ -174,24 +170,6 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig) *cpuCollector {
|
||||
return &cc
|
||||
}
|
||||
|
||||
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) recordUsage() {
|
||||
if cc.mUsageTime == nil {
|
||||
return
|
||||
@@ -236,46 +214,6 @@ func (cc *cpuCollector) recordUsage() {
|
||||
cc.lastUsageTime["guest_nice"] = clockTick * timersStat.GuestNice
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func (cc *cpuCollector) collect() {
|
||||
if cc == nil {
|
||||
return
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright 2021 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 (
|
||||
"testing"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
)
|
||||
|
||||
func TestDiskCollector(t *testing.T) {
|
||||
dc := NewDiskCollectorOrDie(&ssmtypes.DiskStatsConfig{})
|
||||
dc.collect()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2021 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 (
|
||||
"testing"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
)
|
||||
|
||||
func TestHostCollector(t *testing.T) {
|
||||
hc := NewHostCollectorOrDie(&ssmtypes.HostStatsConfig{})
|
||||
hc.collect()
|
||||
val, ok := hc.tags["os_version"]
|
||||
if !ok {
|
||||
t.Errorf("tags[os_version] should exist.")
|
||||
} else if val == "" {
|
||||
t.Errorf("tags[os_version] should not be empty")
|
||||
}
|
||||
|
||||
val, ok = hc.tags["kernel_version"]
|
||||
if !ok {
|
||||
t.Errorf("tags[kernel_version] should exist.")
|
||||
} else if val == "" {
|
||||
t.Errorf("tags[kernel_version] should not be empty")
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
@@ -96,48 +95,3 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
|
||||
return &mc
|
||||
}
|
||||
|
||||
func (mc *memoryCollector) collect() {
|
||||
if mc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
proc, err := procfs.NewDefaultFS()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to find /proc mount point: %v", err)
|
||||
return
|
||||
}
|
||||
meminfo, err := proc.Meminfo()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve memory stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if mc.mBytesUsed != nil {
|
||||
memUsed := meminfo.MemTotal - meminfo.MemFree - meminfo.Buffers - meminfo.Cached - meminfo.Slab
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "free"}, int64(meminfo.MemFree)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "used"}, int64(memUsed)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "buffered"}, int64(meminfo.Buffers)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "cached"}, int64(meminfo.Cached)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "slab"}, int64(meminfo.Slab)*1024)
|
||||
}
|
||||
|
||||
if mc.mDirtyUsed != nil {
|
||||
mc.mDirtyUsed.Record(map[string]string{stateLabel: "dirty"}, int64(meminfo.Dirty)*1024)
|
||||
mc.mDirtyUsed.Record(map[string]string{stateLabel: "writeback"}, int64(meminfo.Writeback)*1024)
|
||||
}
|
||||
|
||||
if mc.mAnonymousUsed != nil {
|
||||
mc.mAnonymousUsed.Record(map[string]string{stateLabel: "active"}, int64(meminfo.ActiveAnon)*1024)
|
||||
mc.mAnonymousUsed.Record(map[string]string{stateLabel: "inactive"}, int64(meminfo.InactiveAnon)*1024)
|
||||
}
|
||||
|
||||
if mc.mPageCacheUsed != nil {
|
||||
mc.mPageCacheUsed.Record(map[string]string{stateLabel: "active"}, int64(meminfo.ActiveFile)*1024)
|
||||
mc.mPageCacheUsed.Record(map[string]string{stateLabel: "inactive"}, int64(meminfo.InactiveFile)*1024)
|
||||
}
|
||||
|
||||
if mc.mUnevictableUsed != nil {
|
||||
mc.mUnevictableUsed.Record(map[string]string{}, int64(meminfo.Unevictable)*1024)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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 (
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
)
|
||||
|
||||
func (mc *memoryCollector) collect() {
|
||||
if mc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
proc, err := procfs.NewDefaultFS()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to find /proc mount point: %v", err)
|
||||
return
|
||||
}
|
||||
meminfo, err := proc.Meminfo()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve memory stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if mc.mBytesUsed != nil {
|
||||
memUsed := meminfo.MemTotal - meminfo.MemFree - meminfo.Buffers - meminfo.Cached - meminfo.Slab
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "free"}, int64(meminfo.MemFree)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "used"}, int64(memUsed)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "buffered"}, int64(meminfo.Buffers)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "cached"}, int64(meminfo.Cached)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "slab"}, int64(meminfo.Slab)*1024)
|
||||
}
|
||||
|
||||
if mc.mDirtyUsed != nil {
|
||||
mc.mDirtyUsed.Record(map[string]string{stateLabel: "dirty"}, int64(meminfo.Dirty)*1024)
|
||||
mc.mDirtyUsed.Record(map[string]string{stateLabel: "writeback"}, int64(meminfo.Writeback)*1024)
|
||||
}
|
||||
|
||||
if mc.mAnonymousUsed != nil {
|
||||
mc.mAnonymousUsed.Record(map[string]string{stateLabel: "active"}, int64(meminfo.ActiveAnon)*1024)
|
||||
mc.mAnonymousUsed.Record(map[string]string{stateLabel: "inactive"}, int64(meminfo.InactiveAnon)*1024)
|
||||
}
|
||||
|
||||
if mc.mPageCacheUsed != nil {
|
||||
mc.mPageCacheUsed.Record(map[string]string{stateLabel: "active"}, int64(meminfo.ActiveFile)*1024)
|
||||
mc.mPageCacheUsed.Record(map[string]string{stateLabel: "inactive"}, int64(meminfo.InactiveFile)*1024)
|
||||
}
|
||||
|
||||
if mc.mUnevictableUsed != nil {
|
||||
mc.mUnevictableUsed.Record(map[string]string{}, int64(meminfo.Unevictable)*1024)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 (
|
||||
"testing"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
)
|
||||
|
||||
func TestMemoryCollector(t *testing.T) {
|
||||
mc := NewMemoryCollectorOrDie(&ssmtypes.MemoryStatsConfig{})
|
||||
mc.collect()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 (
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
func (mc *memoryCollector) collect() {
|
||||
if mc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
meminfo, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
glog.Errorf("cannot get windows memory metrics from GlobalMemoryStatusEx: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if mc.mBytesUsed != nil {
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "free"}, int64(meminfo.Available)*1024)
|
||||
mc.mBytesUsed.Record(map[string]string{stateLabel: "used"}, int64(meminfo.Used)*1024)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user