-
Notifications
You must be signed in to change notification settings - Fork 0
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
cf6ac7a
commit 648a331
Showing
15 changed files
with
188 additions
and
27 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
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
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,41 @@ | ||
package subcommands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/api" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/spinner" | ||
) | ||
|
||
var HealthCheckCmd = &cobra.Command{ | ||
Use: "healthcheck", | ||
Short: "Checks if the Runtipi system is up and running use the API", | ||
Long: "Checks if the Runtipi system is up and running using the worker API", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Define Path | ||
path := "healthcheck" | ||
|
||
// Start Spinner | ||
spinner.SetMessage("Checking system") | ||
spinner.Start() | ||
|
||
// Do Check | ||
response, err := api.ApiRequest(path, "GET", 1 * time.Minute) | ||
|
||
if err != nil { | ||
spinner.Fail("Failed to check system, is runtipi running?") | ||
spinner.Stop() | ||
fmt.Printf("Error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
defer response.Body.Close() | ||
|
||
// Succeed | ||
spinner.Succeed("Runtipi system up and running") | ||
spinner.Stop() | ||
}, | ||
} |
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,62 @@ | ||
package subcommands | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/api" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/constants" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/schemas" | ||
"github.com/steveiliop56/runtipi-cli-go/internal/spinner" | ||
) | ||
|
||
var StatusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Gets system readings from the Runtipi API", | ||
Long: "Shows the system readings (e.g. cpu usage, disk usage) from the Runtipi worker API", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Define Path | ||
path := "system-status" | ||
|
||
// Start Spinner | ||
spinner.SetMessage("Getting system status") | ||
spinner.Start() | ||
|
||
// Do Check | ||
response, err := api.ApiRequest(path, "GET", 1 * time.Minute) | ||
|
||
if err != nil { | ||
spinner.Fail("Failed to get system status, is runtipi running?") | ||
spinner.Stop() | ||
fmt.Printf("Error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Parse Json | ||
|
||
status := new(schemas.SystemStatusApi) | ||
|
||
jsonErr := json.NewDecoder(response.Body).Decode(&status) | ||
|
||
if jsonErr != nil { | ||
spinner.Fail("Failed to decode system status json") | ||
spinner.Stop() | ||
fmt.Printf("Error: %s\n", jsonErr) | ||
os.Exit(1) | ||
} | ||
|
||
defer response.Body.Close() | ||
|
||
// Succeed | ||
spinner.Succeed("Successfully got system status") | ||
spinner.Stop() | ||
|
||
// Print status | ||
fmt.Printf("Your CPU usage is %s %% \n", constants.Blue(fmt.Sprintf("%.2f", status.Data.CpuLoad))) | ||
fmt.Printf("Your Disk size is %s GB, you are using %s GB which is %s %% \n", constants.Blue(status.Data.DiskSize), constants.Blue(status.Data.DiskUsed), constants.Blue(status.Data.PercentUsed)) | ||
fmt.Printf("Your Memory size is %s GB and you are using %s %% \n", constants.Blue(status.Data.MemoryTotal), constants.Blue(status.Data.PercentUsedMemory)) | ||
}, | ||
} |
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,17 @@ | ||
package system | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/steveiliop56/runtipi-cli-go/cmd/system/subcommands" | ||
) | ||
|
||
func SystemCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "system", | ||
Short: "System commands", | ||
Long: "Control your Runtipi system through the CLI", | ||
} | ||
cmd.AddCommand(subcommands.HealthCheckCmd) | ||
cmd.AddCommand(subcommands.StatusCmd) | ||
return cmd | ||
} |
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
Oops, something went wrong.