Skip to content

Commit

Permalink
add_gcp_sql_instances
Browse files Browse the repository at this point in the history
  • Loading branch information
idank-orca committed Apr 27, 2023
1 parent 42f70a3 commit 4411191
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions azure_resource_count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ for subscription in $subscriptions; do
az sql server list --subscription $subscription --query "[].{name: name, resourceGroup: resourceGroup}" -o json> ${_temp_subscription_output} 2>> $LOG_FILE || echo "Failed to get Managed Data Stores for subscription ${subscription}"
servers=$(cat "${_temp_subscription_output}")
currentNodesCount=0
for cluster in $(echo "$servers" | jq -c '.[]'); do
server_name=$(echo $cluster | jq -r '.name')
rg_name=$(echo $cluster | jq -r '.resourceGroup')
for server in $(echo "$servers" | jq -c '.[]'); do
server_name=$(echo $server | jq -r '.name')
rg_name=$(echo $server | jq -r '.resourceGroup')
az sql db list --subscription $subscription --resource-group $rg_name --server $server_name --query "[?name!='master'] | length(@)" -o tsv > ${_temp_subscription_output} 2>> $LOG_FILE || echo "Failed to get Managed Data Stores for subscription ${subscription}"
currentDBCount=$(cat "${_temp_subscription_output}")
if [ -n "$currentDBCount" ]; then
Expand Down
22 changes: 18 additions & 4 deletions gcp_resource_count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ set -e

LOG_FILE='gcp_resource_count.log'
WORKLOAD_VM_UNITS=1
WORKLOAD_FUNCTION_UNITS=50
WORKLOAD_SERVERLESS_CONTAINER_UNITS=10
WORKLOAD_FUNCTION_UNITS=50 # (1 / 50)
WORKLOAD_SERVERLESS_CONTAINER_UNITS=10 # (1 / 10)
WORKLOAD_VM_IMAGE_UNITS=1
WORKLOAD_CONTAINER_IMAGE_UNITS=10
WORKLOAD_CONTAINER_IMAGE_UNITS=10 # (1 / 10)
WORKLOAD_CONTAINER_HOST_UNITS=1
WORKLOAD_DATABASE_UNITS=2


_tmp_files=$(mktemp)
Expand Down Expand Up @@ -59,6 +60,7 @@ total_cloud_run=0
total_container_images=0
total_vm_images=0
total_gke_nodes=0
total_dbs=0
counter=0
_temp_project_output=$(_make_temp_file)
for project in $PROJECTS; do
Expand Down Expand Up @@ -122,6 +124,13 @@ for project in $PROJECTS; do
echo "Container Hosts Count: $project_nodes_count"
fi

gcloud -q sql instances list --project "${project}" --filter='-masterInstanceName:* AND settings.activationPolicy!='NEVER' AND settings.backupConfiguration.enabled=true' --format=json > ${_temp_project_output} 2>> $LOG_FILE || echo "Failed to get Managed Data Stores for project ${project}"
project_dbs_count=$(cat "${_temp_project_output}" | jq -r '. | length')
if [ -n "$project_dbs_count" ]; then
total_dbs=$((total_dbs + project_dbs_count))
echo "Managed Data Stores Count: $project_dbs_count"
fi

#Increment counter
counter=$((counter+1))
if [ -n "$PROJECT_LEN" ]; then
Expand Down Expand Up @@ -159,7 +168,11 @@ container_host_workloads=$(( ( total_gke_nodes + WORKLOAD_CONTAINER_HOST_UNITS /
if [[ $container_host_workloads -eq 0 && $total_gke_nodes -gt 0 ]]; then
container_host_workloads=1
fi
total_workloads=$(( vm_workloads + function_workloads + container_workloads + container_image_workloads + vm_image_workloads + container_host_workloads ))
db_workloads=$(( total_dbs * WORKLOAD_DATABASE_UNITS ))
if [[ $db_workloads -eq 0 && $total_dbs -gt 0 ]]; then
db_workloads=1
fi
total_workloads=$(( vm_workloads + function_workloads + container_workloads + container_image_workloads + vm_image_workloads + container_host_workloads + db_workloads))

echo "=============="
echo "Total results:"
Expand All @@ -170,6 +183,7 @@ echo "Serverless Containers Count: $total_cloud_run (Workload Units: ${container
echo "Container Images Count: $total_container_images (Workload Units: ${container_image_workloads})"
echo "VM Images Count: $total_vm_images (Workload Units: ${vm_image_workloads})"
echo "Container Hosts Count: $total_gke_nodes (Workload Units: ${container_host_workloads})"
echo "Managed Data Stores Count: $total_dbs (Workload Units: ${db_workloads})"
echo "--------------------------------------"
echo "TOTAL Estimated Workload Units: ${total_workloads}"
echo
Expand Down

0 comments on commit 4411191

Please sign in to comment.