Skip to content

Commit

Permalink
Add more detailed output on get-node-status script
Browse files Browse the repository at this point in the history
  • Loading branch information
hsoerensen committed Mar 15, 2024
1 parent c962b67 commit 9d5795d
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 13 deletions.
97 changes: 95 additions & 2 deletions bin/get-node-status
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
#!/bin/bash

execute_sudo() {
if sudo -v &> /dev/null; then
if [[ $(id -u) -eq 0 ]]; then
bash -c "$*"
else
sudo bash -c "$*"
fi
else
echo "The user does not have sudo privileges. Exiting the program."
exit 1
fi
}

get_last_committed_block() {
docker exec -it "${container_id}" bash -c "goal node status | grep 'Last committed block' | cut -d' ' -f4 | tr -cd '[:digit:]'"
}

get_account_info() {
if execute_sudo 'test ! -f "/var/lib/voi/algod/data/voitest-v1/accountList.json"'; then
abort "Account list not found. Exiting the program."
fi

accounts_json=$(execute_sudo 'cat /var/lib/voi/algod/data/voitest-v1/accountList.json')
number_of_accounts=$(echo "${accounts_json}" | jq '.Accounts | length')

if [[ ! $number_of_accounts -eq 1 ]]; then
echo "More than one account, or zero, found in wallet."
return 1
fi

account_address=$(echo "$accounts_json" | jq -r '.Accounts | keys[0]')
echo "${account_address}"
}

get_participation_expiration_eta() {
local active_key_last_valid_round=$1
local last_committed_block=$2
local current_key_blocks_remaining=$((active_key_last_valid_round - last_committed_block))
local remaining_seconds
local current_timestamp
local expiration_timestamp
local expiration_date

remaining_seconds=$(echo "${current_key_blocks_remaining}*2.9" | bc)
current_timestamp=$(date +%s)
expiration_timestamp=$(echo "${current_timestamp}+${remaining_seconds}" | bc)

# Convert the new timestamp to a date and time
expiration_date=$(date -d "@${expiration_timestamp}" '+%Y-%m-%d %H:%M')

echo "${expiration_date}"
}

display_participation_key_information() {
local existing_expiration_date
local active_key_last_valid_round
local last_committed_block
last_committed_block=$(get_last_committed_block)

active_key_last_valid_round=$(docker exec -it "${container_id}" bash -c 'goal account listpartkeys' | awk '$1=="yes" {print $6}' | tr -cd '[:digit:]')
existing_expiration_date=$(get_participation_expiration_eta "${active_key_last_valid_round}" "${last_committed_block}")

echo "Participation status: $(docker exec -it "${container_id}" bash -c 'goal account dump -a '"${account_address}"' | jq -r '\''if (.onl == 1) then "online" else "offline" end'\''')"
echo "Participation key expires at block: ${active_key_last_valid_round} (last committed: ${last_committed_block})"
echo "Participation key expected to expire at: ${existing_expiration_date}"
}

container_id=$(docker ps -q -f name=voinetwork_algod)
if [ -z "${container_id}" ]; then
echo "AVM container is not running. Please start it first."
Expand All @@ -26,9 +93,35 @@ else
health_checks["Daemon ready (and caught up)"]="false"
fi

# Print all health checks
echo "Health checks:"
echo "Voi Swarm Docker status:"
echo "**************"
swarm_running_image=$(docker inspect --format='{{.Image}}' "${container_id}" | cut -d':' -f2)
echo "Running container image (sha256): ${swarm_running_image}"
echo ""

echo "AVM version:"
echo "**************"
algod_version=$(docker exec -it "${container_id}" bash -c 'goal version -v')
account_address=$(get_account_info)
echo "${algod_version}"
echo ""

echo "Node health checks:"
echo "**************"
for check in "${!health_checks[@]}"; do
echo "$check: ${health_checks[$check]}"
done
echo ""

echo "Account status:"
echo "**************"
echo "Address: ${account_address}"
echo "Balance: $(docker exec -it "${container_id}" bash -c 'goal account balance -a '"${account_address}"'')"
display_participation_key_information

echo ""
echo "Telemetry status:"
echo "**************"
echo "Enabled: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .Enable")"
echo "Name: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .Name")"
echo "Short GUID: $(execute_sudo "cat /var/lib/voi/algod/data/logging.config | jq -r .GUID | cut -c 1-13")"
25 changes: 18 additions & 7 deletions docs/cli-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,30 @@ Open a bash shell in the AVM container with the following command:
~/voi/bin/start-shell
```

### Getting Basic Node Health
### Getting Node Health

To retrieve basic health information about your node, execute the following command:
To retrieve health information about your node, execute the following command:

```bash
~/voi/bin/get-node-status
```

The `get-node-status` command performs checks using:

- `goal node status` to connect to the running daemon and retrieve basic node information
- `/health`: This API endpoint checks the reported health of the node. [REST API /health documentation](https://developer.algorand.org/docs/rest-apis/algod/#get-health).
- `/ready`: This API endpoint checks the reported readiness of the node and if fully caught up. [REST API /ready documentation](https://developer.algorand.org/docs/rest-apis/algod/#get-ready).
The `get-node-status` command prints out the following information

- Running Voi Swarm image identifier
- AVM version
- Node health status
- High-level service status
- Health status and if service is running
- If the node is fully caught up with the chain
- Account status
- Address
- Balance
- Participation key status
- Telemetry status
- Enablement
- Name
- Short GUID

### Set Telemetry Name and GUID

Expand Down
2 changes: 1 addition & 1 deletion docs/installation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export VOINETWORK_IMPORT_ACCOUNT=1
???+ info
While the installation detects existing host-based setups (such as D13) on the same host
and offers migration automatically,
it is important to familiarize yourself with the [migration steps](../../migrating/) in particular
it is important to familiarize yourself with the [migration steps](../../migrating/), in particular,
if you are [migrating from a different host](../../migrating/#installing-on-a-new-server).
10 changes: 7 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ bold=$(tput bold)
normal=$(tput sgr0)

execute_sudo() {
if [[ ${is_root} -eq 1 ]]; then
bash -c "$1"
if sudo -v &> /dev/null; then
if [[ $(id -u) -eq 0 ]]; then
bash -c "$1"
else
sudo bash -c "$1"
fi
else
sudo bash -c "$1"
abort "Your user does not have sudo privileges. Exiting the program."
fi
}

Expand Down

0 comments on commit 9d5795d

Please sign in to comment.