Skip to content

Commit

Permalink
Added deployment time tracking, memory, and disk space usage monitori…
Browse files Browse the repository at this point in the history
…ng in mojafos bash scripts
  • Loading branch information
Abhinavcode13 committed May 23, 2024
1 parent 718bdd6 commit 07ca1e6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 8 deletions.
37 changes: 31 additions & 6 deletions src/mojafos/commandline/commandline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ function getoptions {
}

# this function is called when Ctrl-C is sent
function cleanUp ()
{
function cleanUp () {
# perform cleanup here
echo -e "${RED}Performing graceful clean up${RESET}"

Expand All @@ -104,6 +103,30 @@ function trapCtrlc {
# when signal 2 (SIGINT) is received
trap "trapCtrlc" 2

function getMemoryUsage() {
kubectl top pod --all-namespaces | grep -E 'mifos|mojaloop|phee'
}

function getDiskUsage() {
du -sh /var/lib/kubelet/pods
}

function measureTime() {
local start_time=$(date +%s)
$@
local end_time=$(date +%s)
local elapsed=$(( end_time - start_time ))
echo "Time taken: $(($elapsed / 60)) minutes and $(($elapsed % 60)) seconds."
}

function monitorResources() {
echo "Memory usage by components:"
getMemoryUsage

echo "Disk usage:"
getDiskUsage
}

###########################################################################
# MAIN
###########################################################################
Expand All @@ -116,11 +139,13 @@ function main {
echo -e "The deployment made by this script is meant for demo purposes and not for production"
echo -e "===================================================================================="
echo -e "${RESET}"
envSetupMain "$mode" "k3s" "1.26" "$environment"
deployApps "$fineract_instansces" "$apps"
measureTime envSetupMain "$mode" "k3s" "1.26" "$environment"
measureTime deployApps "$fineract_instansces" "$apps"
monitorResources
elif [ $mode == "cleanup" ]; then
logWithVerboseCheck $debug info "Cleaning up all traces of Mojafos"
envSetupMain "$mode" "k3s" "1.26" "$environment"
measureTime envSetupMain "$mode" "k3s" "1.26" "$environment"
monitorResources
else
showUsage
fi
Expand All @@ -129,4 +154,4 @@ function main {
###########################################################################
# CALL TO MAIN
###########################################################################
main "$@"
main "$@"
67 changes: 65 additions & 2 deletions src/mojafos/configurationManager/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ FIN_NAMESPACE="fineract"
FIN_RELEASE_NAME="fineract"
FIN_VALUES_FILE="$BASE_DIR/src/mojafos/deployer/fin_values.yaml"

# Timers
START_TIME=$(date +%s)

########################################################################
# FUNCTIONS FOR CONFIGURATION MANAGEMENT
Expand Down Expand Up @@ -129,7 +131,7 @@ function configureMojaloop() {
old_value=$(echo "$json_object" | jq -r '.old_value')
new_value=$(echo "$json_object" | jq -r ".new_value")

# Call the function with the extracted attributes
# Call the function with the extracted attributes
replaceValuesInFile "$file_name" "$old_value" "$new_value"
done

Expand Down Expand Up @@ -193,4 +195,65 @@ function configurePH() {

function configureFineract(){
echo -e "${BLUE}Configuring fineract ${RESET}"
}
}

########################################################################
# FUNCTION TO MONITOR DEPLOYMENT
########################################################################
function monitorDeployment() {
echo -e "${BLUE}Monitoring Deployment ${RESET}"

echo -e "Waiting for all pods to be in 'Running' state..."
start_time=$(date +%s)
while true; do
not_running_pods=$(kubectl get pods --all-namespaces --field-selector=status.phase!=Running | wc -l)
if [ "$not_running_pods" -eq 0 ]; then
echo "All pods are in 'Running' state."
break
fi
sleep 5
done
end_time=$(date +%s)
total_time=$((end_time - start_time))
echo -e "${GREEN}All pods are in 'Running' state. Total deploy time: ${total_time}s${RESET}"
}

########################################################################
# FUNCTION TO CHECK MEMORY USAGE
########################################################################
function checkMemoryUsage() {
echo -e "${BLUE}Checking Memory Usage ${RESET}"
kubectl top pods --all-namespaces | awk '
NR==1 {print $0}
/mojaloop|paymenthub|fineract/ {print $0}'
}

########################################################################
# FUNCTION TO CHECK DISK SPACE USAGE
########################################################################
function checkDiskSpaceUsage() {
echo -e "${BLUE}Checking Disk Space Usage ${RESET}"
df -h | awk 'NR==1 || /\/$/ {print $0}'
}

########################################################################
# MAIN EXECUTION
########################################################################

# Run configuration functions
configureMojaloop
configurePH "$PHREPO_DIR"
configureFineract

# Monitor deployment
monitorDeployment

# Check memory and disk space usage
checkMemoryUsage
checkDiskSpaceUsage

END_TIME=$(date +%s)
TOTAL_DEPLOY_TIME=$((END_TIME - START_TIME))
echo -e "${GREEN}Total deployment time: ${TOTAL_DEPLOY_TIME}s${RESET}"

echo -e "${GREEN}Deployment and configuration complete.${RESET}"

0 comments on commit 07ca1e6

Please sign in to comment.