Blame SOURCES/sos-bz1853235-foreman_collect_stats_of_some_tables.patch

9ab0e5
From 65c81d285def5f5b7e150bfe68dc84cacbe73cbe Mon Sep 17 00:00:00 2001
9ab0e5
From: Jan Jansky <jjansky@redhat.com>
9ab0e5
Date: Thu, 25 Jun 2020 13:28:14 +0200
9ab0e5
Subject: [PATCH] [foreman] collects stats of some tables from foreman DB
9ab0e5
9ab0e5
Too many logs, audits or fact_names suggest performance problems,
9ab0e5
so it is worth collecting stats/counts of them.
9ab0e5
9ab0e5
Related: #2117
9ab0e5
Resolves: #2131
9ab0e5
9ab0e5
Signed-off-by: Jan Jansky <jjansky@redhat.com>
9ab0e5
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
9ab0e5
---
9ab0e5
 sos/plugins/foreman.py | 12 ++++++++++++
9ab0e5
 1 file changed, 12 insertions(+)
9ab0e5
9ab0e5
diff --git a/sos/plugins/foreman.py b/sos/plugins/foreman.py
9ab0e5
index a533251..16d8c7f 100644
9ab0e5
--- a/sos/plugins/foreman.py
9ab0e5
+++ b/sos/plugins/foreman.py
9ab0e5
@@ -204,6 +204,15 @@ class Foreman(Plugin):
9ab0e5
             % quote(months)
9ab0e5
         )
9ab0e5
 
9ab0e5
+        # counts of fact_names prefixes/types: much of one type suggests
9ab0e5
+        # performance issues
9ab0e5
+        factnamescmd = (
9ab0e5
+            'WITH prefix_counts AS (SELECT split_part(name,\'::\',1) FROM '
9ab0e5
+            'fact_names) SELECT COUNT(*), split_part AS "fact_name_prefix" '
9ab0e5
+            'FROM prefix_counts GROUP BY split_part ORDER BY count DESC '
9ab0e5
+            'LIMIT 100'
9ab0e5
+        )
9ab0e5
+
9ab0e5
         # Populate this dict with DB queries that should be saved directly as
9ab0e5
         # postgres formats them. The key will be the filename in the foreman
9ab0e5
         # plugin directory, with the value being the DB query to run
9ab0e5
@@ -213,6 +222,9 @@ class Foreman(Plugin):
9ab0e5
             'foreman_auth_table': authcmd,
9ab0e5
             'dynflow_schema_info': 'select * from dynflow_schema_info',
9ab0e5
             'foreman_tasks_tasks': 'select * from foreman_tasks_tasks',
9ab0e5
+            'audits_table_count': 'select count(*) from audits',
9ab0e5
+            'logs_table_count': 'select count(*) from logs',
9ab0e5
+            'fact_names_prefixes': factnamescmd,
9ab0e5
             'smart_proxies': 'select sp.name, sp.url, ' +
9ab0e5
                              'sp.download_policy,n.ip from smart_proxies ' +
9ab0e5
                              'as sp left join hosts as h on h.name=sp.name ' +
9ab0e5
-- 
9ab0e5
1.8.3.1
9ab0e5