Skip to content

Commit

Permalink
Consider only PODs with configured limits in the summary
Browse files Browse the repository at this point in the history
Otherwise the calculated overall percentage doesn't make any sense
if we would take usages into account without a set limit.
  • Loading branch information
eht16 committed Apr 15, 2020
1 parent 53032e7 commit f56a795
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ Example:
[15:09:58] enrico@host (0): ~% kubecargoload.py --all-namespaces
Namespace Name Requests Limits Usage %
----------------------------------------------------------------------------------------------------------
default kube-web-view-7c67ddb647-pvjvs 100.0 MB 100.0 MB 29.0 MB 29.00 %
jitsi jitsi-57d5888c88-vzrzl 0.0 B 0.0 B 131.0 MB 0.00 %
kube-system coredns-66bff467f8-qn4pq 70.0 MB 170.0 MB 16.0 MB 9.41 %
kube-system coredns-66bff467f8-znpxv 70.0 MB 170.0 MB 13.0 MB 7.65 %
kube-system etcd-minikube 0.0 B 0.0 B 43.0 MB 0.00 %
kube-system kindnet-ptgnz 50.0 MB 50.0 MB 14.0 MB 28.00 %
kube-system kube-apiserver-minikube 0.0 B 0.0 B 275.0 MB 0.00 %
kube-system kube-controller-manager-minikube 0.0 B 0.0 B 46.0 MB 0.00 %
kube-system kube-proxy-s7bl8 0.0 B 0.0 B 20.0 MB 0.00 %
kube-system kube-scheduler-minikube 0.0 B 0.0 B 20.0 MB 0.00 %
kube-system metrics-server-7bc6d75975-d6sgr 0.0 B 0.0 B 12.0 MB 0.00 %
kube-system nginx-ingress-controller-6d57c87cb9-qpwh6 0.0 B 0.0 B 67.0 MB 0.00 %
kube-system storage-provisioner 0.0 B 0.0 B 21.0 MB 0.00 %
default kube-web-view-7c67ddb647-pvjvs 100.0 Mi 100.0 Mi 29.0 Mi 29.00 %
jitsi jitsi-57d5888c88-vzrzl 0.0 B 0.0 B 137.0 Mi 0.00 %
kube-system coredns-66bff467f8-qn4pq 70.0 Mi 170.0 Mi 13.0 Mi 7.65 %
kube-system coredns-66bff467f8-znpxv 70.0 Mi 170.0 Mi 11.0 Mi 6.47 %
kube-system etcd-minikube 0.0 B 0.0 B 58.0 Mi 0.00 %
kube-system kindnet-ptgnz 50.0 Mi 50.0 Mi 13.0 Mi 26.00 %
kube-system kube-apiserver-minikube 0.0 B 0.0 B 257.0 Mi 0.00 %
kube-system kube-controller-manager-minikube 0.0 B 0.0 B 50.0 Mi 0.00 %
kube-system kube-proxy-s7bl8 0.0 B 0.0 B 16.0 Mi 0.00 %
kube-system kube-scheduler-minikube 0.0 B 0.0 B 19.0 Mi 0.00 %
kube-system metrics-server-7bc6d75975-d6sgr 0.0 B 0.0 B 13.0 Mi 0.00 %
kube-system nginx-ingress-controller-6d57c87cb9-tgwwm 0.0 B 0.0 B 0.0 B 0.00 %
kube-system storage-provisioner 0.0 B 0.0 B 15.0 Mi 0.00 %
----------------------------------------------------------------------------------------------------------
Summary 290.0 MB 490.0 MB 707.0 MB 144.29 %
Summary (PODs without configured limits ignored) 290.0 Mi 490.0 Mi 66.0 Mi 13.47 %


Setup
Expand Down
9 changes: 5 additions & 4 deletions kubecargoload.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def print(self):

def _determine_maximum_column_widths(self):
max_namespace = 0
max_name = 0
max_name = 40
for pod in self._overview.values():
max_namespace = max(max_namespace, len(pod.namespace))
max_name = max(max_name, len(pod.name))
Expand Down Expand Up @@ -277,8 +277,9 @@ def _print_pod_data(self):
pods_sorted = sorted(self._overview.values(), key=self._get_sort_key_for_pod)
for self._pod in pods_sorted:
self._sums['memory_requests'] += self._pod.memory_requests
self._sums['memory_limits'] += self._pod.memory_limits
self._sums['memory_usage'] += self._pod.memory_usage
if self._pod.memory_limits: # consider usage for summary only if limit is set
self._sums['memory_limits'] += self._pod.memory_limits
self._sums['memory_usage'] += self._pod.memory_usage

print(
self._format_pattern.format(
Expand Down Expand Up @@ -340,7 +341,7 @@ def _get_memory_usage_ratio(self, maximum=None, use=None):
def _print_summary(self):
print(self._format_pattern.format(
'Summary',
'',
'(PODs without configured limits ignored)',
self._humanize_bytes(self._sums['memory_requests']),
self._humanize_bytes(self._sums['memory_limits']),
self._humanize_bytes(self._sums['memory_usage']),
Expand Down

0 comments on commit f56a795

Please sign in to comment.