diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2017-07-15 23:53:36 -0400 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2017-08-31 17:03:19 +0100 |
commit | 45d55b34a20b6f36788289e2ebfb33943aa2c3a4 (patch) | |
tree | 8a5999210e12bd534ff823caa0643d05707dcb3a | |
parent | 17aa75c07e2fca094fd99929044a2cf126163d61 (diff) | |
download | sos-45d55b34a20b6f36788289e2ebfb33943aa2c3a4.tar.gz |
[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 <jhunsake@redhat.com>
-rw-r--r-- | sos/plugins/etcd.py | 45 |
1 files 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 |