Blob Blame History Raw
From 5a9458d318302c1caef862a868745fc8bdf5c741 Mon Sep 17 00:00:00 2001
From: Pavel Moravec <pmoravec@redhat.com>
Date: Mon, 4 Oct 2021 15:52:36 +0200
Subject: [PATCH] [foreman] Collect puma status and stats

Collect foreman-puma-status and 'pumactl [gc-|]stats', optionally using
SCL (if detected).

Resolves: #2712

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
---
 sos/report/plugins/foreman.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/sos/report/plugins/foreman.py b/sos/report/plugins/foreman.py
index 4539f12b..351794f4 100644
--- a/sos/report/plugins/foreman.py
+++ b/sos/report/plugins/foreman.py
@@ -13,6 +13,7 @@ from sos.report.plugins import (Plugin,
                                 UbuntuPlugin)
 from pipes import quote
 from re import match
+from sos.utilities import is_executable
 
 
 class Foreman(Plugin):
@@ -26,7 +27,9 @@ class Foreman(Plugin):
     option_list = [
         ('months', 'number of months for dynflow output', 'fast', 1),
         ('proxyfeatures', 'collect features of smart proxies', 'slow', False),
+        ('puma-gc', 'collect Puma GC stats', 'fast', False),
     ]
+    pumactl = 'pumactl %s -S /usr/share/foreman/tmp/puma.state'
 
     def setup(self):
         # for external DB, search in /etc/foreman/database.yml for:
@@ -134,6 +138,17 @@ class Foreman(Plugin):
                                 suggest_filename='dynflow_sidekiq_status')
         self.add_journal(units="dynflow-sidekiq@*")
 
+        # Puma stats & status, i.e. foreman-puma-stats, then
+        # pumactl stats -S /usr/share/foreman/tmp/puma.state
+        # and optionally also gc-stats
+        # if on RHEL with Software Collections, wrap the commands accordingly
+        if self.get_option('puma-gc'):
+            self.add_cmd_output(self.pumactl % 'gc-stats',
+                                suggest_filename='pumactl_gc-stats')
+        self.add_cmd_output(self.pumactl % 'stats',
+                            suggest_filename='pumactl_stats')
+        self.add_cmd_output('/usr/sbin/foreman-puma-status')
+
         # collect tables sizes, ordered
         _cmd = self.build_query_cmd(
             "SELECT table_name, pg_size_pretty(total_bytes) AS total, "
@@ -297,6 +312,10 @@ class RedHatForeman(Foreman, RedHatPlugin):
         self.add_file_tags({
             '/usr/share/foreman/.ssh/ssh_config': 'ssh_foreman_config',
         })
+        # if we are on RHEL7 with scl, wrap some Puma commands by
+        # scl enable tfm 'command'
+        if self.policy.dist_version() == 7 and is_executable('scl'):
+            self.pumactl = "scl enable tfm '%s'" % self.pumactl
 
         super(RedHatForeman, self).setup()
 
-- 
2.31.1