From: Paul Cuzner Date: Wed, 23 Aug 2017 02:58:34 +0000 (+1200) Subject: rgw: look for the admin_socket on each call X-Git-Tag: v1.0~28^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7760bbfcae60e46f6cc13c840c907d966bbdc921;p=cephmetrics.git rgw: look for the admin_socket on each call The admin_socket name for rgw is not fixed, unlike mon/osds. Therefore to account for svc restarts and name changes the socket name is determined at each get_stats cycle. If the socket isn't there, the collector just passes back the version of radosgw to the caller and will send stats again once a socket is detected on the host --- diff --git a/collectors/rgw.py b/collectors/rgw.py index 45f9749..72bd9dd 100644 --- a/collectors/rgw.py +++ b/collectors/rgw.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import time +import glob from collectors.base import BaseCollector from collectors.common import get_hostname, merge_dicts @@ -35,20 +36,28 @@ class RGW(BaseCollector): def __init__(self, *args, **kwargs): BaseCollector.__init__(self, *args, **kwargs) + self.host_name = get_hostname() def _get_rgw_data(self): - response = self._admin_socket() - - if response: - key_name = 'client.rgw.{}'.format(self.host_name) - return response.get(key_name) + rgw_sockets = glob.glob('/var/run/ceph/{}-client.rgw.' + '{}.*.asok'.format(self.cluster_name, + self.host_name)) + if rgw_sockets: + response = self._admin_socket(socket_path=rgw_sockets[0]) + + if response: + key_name = 'client.rgw.{}'.format(self.host_name) + return response.get(key_name) + else: + # admin_socket call failed + return {} else: - # admin_socket call failed return {} - def _filter(self, stats): + @staticmethod + def stats_filter(stats): # pick out the simple metrics filtered = {key: stats[key] for key in RGW.simple_metrics} @@ -66,9 +75,13 @@ class RGW(BaseCollector): raw_stats = self._get_rgw_data() if raw_stats: - stats = self._filter(raw_stats) + stats = RGW.stats_filter(raw_stats) else: stats = {} + self.error = True + msg = 'RGW socket not available...radosgw running?' + self.error_msgs = [msg] + self.logger.warning(msg) stats['ceph_version'] = self.version