How on golang find out the CPU load, computer name and user name on the computer?
- os / user will answer at least two recent questions. - KoVadim
|
1 answer
On stackoverflow, it is customary not to mix many questions into one.
1. Current user name
Package os/user . Example:
package main import ( "os/user" "log" "fmt" ) func main() { // текущий пользователь cur, err := user.Current() if err != nil { log.Fatal(err) } fmt.Println("Current user:", cur) } There is another choice of the user by name and by identifier. Play.golang.org does not work.
2. Computer name.
The os.Hostname function. Play
3. Processor load.
Use third-party libraries.
- @ "Ivan Black" Thank you. And which third-party libraries and how to connect them? Could you tell? - Rakzin Roman pm
- I just here found socketloop.com/references/… - Rakzin Roman
- @RakzinRoman, I used this one gosigar . But
githubnot a stable branch. However, you can use thevendorfolder if go1.5 +. Orgodepfor older versions. - Ivan Black
|