-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
160 additions
and
13 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
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
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
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
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,59 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// SysCPU reflects cpu system information from /sys/devices/system/cpu/cpu* | ||
type SysCPU struct { | ||
MaxFreq float32 | ||
MinFreq float32 | ||
CurFreq float32 | ||
} | ||
|
||
// GetSysCPU returns the system CPU information for available cores | ||
func GetSysCPU() []SysCPU { | ||
stats := []SysCPU{} | ||
|
||
files, err := filepath.Glob("/sys/devices/system/cpu/cpu[0-999]") | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Cannot read cpu infos from sys fs: %s\n", err) | ||
return stats | ||
} | ||
|
||
var filepath string | ||
var filecontent []byte | ||
for _, f := range files { | ||
cpuStat := SysCPU{} | ||
|
||
filepath = fmt.Sprint(f + "/cpufreq/cpuinfo_max_freq") | ||
filecontent, _ = ioutil.ReadFile(filepath) | ||
fmt.Fscan( | ||
bytes.NewBuffer(filecontent), | ||
&cpuStat.MaxFreq, | ||
) | ||
|
||
filepath = fmt.Sprint(f + "/cpufreq/cpuinfo_min_freq") | ||
filecontent, _ = ioutil.ReadFile(filepath) | ||
fmt.Fscan( | ||
bytes.NewBuffer(filecontent), | ||
&cpuStat.MinFreq, | ||
) | ||
|
||
filepath = fmt.Sprint(f + "/cpufreq/scaling_cur_freq") | ||
filecontent, _ = ioutil.ReadFile(filepath) | ||
fmt.Fscan( | ||
bytes.NewBuffer(filecontent), | ||
&cpuStat.CurFreq, | ||
) | ||
|
||
stats = append(stats, cpuStat) | ||
|
||
} | ||
|
||
return stats | ||
} |
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,24 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
// SysNetSpeed reflects network interface speed from /sys/class/net/$iface/speed | ||
type SysNetSpeed struct { | ||
Value float32 | ||
} | ||
|
||
// GetSysNetSpeed reads the network device's speed from /sys/class/net | ||
func GetSysNetSpeed(devName string) SysNetSpeed { | ||
stat := SysNetSpeed{} | ||
filepath := fmt.Sprint("/sys/class/net/" + devName + "/speed") | ||
filecontent, _ := ioutil.ReadFile(filepath) | ||
fmt.Fscan( | ||
bytes.NewBuffer(filecontent), | ||
&stat.Value, | ||
) | ||
return stat | ||
} |