From 45d55b34a20b6f36788289e2ebfb33943aa2c3a4 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Sat, 15 Jul 2017 23:53:36 -0400 Subject: [etcd] Use etcdctl and determine proper listening address This moves several collected outputs over from using curl to using the etcdctl command, as well as adding some addition collection. Only statistic information is now obtained via curl. Also we now attempt to determine the actual listening address based on etcd.conf, and if that is not possible the plugin assumes version-specifc defaults. Closes: #1059. Signed-off-by: Jake Hunsaker --- sos/plugins/etcd.py | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/sos/plugins/etcd.py b/sos/plugins/etcd.py index 89b2dd9c..d5c8fceb 100644 --- a/sos/plugins/etcd.py +++ b/sos/plugins/etcd.py @@ -23,15 +23,48 @@ class etcd(Plugin, RedHatPlugin): """etcd plugin """ + packages = ('etcd',) + + cmd = 'etcdctl' + def setup(self): - self.add_copy_spec("/etc/etcd") + etcd_url = self.get_etcd_url() + + self.add_copy_spec('/etc/etcd') + + subcmds = [ + '--version', + 'member list', + 'cluster-health', + 'ls --recursive', + ] + + self.add_cmd_output(['%s %s' % (self.cmd, sub) for sub in subcmd]) + + urls = [ + '/v2/stats/leader', + '/v2/stats/self', + '/v2/stats/store', + ] + + if etcd_url: + self.add_cmd_output(['curl -s %s%s' % (etcd_url, u) for u in urls]) - self.add_cmd_output("curl http://localhost:4001/version") - self.add_cmd_output("curl http://localhost:4001/v2/members") - self.add_cmd_output("curl http://localhost:4001/v2/stats/leader") - self.add_cmd_output("curl http://localhost:4001/v2/stats/self") - self.add_cmd_output("curl http://localhost:4001/v2/stats/store") self.add_cmd_output("ls -lR /var/lib/etcd/") + def get_etcd_url(self): + try: + with open('/etc/etcd/etcd.conf', 'r') as ef: + for line in ef: + if line.startswith('ETCD_LISTEN_CLIENT_URLS'): + return line.split('=')[1].replace('"', '').strip() + # If we can't read etcd.conf, assume defaults by etcd version + except: + ver = self.policy().package_manager.get_pkg_list()['etcd'] + ver = ver['version'][0] + if ver == '2': + return 'http://localhost:4001' + if ver == '3': + return 'http://localhost:2379' # vim: et ts=5 sw=4 -- cgit