Add debug output for libvirt ping checks

This patch adds some extra debug options to the ping check. It writes
the STDOUT of ping subprocess to a temporary file which can be logged in
the debug log level.

Change-Id: Ife9a1d409a8326fb9ff07b1b04508cd11f899d10
This commit is contained in:
KeithMnemonic 2020-04-29 10:51:11 -04:00 committed by Keith Berger
parent 5148493fb7
commit 674cefe1e7

View File

@ -24,6 +24,7 @@ import os
import re import re
import stat import stat
import subprocess import subprocess
import tempfile
import time import time
from calendar import timegm from calendar import timegm
@ -713,21 +714,31 @@ class LibvirtCheck(AgentCheck):
dims_operations_ip = dims_operations.copy() dims_operations_ip = dims_operations.copy()
dims_customer_ip['ip'] = net['ip'] dims_customer_ip['ip'] = net['ip']
dims_operations_ip['ip'] = net['ip'] dims_operations_ip['ip'] = net['ip']
with open(os.devnull, "w") as fnull: res = 0
with tempfile.TemporaryFile() as tfile:
try: try:
self.log.debug("Running ping test: {0}".format(' '.join(ping_cmd))) self.log.debug("Running ping test: {0}".format(' '.join(ping_cmd)))
res = subprocess.call(ping_cmd, subprocess.check_call(ping_cmd,
stdout=fnull, stdout=tfile,
stderr=fnull) stderr=subprocess.STDOUT)
tenant_id = instance_cache.get(inst_name)['tenant_id'] tfile.seek(0)
hostname = instance_cache.get(inst_name)['hostname'] self.log.debug("Output from running '{0}' is: '{1}'".format
return (res, dims_customer_ip, dims_operations_ip, tenant_id, (' '.join(ping_cmd), tfile.read()))
hostname) except subprocess.CalledProcessError as ce:
tfile.seek(0)
res = ce.returncode
self.log.debug("Exception from '{0}' command is: '{1}'".format
(' '.join(ping_cmd), tfile.read()))
except Exception as e: except Exception as e:
self.log.exception("OS error running '{0}' failed".format(ping_cmd), e) self.log.exception("OS error running '{0}' failed".format(ping_cmd), e)
raise e raise e
tenant_id = instance_cache.get(inst_name)['tenant_id']
hostname = instance_cache.get(inst_name)['hostname']
self.log.debug("Metric value of ping check {0} is: {1}".format
(' '.join(ping_cmd), res))
return (res, dims_customer_ip, dims_operations_ip, tenant_id, hostname)
def _check_ping_results(self, ping_results): def _check_ping_results(self, ping_results):
"""Iterate through ping results and create measurements""" """Iterate through ping results and create measurements"""
for result in ping_results: for result in ping_results: