gcloud container clusters get-credentials observability-production --region europe-west3
Perl script to calculate allocated CPUs for particular namespace
#/usr/bin/perl
$gcloud_auth=`gcloud container clusters get-credentials observability-production --region europe-west3`;
$context = `kubectl config current-context`;
print "Kubernetes Context: $context";
$cpu_line = `kubectl get po -n loki -o jsonpath="{.items[*].spec.containers[*].resources['limits.cpu']}"`;
print "CPU limits: $cpu_line\n";
my @cpu = split(' ', $cpu_line);
$total_cpu_cores = 0;
foreach (@cpu) {
$unit = substr($_, -1, 1);
if ($unit eq "m") {
$cpu = substr($_, 0, - 1);
$cpu = $cpu / 1000;
} else {
$cpu = $_;
}
$total_cpu_cores += $cpu;
}
print "Total CPU cores: $total_cpu_cores\n";