github.com/minio/madmin-go/v2@v2.2.1/cpu_linux.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  // Copyright (c) 2015-2022 MinIO, Inc.
     5  //
     6  // This file is part of MinIO Object Storage stack
     7  //
     8  // This program is free software: you can redistribute it and/or modify
     9  // it under the terms of the GNU Affero General Public License as
    10  // published by the Free Software Foundation, either version 3 of the
    11  // License, or (at your option) any later version.
    12  //
    13  // This program is distributed in the hope that it will be useful,
    14  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  // GNU Affero General Public License for more details.
    17  //
    18  // You should have received a copy of the GNU Affero General Public License
    19  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    20  //
    21  
    22  package madmin
    23  
    24  import (
    25  	"github.com/prometheus/procfs/sysfs"
    26  )
    27  
    28  func getCPUFreqStats() ([]CPUFreqStats, error) {
    29  	fs, err := sysfs.NewFS("/sys")
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	stats, err := fs.SystemCpufreq()
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	out := make([]CPUFreqStats, 0, len(stats))
    40  	for _, stat := range stats {
    41  		out = append(out, CPUFreqStats{
    42  			Name:                     stat.Name,
    43  			CpuinfoCurrentFrequency:  stat.CpuinfoCurrentFrequency,
    44  			CpuinfoMinimumFrequency:  stat.CpuinfoMinimumFrequency,
    45  			CpuinfoMaximumFrequency:  stat.CpuinfoMaximumFrequency,
    46  			CpuinfoTransitionLatency: stat.CpuinfoTransitionLatency,
    47  			ScalingCurrentFrequency:  stat.ScalingCurrentFrequency,
    48  			ScalingMinimumFrequency:  stat.ScalingMinimumFrequency,
    49  			ScalingMaximumFrequency:  stat.ScalingMaximumFrequency,
    50  			AvailableGovernors:       stat.AvailableGovernors,
    51  			Driver:                   stat.Driver,
    52  			Governor:                 stat.Governor,
    53  			RelatedCpus:              stat.RelatedCpus,
    54  			SetSpeed:                 stat.SetSpeed,
    55  		})
    56  	}
    57  	return out, nil
    58  }