measure memory as percentage
This commit is contained in:
parent
7bbf6c1dc4
commit
4467308d35
1 changed files with 21 additions and 1 deletions
22
check_pve.rb
22
check_pve.rb
|
@ -355,6 +355,21 @@ class CheckPve
|
||||||
check_thresholds(data: value)
|
check_thresholds(data: value)
|
||||||
end
|
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
|
# helper for unit values
|
||||||
def node_helper_to_units(path: 'status', type:, value: 'used', output_msg:, unit: 'gb', perf_label: 'Usage')
|
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}")
|
http_connect(path: "api2/json/nodes/#{@options[:node]}/#{path}")
|
||||||
|
@ -395,7 +410,12 @@ class CheckPve
|
||||||
### node: memory
|
### node: memory
|
||||||
def mem
|
def mem
|
||||||
return unless @options[:mode] == 'memory'
|
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
|
end
|
||||||
|
|
||||||
### node: ksm
|
### node: ksm
|
||||||
|
|
Loading…
Reference in a new issue