aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-12-16 14:23:06 -0500
committerJake Hunsaker <jhunsake@redhat.com>2023-01-03 09:22:33 -0500
commit9c60afed25c6cd8ecbd25c52a403376262a121d2 (patch)
tree85f97fa3f7c18ecde1abb926958162a5fc7af038
parent1ec29fb3a4dc42d5ccdd3f3b7340ec2b38bc4965 (diff)
downloadsos-9c60afed25c6cd8ecbd25c52a403376262a121d2.tar.gz
[ceph_mgr] Update plugin for newer versions of Ceph
Updates the plugin to account for newer versions of Ceph, similar to the previous few commits focusing on the ceph plugins. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/report/plugins/ceph_mgr.py118
1 files changed, 73 insertions, 45 deletions
diff --git a/sos/report/plugins/ceph_mgr.py b/sos/report/plugins/ceph_mgr.py
index 2aaf1a9d..a7391f96 100644
--- a/sos/report/plugins/ceph_mgr.py
+++ b/sos/report/plugins/ceph_mgr.py
@@ -6,28 +6,67 @@
#
# See the LICENSE file in the source distribution for further information.
+import os
+
from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin
class CephMGR(Plugin, RedHatPlugin, UbuntuPlugin):
+ """
+ This plugin is for capturing information from Ceph mgr nodes. While the
+ majority of this plugin should be version-agnostic, several collections are
+ dependent upon the version of Ceph installed. Versions that correlate to
+ RHCS 4 or RHCS 5 are explicitly handled for differences such as those
+ pertaining to log locations on the host filesystem.
+
+ Note that while this plugin will activate based on the presence of Ceph
+ containers, commands are run directly on the host as those containers are
+ often not configured to successfully run the `ceph` commands collected by
+ this plugin. These commands are majorily `ceph daemon` commands that will
+ reference discovered admin sockets under /var/run/ceph.
+ """
short_desc = 'CEPH mgr'
plugin_name = 'ceph_mgr'
profiles = ('storage', 'virt', 'container')
- files = ('/var/lib/ceph/mgr/',)
- containers = ('ceph-(.*)?mgr.*',)
+ files = ('/var/lib/ceph/mgr/', '/var/lib/ceph/*/mgr*')
+ containers = ('ceph-(.*-)?mgr.*',)
def setup(self):
+
+ self.ceph_version = self.get_ceph_version()
+
+ logdir = '/var/log/ceph'
+ libdir = '/var/lib/ceph'
+ rundir = '/run/ceph'
+
+ if self.ceph_version >= 16:
+ logdir += '/*'
+ libdir += '/*'
+ rundir += '/*'
+
self.add_file_tags({
- '/var/log/ceph/ceph-mgr.*.log': 'ceph_mgr_log',
+ f'{logdir}/ceph-mgr.*.log': 'ceph_mgr_log',
})
+ self.add_forbidden_path([
+ "/etc/ceph/*keyring*",
+ f"{libdir}/*keyring*",
+ f"{libdir}/**/*keyring*",
+ f"{libdir}/osd*",
+ f"{libdir}/mon*",
+ # Excludes temporary ceph-osd mount location like
+ # /var/lib/ceph/tmp/mnt.XXXX from sos collection.
+ f"{libdir}/tmp/*mnt*",
+ "/etc/ceph/*bindpass*",
+ ])
+
self.add_copy_spec([
- "/var/log/ceph/ceph-mgr*.log",
- "/var/lib/ceph/mgr/",
- "/var/lib/ceph/bootstrap-mgr/",
- "/run/ceph/ceph-mgr*",
+ f"{logdir}/ceph-mgr*.log",
+ f"{libdir}/mgr*",
+ f"{libdir}/bootstrap-mgr/",
+ f"{rundir}/ceph-mgr*",
])
# more commands to be added later
@@ -42,7 +81,7 @@ class CephMGR(Plugin, RedHatPlugin, UbuntuPlugin):
"ceph log last cephadm"
])
- ceph_cmds = [
+ cmds = [
"config diff",
"config show",
"dump_cache",
@@ -61,44 +100,33 @@ class CephMGR(Plugin, RedHatPlugin, UbuntuPlugin):
"version"
]
- self.add_forbidden_path([
- "/etc/ceph/*keyring*",
- "/var/lib/ceph/*keyring*",
- "/var/lib/ceph/*/*keyring*",
- "/var/lib/ceph/*/*/*keyring*",
- "/var/lib/ceph/osd",
- "/var/lib/ceph/mon",
- # Excludes temporary ceph-osd mount location like
- # /var/lib/ceph/tmp/mnt.XXXX from sos collection.
- "/var/lib/ceph/tmp/*mnt*",
- "/etc/ceph/*bindpass*",
- ])
+ self.add_cmd_output([
+ f"ceph daemon {m} {cmd}" for m in self.get_socks() for cmd in cmds]
+ )
- mgr_ids = []
- # Get the ceph user processes
- out = self.exec_cmd('ps -u ceph -o args')
-
- if out['status'] == 0:
- # Extract the OSD ids from valid output lines
- for procs in out['output'].splitlines():
- proc = procs.split()
- # Locate the '--id' value
- if proc and proc[0].endswith("ceph-mgr"):
- try:
- id_index = proc.index("--id")
- mgr_ids.append("mgr.%s" % proc[id_index+1])
- except (IndexError, ValueError):
- self.log_warn("could not find ceph-mgr id: %s", procs)
-
- # If containerized, run commands in containers
- try:
- cname = self.get_all_containers_by_regex("ceph-mgr*")[0][1]
- except Exception:
- cname = None
+ def get_ceph_version(self):
+ ver = self.exec_cmd('ceph --version')
+ if ver['status'] == 0:
+ try:
+ _ver = ver['output'].split()[2]
+ return int(_ver.split('.')[0])
+ except Exception as err:
+ self._log_debug(f"Could not determine ceph version: {err}")
+ self._log_error(
+ 'Failed to find ceph version, command collection will be limited'
+ )
+ return 0
- self.add_cmd_output([
- "ceph daemon %s %s"
- % (mgrid, cmd) for mgrid in mgr_ids for cmd in ceph_cmds
- ], container=cname)
+ def get_socks(self):
+ """
+ Find any available admin sockets under /var/run/ceph (or subdirs for
+ later versions of Ceph) which can be used for ceph daemon commands
+ """
+ ceph_sockets = []
+ for rdir, dirs, files in os.walk('/var/run/ceph/'):
+ for file in files:
+ if file.startswith('ceph-mgr') and file.endswith('.asok'):
+ ceph_sockets.append(self.path_join(rdir, file))
+ return ceph_sockets
# vim: set et ts=4 sw=4 :