cisagov / Malcolm

Malcolm is a powerful, easily deployable network traffic analysis tool suite for full packet capture artifacts (PCAP files), Zeek logs and Suricata alerts.
https://cisagov.github.io/Malcolm/
Other
1.91k stars 319 forks source link

Potential bug in `scripts/malcolm_kubernetes.py` #299

Closed ya0guang closed 4 months ago

ya0guang commented 6 months ago

🐛 Summary

Here is a code snippet in function pod_stats:

                cpu = 0
                mem = 0
                cpu_mem = stats_api.get_namespaced_custom_object(
                    "metrics.k8s.io", "v1beta1", namespace, "pods", pod_name
                )
                for c in cpu_mem['containers']:
                    if c['usage']['cpu'] == '0':
                        pass
                    else:
                        cpu = +int(c['usage']['cpu'][:-1])
                cpu = str(cpu) + 'n'
                cpu = _nanocore_to_millicore(cpu)
                for m in cpu_mem['containers']:
                    mem = +int(m['usage']['memory'][:-2])
                mem = str(mem) + 'Ki'
                mem = _to_gibibyte_or_mebibyte(mem)

Should cpu = +int(c['usage']['cpu'][:-1]) be cpu += int(c['usage']['cpu'][:-1])? Similarly, mem = +int(m['usage']['memory'][:-2]) may also be mem += int(m['usage']['memory'][:-2])?

To reproduce

Steps to reproduce the behavior:

  1. Do this
  2. Then this

Expected behavior

What did you expect to happen that didn't?

Any helpful log output or screenshots

Paste the results here:

Add any screenshots of the problem here.

mmguero commented 6 months ago

Thanks, we'll take a look.

mmguero commented 4 months ago

transferred to idaholab/Malcolm#467