Skip to content

Instantly share code, notes, and snippets.

@logankimmel
Created March 7, 2024 23:31
Show Gist options
  • Save logankimmel/a9a05b45bd800234e0808af33178e426 to your computer and use it in GitHub Desktop.
Save logankimmel/a9a05b45bd800234e0808af33178e426 to your computer and use it in GitHub Desktop.
Collect information for TO sizing
#!/bin/bash
# Get the number of nodes
num_nodes=$(kubectl get nodes --no-headers | wc -l)
echo "Number of nodes: $num_nodes"
# Get the number of pods
num_pods=$(kubectl get pods --all-namespaces --no-headers | wc -l)
echo "Number of pods: $num_pods"
# Get the sum of all containers in all pods
sum_containers=$(kubectl get pods --all-namespaces -o jsonpath='{.items[*].spec.containers[*]}' | wc -w)
echo "Sum of all containers in all pods: $sum_containers"
# Get the number of namespaces
num_namespaces=$(kubectl get namespaces --no-headers | wc -l)
echo "Number of namespaces: $num_namespaces"
$VCServer = 'vcenter.local'
$Username = 'administrator@vsphere.local'
$Password = 'password'
Connect-VIServer -Server $VCServer -User $Username -Password $Password
# Collect ESXi Host Information
$hosts = Get-VMHost
$totalHosts = $hosts.Count
$totalCPUs = ($hosts | Measure-Object -Property NumCpu -Sum).Sum
$totalDisks = ($hosts | Get-VMHostStorage -Refresh | Measure-Object -Property ScsiLun).Sum
$totalNICs = ($hosts | Get-VMHostNetworkAdapter | Measure-Object).Count
$totalStorageAdapters = ($hosts | Get-VMHostHba | Measure-Object).Count
# Collect VM Information
$vms = Get-VM
$totalVMs = $vms.Count
$totalVMDisks = ($vms | Get-HardDisk | Measure-Object).Count
$totalVMCPUs = ($vms | Measure-Object -Property NumCpu -Sum).Sum
$totalVMNICs = ($vms | Get-NetworkAdapter | Measure-Object).Count
# Display the information
Write-Host "Total ESXi Hosts: $totalHosts"
Write-Host "Sum CPUs/Host: $totalCPUs"
Write-Host "Sum Disks/Host: $totalDisks"
Write-Host "Sum NICs/Host: $totalNICs"
Write-Host "Sum Storage Adapters/Host: $totalStorageAdapters"
Write-Host "Total VMs: $totalVMs"
Write-Host "Sum Disks/VM: $totalVMDisks"
Write-Host "Sum CPUs/VM: $totalVMCPUs"
Write-Host "Sum NICs/VM: $totalVMNICs"
# Disconnect from the vCenter Server
Disconnect-VIServer -Server $VCServer -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment