Reduce the number of reads to /proc/partitions file

to retrive the partitions on disk
This commit is contained in:
varsha teratipally
2021-06-13 21:11:34 +00:00
parent 1150ce519f
commit 7b51a90328
2 changed files with 10 additions and 14 deletions

View File

@@ -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)
}

View File

@@ -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.")
}
}