From 9bf26341aabd6a727c7e02e6c938282161f68b95 Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Sat, 30 Nov 2024 15:12:32 +0100 Subject: [PATCH] feat: info & stats commands --- dlinux | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/dlinux b/dlinux index 2cd122c..cb7f644 100755 --- a/dlinux +++ b/dlinux @@ -13,23 +13,52 @@ print_help() { printf " $0 hello - Get a hello message $0 name - Get your SSHID +$0 info - Get info about your container +$0 stats - Get your container memory usage statistics " } # Helper function call_api() { - curl -X $1 -H "x-ssh-auth: $API_KEY" "https://api.ssh.surf/$2" + curl -X $1 -H "x-ssh-auth: $API_KEY" "https://api.ssh.surf/$2" 2> /dev/null } # Commands command_hello() { - call_api GET hello | jq .message + call_api GET hello | jq -r .message } command_name() { - call_api GET name | jq .message + call_api GET name | jq -r .message +} + +command_info() { + data=$(call_api GET info) + + printf " +Name: $(echo $data | jq -r .data.name) +IP Address: $(echo $data | jq -r .data.IPAddress) +MAC Address: $(echo $data | jq -r .data.MACAddress) +Memory: $(echo $data | jq -r .data.memory) +CPUs: $(echo $data | jq -r .data.cpus) +Restart policy: $(echo $data | jq -r .data.restartPolicy.Name) +Restarts: $(echo $data | jq -r .data.restarts) +State: $(echo $data | jq -r .data.state.Status) +Pid: $(echo $data | jq -r .data.state.Pid) +Started at: $(echo $data | jq -r .data.state.StartedAt) +" +} + +command_stats() { + data=$(call_api GET stats) + + printf " +Raw: $(echo $data | jq -r .data.memory.raw) +Percentage: $(echo $data | jq -r .data.memory.percent)% +CPU: $(echo $data | jq -r .data.cpu)% +" } # Command handler