2020-12-25 17:20:30 -05:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"os/user"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"csctl/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Resources(*cli.Context) error {
|
|
|
|
u, _ := user.Current()
|
|
|
|
|
2020-12-25 17:24:41 -05:00
|
|
|
memoryUsage, err := internal.ContactSR(&internal.TCPData{Type: "ram", Username: u.Username})
|
2020-12-25 17:20:30 -05:00
|
|
|
if err != nil {
|
|
|
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
|
|
|
}
|
|
|
|
storageUsage, err := internal.ContactSR(&internal.TCPData{Type: "storage", Username: u.Username})
|
|
|
|
if err != nil {
|
|
|
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
|
|
|
}
|
|
|
|
processCount, err := internal.ContactSR(&internal.TCPData{Type: "processcount", Username: u.Username})
|
|
|
|
if err != nil {
|
|
|
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
|
|
|
}
|
|
|
|
sshLogins, err := internal.ContactSR(&internal.TCPData{Type: "sshlogins", Username: u.Username})
|
|
|
|
|
|
|
|
tableString := &strings.Builder{}
|
|
|
|
table := tablewriter.NewWriter(tableString)
|
|
|
|
table.SetHeader([]string{"RAM Usage", "Storage Usage", "Processes Running", "SSH Logins"})
|
|
|
|
table.Append([]string{memoryUsage, storageUsage, processCount, sshLogins})
|
|
|
|
table.Render()
|
|
|
|
|
|
|
|
fmt.Println(tableString.String())
|
|
|
|
return nil
|
|
|
|
}
|