Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const DEFAULT_REFRESH = 5 // default refresh interval in seconds

func usage(code int) {
fmt.Printf(
`rtop %s - (c) 2015 RapidLoop - MIT Licensed - http://rtop-monitor.org
`rtop %s - (c) 2015 RapidLoop - MIT Licensed - http://rtop-monitor.org
rtop monitors server statistics over an ssh connection

Usage: rtop [-i private-key-file] [user@]host[:port] [interval]
Expand Down Expand Up @@ -144,6 +144,21 @@ func parseCmdLine() (key, username, addr string, interval time.Duration) {
return
}

//rtop only support for Linux system
func validateOS(client *ssh.Client) {
ostype, err := runCommand(client, "uname")
if err != nil {
os.Exit(1)
}
//remove newline character
ostype = strings.Trim(ostype, "\n")

if !strings.EqualFold(ostype, "Linux") {
fmt.Println("\nrtop not support for ", ostype, "system\n")
os.Exit(1)
}
}

//----------------------------------------------------------------------------

func main() {
Expand All @@ -154,6 +169,7 @@ func main() {
keyPath, username, addr, interval := parseCmdLine()

client := sshConnect(username, addr, keyPath)
validateOS(client)

// the loop
showStats(client)
Expand All @@ -177,7 +193,7 @@ func showStats(client *ssh.Client) {
getAllStats(client, &stats)
used := stats.MemTotal - stats.MemFree - stats.MemBuffers - stats.MemCached
fmt.Printf(
`%s%s%s%s up %s%s%s
`%s%s%s%s up %s%s%s

Load:
%s%s %s %s%s
Expand Down