robscott / kube-capacity

A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
Apache License 2.0
2.09k stars 114 forks source link

Json output shows CPU utilization with unknown unit #56

Closed leshibily closed 2 years ago

leshibily commented 2 years ago

Hello folks,

I get different outputs in JSON and non-JSON outputs for the following command:

kube-capacity --util --sort cpu.util --output json

JSON output:

{ "nodes": [ { "name": "gke-snapblocs-dpstudi-default-f5be526-2c7e96ef-t6t4", "cpu": { "requests": "2062m", "requestsPercent": "52%", "limits": "5544m", "limitsPercent": "141%", "utilization": "1013446562n", "utilizationPercent": "25%" }, "memory": { "requests": "5821Mi", "requestsPercent": "43%", "limits": "6151Mi", "limitsPercent": "46%", "utilization": "3707128Ki", "utilizationPercent": "27%" } }, { "name": "gke-snapblocs-dpstudi-default-f5be526-e4e0068f-6zts", "cpu": { "requests": "1803m", "requestsPercent": "45%", "limits": "3100m", "limitsPercent": "79%", "utilization": "787564923n", "utilizationPercent": "20%" }, "memory": { "requests": "2768Mi", "requestsPercent": "20%", "limits": "3438Mi", "limitsPercent": "25%", "utilization": "2532912Ki", "utilizationPercent": "18%" } }, { "name": "gke-snapblocs-dpstudi-default-f5be526-e4e0068f-8xjc", "cpu": { "requests": "2083m", "requestsPercent": "53%", "limits": "3410m", "limitsPercent": "86%", "utilization": "626234143n", "utilizationPercent": "15%" }, "memory": { "requests": "3802Mi", "requestsPercent": "28%", "limits": "3458Mi", "limitsPercent": "26%", "utilization": "2229032Ki", "utilizationPercent": "16%" } }, { "name": "gke-snapblocs-dpstudi-default-f5be526-2c7e96ef-8w0p", "cpu": { "requests": "2113m", "requestsPercent": "53%", "limits": "4600m", "limitsPercent": "117%", "utilization": "597228442n", "utilizationPercent": "15%" }, "memory": { "requests": "4172Mi", "requestsPercent": "31%", "limits": "4252Mi", "limitsPercent": "31%", "utilization": "2956028Ki", "utilizationPercent": "21%" } }, { "name": "gke-snapblocs-dpstudi-default-f5be526-2c7e96ef-292x", "cpu": { "requests": "1813m", "requestsPercent": "46%", "limits": "3400m", "limitsPercent": "86%", "utilization": "538324970n", "utilizationPercent": "13%" }, "memory": { "requests": "4696Mi", "requestsPercent": "35%", "limits": "3228Mi", "limitsPercent": "24%", "utilization": "2081224Ki", "utilizationPercent": "15%" } }, { "name": "gke-snapblocs-dpstudi-default-f5be526-e4e0068f-p2m0", "cpu": { "requests": "1713m", "requestsPercent": "43%", "limits": "3200m", "limitsPercent": "81%", "utilization": "528323068n", "utilizationPercent": "13%" }, "memory": { "requests": "3762Mi", "requestsPercent": "28%", "limits": "3228Mi", "limitsPercent": "24%", "utilization": "2317608Ki", "utilizationPercent": "17%" } } ], "clusterTotals": { "cpu": { "requests": "11587m", "requestsPercent": "49%", "limits": "23254m", "limitsPercent": "98%", "utilization": "4091122108n", "utilizationPercent": "17%" }, "memory": { "requests": "25021Mi", "requestsPercent": "31%", "limits": "23755Mi", "limitsPercent": "29%", "utilization": "15823932Ki", "utilizationPercent": "19%" } } }

Non JSON output:

Screenshot 2021-10-05 at 5 58 33 PM

As you can notice for the node gke-snapblocs-dpstudi-default-f5be526-2c7e96ef-t6t4 CPU utilization and Memory utilization in JSON are having n and Ki units which are not matching with Non JSON output which is m and Mi.

Version: kubernetes: 1.20 kube-capacity: 0.6.1

robscott commented 2 years ago

Thanks for the bug report! It looks like the table (default) printer got updated to properly print out metrics, but the list printer (json and yaml) did not. I'm pretty overloaded right now, so not sure how soon I'll be able to get a fix in, but if anyone has extra time, PRs are always welcome.

robscott commented 2 years ago

This was fixed by #62, will get a new release out soon.