measure memory as percentage

This commit is contained in:
bain 2023-12-01 21:43:08 +01:00
parent 7bbf6c1dc4
commit 4467308d35
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B

View file

@ -355,6 +355,21 @@ class CheckPve
check_thresholds(data: value)
end
# helper for nested percentage values
def node_helper_to_nested_pct(path: 'status', key:, value:, output_msg:, perf_label: 'Usage', **args)
http_connect(path: "api2/json/nodes/#{@options[:node]}/#{path}")
data = JSON.parse(@response.body)['data'][key]
# calc used data
value = if args.empty?
format_float(float_data: data[value])
else
format_float(float_data: data[value].to_f / data[args[:value_to_compare]])
end
build_output(msg: "#{output_msg}: #{value}%")
build_perfdata(perfdata: "#{perf_label}=#{value}%")
check_thresholds(data: value)
end
# helper for unit values
def node_helper_to_units(path: 'status', type:, value: 'used', output_msg:, unit: 'gb', perf_label: 'Usage')
http_connect(path: "api2/json/nodes/#{@options[:node]}/#{path}")
@ -395,7 +410,12 @@ class CheckPve
### node: memory
def mem
return unless @options[:mode] == 'memory'
node_helper_to_units(type: 'memory', output_msg: 'Memory Usage')
node_helper_to_nested_pct(
key: 'memory',
value: 'used',
value_to_compare: 'total',
output_msg: 'Memory usage'
)
end
### node: ksm