6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/kdep/cluster_health.rb', line 6
def check
begin
output = Kdep::Kubectl.run("top", "nodes", "--no-headers")
rescue Kdep::Kubectl::Error
return ["Cluster health metrics unavailable (metrics-server may not be installed)"]
end
warnings = []
output.each_line do |line|
parts = line.strip.split(/\s+/)
next if parts.length < 5
name = parts[0]
cpu_percent = parts[2].sub("%", "").to_i
mem_percent = parts[4].sub("%", "").to_i
if cpu_percent > CPU_WARN
warnings << "Node #{name}: CPU at #{cpu_percent}% (threshold: #{CPU_WARN}%)"
end
if mem_percent > MEMORY_WARN
warnings << "Node #{name}: Memory at #{mem_percent}% (threshold: #{MEMORY_WARN}%)"
end
end
warnings
end
|