-
Notifications
You must be signed in to change notification settings - Fork 36
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
1 parent
6bd6ab2
commit c56dfa1
Showing
5 changed files
with
104 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build linux | ||
|
||
package sysinfo | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"regexp" | ||
) | ||
|
||
func cpuModel() string { | ||
column := regexp.MustCompile("\t+: ") | ||
|
||
f, _ := os.Open("/proc/cpuinfo") | ||
defer f.Close() | ||
|
||
s := bufio.NewScanner(f) | ||
|
||
for s.Scan() { | ||
sl := column.Split(s.Text(), 2) | ||
if sl == nil { | ||
continue | ||
} | ||
|
||
// pfft, who needs multiple cpus? just return if we got all we need | ||
if sl[0] == "model name" { | ||
return sl[1] | ||
} | ||
} | ||
|
||
return "unknown cpu" | ||
} |
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,36 @@ | ||
package sysinfo | ||
|
||
import ( | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
type kernel struct { | ||
Release string | ||
Version string | ||
} | ||
|
||
func getKernel() kernel { | ||
var un syscall.Utsname | ||
_ = syscall.Uname(&un) | ||
|
||
return kernel{ | ||
Release: unameString(un.Release), | ||
Version: unameString(un.Version), | ||
} | ||
} | ||
|
||
func (k kernel) String() string { | ||
return k.Release + " " + k.Version | ||
} | ||
|
||
func unameString(unarr [65]int8) string { | ||
var sb strings.Builder | ||
for _, b := range unarr[:] { | ||
if b == 0 { | ||
break | ||
} | ||
sb.WriteByte(byte(b)) | ||
} | ||
return sb.String() | ||
} |
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