mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 18:09:57 +00:00
Reduce the number of reads to /proc/partitions file
to retrive the partitions on disk
This commit is contained in:
@@ -244,8 +244,15 @@ func (dc *diskCollector) collect() {
|
||||
if dc.config.IncludeRootBlk {
|
||||
devices = append(devices, listRootBlockDevices(dc.config.LsblkTimeout)...)
|
||||
}
|
||||
|
||||
partitions, err := disk.Partitions(false)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to list disk partitions: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if dc.config.IncludeAllAttachedBlk {
|
||||
devices = append(devices, listAttachedBlockDevices()...)
|
||||
devices = append(devices, listAttachedBlockDevices(partitions)...)
|
||||
}
|
||||
|
||||
// Fetch metrics from /proc, /sys.
|
||||
@@ -254,11 +261,6 @@ func (dc *diskCollector) collect() {
|
||||
glog.Errorf("Failed to retrieve disk IO counters: %v", err)
|
||||
return
|
||||
}
|
||||
partitions, err := disk.Partitions(false)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to list disk partitions: %v", err)
|
||||
return
|
||||
}
|
||||
sampleTime := time.Now()
|
||||
defer func() { dc.lastSampleTime = sampleTime }()
|
||||
|
||||
@@ -310,15 +312,9 @@ func listRootBlockDevices(timeout time.Duration) []string {
|
||||
}
|
||||
|
||||
// listAttachedBlockDevices lists all currently attached block devices.
|
||||
func listAttachedBlockDevices() []string {
|
||||
func listAttachedBlockDevices(partitions []disk.PartitionStat) []string {
|
||||
blks := []string{}
|
||||
|
||||
partitions, err := disk.Partitions(false)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve the list of disk partitions: %v", err)
|
||||
return blks
|
||||
}
|
||||
|
||||
for _, partition := range partitions {
|
||||
blks = append(blks, partition.Device)
|
||||
}
|
||||
|
||||
@@ -28,4 +28,4 @@ func TestRegistration(t *testing.T) {
|
||||
assert.NotPanics(t,
|
||||
func() { problemdaemon.GetProblemDaemonHandlerOrDie(SystemStatsMonitorName) },
|
||||
"System stats monitor failed to register itself as a problem daemon.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user