mirror of
https://ak-git.vectorsigma.ru/terghalin/metalcheck.git
synced 2026-03-15 23:03:30 +09:00
fix(k8s): conversion fix
This commit is contained in:
@@ -9,11 +9,18 @@ router = APIRouter()
|
||||
|
||||
# Helper functions for conversions
|
||||
def convert_cpu_to_millicores(cpu):
|
||||
if "n" in cpu:
|
||||
"""
|
||||
Convert CPU usage to millicores (m).
|
||||
Handles units: n (nano), u (micro), m (milli), or none (cores).
|
||||
"""
|
||||
if "n" in cpu: # Convert nanocores to millicores
|
||||
return int(cpu.replace("n", "")) / 1e6
|
||||
elif "m" in cpu:
|
||||
elif "u" in cpu: # Convert microcores to millicores
|
||||
return int(cpu.replace("u", "")) / 1e3
|
||||
elif "m" in cpu: # Already in millicores
|
||||
return int(cpu.replace("m", ""))
|
||||
return float(cpu) * 1000
|
||||
return float(cpu) * 1000 # Convert cores to millicores
|
||||
|
||||
|
||||
def convert_memory_to_mib(memory):
|
||||
if "Ki" in memory:
|
||||
|
||||
@@ -51,11 +51,18 @@ def fetch_k8s_data_with_usage():
|
||||
|
||||
|
||||
def convert_cpu_to_millicores(cpu):
|
||||
if "n" in cpu:
|
||||
"""
|
||||
Convert CPU usage to millicores (m).
|
||||
Handles units: n (nano), u (micro), m (milli), or none (cores).
|
||||
"""
|
||||
if "n" in cpu: # Convert nanocores to millicores
|
||||
return int(cpu.replace("n", "")) / 1e6
|
||||
elif "m" in cpu:
|
||||
elif "u" in cpu: # Convert microcores to millicores
|
||||
return int(cpu.replace("u", "")) / 1e3
|
||||
elif "m" in cpu: # Already in millicores
|
||||
return int(cpu.replace("m", ""))
|
||||
return float(cpu) * 1000 # Use float to ensure compatibility
|
||||
return float(cpu) * 1000 # Convert cores to millicores
|
||||
|
||||
|
||||
def convert_memory_to_mib(memory):
|
||||
if "Ki" in memory:
|
||||
|
||||
Reference in New Issue
Block a user