Skip to content

Commit fcd8eb0

Browse files
authored
B #6765: Improve QEMU Guest Agent monitoring. (#3328)
* Improve qemu-ga monitoring resilience * Add more commands to config files
1 parent 8ff4b90 commit fcd8eb0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/im_mad/remotes/kvm-probes.d/guestagent.conf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@
88
# The value will be run as a command executed with virsh qemu-agent-command
99
# The $vm_id substring, if existing, will be replaced by the VM ID when the monitoring probes
1010
# are looping on each of the VMs on the host. Each command will be run once per VM.
11+
# The expected response for each command is a JSON string with a "return" key.
12+
# The contents of it will appear on the MONITORING message from the poll probe.
1113
:commands:
12-
:vm_qemu_ping: "one-$vm_id '{\"execute\":\"guest-ping\"}' --timeout 5"
14+
:vm_qemu_ping: one-$vm_id '{"execute":"guest-ping"}' --timeout 5
15+
# :guest_info: one-$vm_id '{"execute":"guest-info"}' --timeout 5
16+
# # The first non-loopback address
17+
# :vm_ip_address: >
18+
# one-$vm_id '{"execute":"guest-network-get-interfaces"}' --timeout 5 |
19+
# jq '{"return": [.return[] | select(."ip-addresses") | ."ip-addresses"[] | select(."ip-address-type"=="ipv4" and (."ip-address"|startswith("127.")|not))."ip-address"][0]}'
20+
# # Array of all IP addresses
21+
# :vm_ip_address_list: >
22+
# one-$vm_id '{"execute":"guest-network-get-interfaces"}' --timeout 5 |
23+
# jq '{"return" : [ .return[] | select(."ip-addresses") | ."ip-addresses"[]."ip-address" ]}'

src/im_mad/remotes/lib/kvm.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,16 @@ def ga_stats
350350
if s.exitstatus != 0
351351
@vm[ga_info] = e.chomp
352352
else
353-
@vm[ga_info] = JSON.parse(text)['return']
353+
begin
354+
info = JSON.parse(text)['return']
355+
356+
info = info.join(', ') if info.is_a?(Array)
357+
info = info.to_s.gsub(/["\[\]]/) { |match| "\\#{match}" } if info.is_a?(Hash)
358+
359+
@vm[ga_info] = info
360+
rescue JSON::ParserError => e
361+
@vm[ga_info] = "Failed to parse command output: #{e}"
362+
end
354363
end
355364
end
356365
else

0 commit comments

Comments
 (0)