-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1122 from allencloud/add-options
feature: add more daemon option in get /info API
Showing
5 changed files
with
111 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package system | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// file to check to determine Operating System | ||
const etcOsRelease = "/etc/os-release" | ||
|
||
// GetOSName gets data in /etc/os-release and gets OS name. | ||
// For example, in a Ubuntu host, fetched data are like: | ||
// root@i-8brpbc9t:~# cat /etc/os-release | ||
// NAME="Ubuntu" | ||
// VERSION="16.04.2 LTS (Xenial Xerus)" | ||
// ID=ubuntu | ||
// ID_LIKE=debian | ||
// PRETTY_NAME="Ubuntu 16.04.2 LTS" | ||
// VERSION_ID="16.04" | ||
// HOME_URL="http://www.ubuntu.com/" | ||
// SUPPORT_URL="http://help.ubuntu.com/" | ||
// BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" | ||
// VERSION_CODENAME=xenial | ||
// UBUNTU_CODENAME=xenial | ||
func GetOSName() (string, error) { | ||
etcOsReleaseFile, err := os.Open(etcOsRelease) | ||
if err != nil { | ||
if !os.IsNotExist(err) { | ||
return "", fmt.Errorf("failed to open %s: %v", etcOsRelease, err) | ||
} | ||
} | ||
defer etcOsReleaseFile.Close() | ||
|
||
var prettyName string | ||
|
||
scanner := bufio.NewScanner(etcOsReleaseFile) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if !strings.HasPrefix(line, "PRETTY_NAME=") { | ||
continue | ||
} | ||
|
||
data := strings.SplitN(line, "=", 2) | ||
prettyName = data[1] | ||
return prettyName, nil | ||
} | ||
|
||
return "Linux", nil | ||
|
||
} |
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 system | ||
|
||
import ( | ||
"syscall" | ||
) | ||
|
||
// getSysInfo gets sysinfo. | ||
func getSysInfo() (*syscall.Sysinfo_t, error) { | ||
si := &syscall.Sysinfo_t{} | ||
err := syscall.Sysinfo(si) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return si, nil | ||
} | ||
|
||
// GetTotalMem gets total ram of host. | ||
func GetTotalMem() (uint64, error) { | ||
si, err := getSysInfo() | ||
if err != nil { | ||
return 0, err | ||
} | ||
return si.Totalram, nil | ||
} |
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