Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding telemetry for logrotate #2045

Merged
merged 5 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions azurelinuxagent/common/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def get_distro():
osinfo[0] = osinfo[0].strip('"').strip(' ').lower()
return osinfo

COMMAND_ABSENT = "Absent"
COMMAND_FAILED = "Failed"


def get_lis_version():
"""
Expand All @@ -169,12 +172,23 @@ def get_lis_version():
# If the system doesn't have LIS drivers, 'modinfo' will
# return nothing on stdout, which will cause 'run_command'
# to return an empty string.
return "Absent"
return COMMAND_ABSENT
except Exception:
# Ignore almost every possible exception because this is in a
# critical code path. Unfortunately the logger isn't already
# imported in this module or we'd log this too.
return "Failed"
return COMMAND_FAILED

def has_logrotate():
try:
logrotate_version = shellutil.run_command(["logrotate", "--version"]).split("\n")[0]
return logrotate_version
except shellutil.CommandError:
# A non-zero return code means that logrotate isn't present on
# the system; --version shouldn't fail otherwise.
return COMMAND_ABSENT
except Exception:
return COMMAND_FAILED


AGENT_NAME = "WALinuxAgent"
Expand Down
23 changes: 17 additions & 6 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
from azurelinuxagent.common.protocol.util import get_protocol_util
from azurelinuxagent.common.protocol.hostplugin import HostPluginProtocol
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, AGENT_DIR_PATTERN, CURRENT_AGENT, \
CURRENT_VERSION, DISTRO_NAME, DISTRO_VERSION, is_current_agent_installed, get_lis_version, PY_VERSION_MAJOR, \
PY_VERSION_MINOR, PY_VERSION_MICRO
from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, AGENT_DIR_PATTERN, CURRENT_AGENT,\
CURRENT_VERSION, DISTRO_NAME, DISTRO_VERSION, is_current_agent_installed, get_lis_version, \
has_logrotate, PY_VERSION_MAJOR, PY_VERSION_MINOR, PY_VERSION_MICRO
from azurelinuxagent.ga.collect_logs import get_collect_logs_handler, is_log_collection_allowed
from azurelinuxagent.ga.env import get_env_handler
from azurelinuxagent.ga.extension_telemetry import get_extension_telemetry_handler
Expand Down Expand Up @@ -263,9 +263,20 @@ def run(self, debug=False): # pylint: disable=R0912,R0914
initialize_event_logger_vminfo_common_parameters(protocol)

# Log OS-specific info.
os_info_msg = u"Distro: {0}-{1}; OSUtil: {2}; AgentService: {3}; Python: {4}.{5}.{6}; systemd: {7}; LISDrivers: {8}".format(
DISTRO_NAME, DISTRO_VERSION, type(self.osutil).__name__, self.osutil.service_name, PY_VERSION_MAJOR,
PY_VERSION_MINOR, PY_VERSION_MICRO, CGroupsApi.is_systemd(), get_lis_version())
os_info_msg = u"Distro: {dist_name}-{dist_ver}; "\
u"OSUtil: {util_name}; AgentService: {service_name}; "\
u"Python: {py_major}.{py_minor}.{py_micro}; "\
u"systemd: {systemd}; "\
u"LISDrivers: {lis_ver}; "\
u"logrotate: {has_logrotate};".format(
dist_name=DISTRO_NAME, dist_ver=DISTRO_VERSION,
util_name=type(self.osutil).__name__,
service_name=self.osutil.service_name,
py_major=PY_VERSION_MAJOR, py_minor=PY_VERSION_MINOR,
py_micro=PY_VERSION_MICRO, systemd=CGroupsApi.is_systemd(),
lis_ver=get_lis_version(), has_logrotate=has_logrotate()
)

logger.info(os_info_msg)
add_event(AGENT_NAME, op=WALAEventOperation.OSInfo, message=os_info_msg)

Expand Down