Skip to content

Commit

Permalink
[pulp,katello] move qpid-stat commands to pulp plugin
Browse files Browse the repository at this point in the history
These commands are rather pulp-related and they are required to be
collected also on Satellite6 Capsules where no katello but pulp
is present.

Resolves: #1805

Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
pmoravec authored and bmr-cymru committed Oct 8, 2019
1 parent 0c9ef08 commit 8588e45
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
29 changes: 28 additions & 1 deletion sos/plugins/katello.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the LICENSE file in the source distribution for further information.

from sos.plugins import Plugin, RedHatPlugin
import os.path
from pipes import quote


class Katello(Plugin, RedHatPlugin):
Expand All @@ -35,5 +35,32 @@ def setup(self):
(opt, cert) for opt in "quc"
])

kat_db = self.build_query_cmd(
"select id,name,checksum_type,updated_at from katello_repositories"
)
self.add_cmd_output(kat_db, suggest_filename="katello_repositories")

db_size = self.build_query_cmd(
"SELECT table_name, pg_size_pretty(total_bytes) AS total, "
"pg_size_pretty(index_bytes) AS INDEX , "
"pg_size_pretty(toast_bytes) AS toast, pg_size_pretty(table_bytes)"
" AS TABLE FROM ( SELECT *, "
"total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes "
"FROM (SELECT c.oid,nspname AS table_schema, relname AS "
"TABLE_NAME, c.reltuples AS row_estimate, "
"pg_total_relation_size(c.oid) AS total_bytes, "
"pg_indexes_size(c.oid) AS index_bytes, "
"pg_total_relation_size(reltoastrelid) AS toast_bytes "
"FROM pg_class c LEFT JOIN pg_namespace n ON "
"n.oid = c.relnamespace WHERE relkind = 'r') a) a order by "
"total_bytes DESC"
)
self.add_cmd_output(db_size, suggest_filename="db_table_size")

def build_query_cmd(self, query):
_cmd = "su postgres -c %s"
_dbcmd = "psql foreman -c %s"
dbq = _dbcmd % quote(query)
return _cmd % quote(dbq)

# vim: set et ts=4 sw=4 :
15 changes: 15 additions & 0 deletions sos/plugins/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def setup(self):
# further, take optional user credentials - here we assume the
# credentials dont contain a whitespace character (that would
# make the parsing more difficult)
#
# further, collect location of CA file for contacting qpid in section
# [messaging]
# certfile: /etc/pki/katello/qpid_client_striped.crt
self.dbhost = "localhost"
self.dbport = "27017"
self.dbuser = ""
self.dbpassword = ""
self.messaging_cert_file = ""
in_messaging_section = False
try:
for line in open("/etc/pulp/server.conf").read().splitlines():
if match(r"^\s*seeds:\s+\S+:\S+", line):
Expand All @@ -45,6 +51,11 @@ def setup(self):
self.dbuser = "-u %s" % line.split()[1]
if match(r"\s*password:\s+\S+", line):
self.dbpassword = "-p %s" % line.split()[1]
if line.startswith("[messaging]"):
in_messaging_section = True
if in_messaging_section and line.startswith("certfile:"):
self.messaging_cert_file = line.split()[1]
in_messaging_section = False
except IOError:
# fallback when the cfg file is not accessible
pass
Expand Down Expand Up @@ -112,6 +123,10 @@ def setup(self):
self.add_cmd_output(prun, suggest_filename="pulp-running_tasks")
self.add_cmd_output(csizes, suggest_filename="mongo-collection_sizes")
self.add_cmd_output(dbstats, suggest_filename="mongo-db_stats")
self.add_cmd_output([
"qpid-stat -%s --ssl-certificate=%s -b amqps://localhost:5671" %
(opt, self.messaging_cert_file) for opt in "quc"
])

def build_mongo_cmd(self, query):
_cmd = "bash -c %s"
Expand Down

0 comments on commit 8588e45

Please sign in to comment.