1

I am writing a script to document the etcd clusters I create. I want to retrieve the cluster ID and member IDs and write it to a report.

I can get the member IDs easily, using etcdctl member list.

$ etcdctl member list
7a37a8973f10a944, started, etcd22, http://192.168.144.22:2380, http://192.168.144.22:2379
bda5a1801ac0115d, started, etcd21, http://192.168.144.21:2380, http://192.168.144.21:2379
c0f27f3c63dd09c6, started, etcd23, http://192.168.144.23:2380, http://192.168.144.23:2379

However, how do I get the cluster ID from a script? The only place I see it printed is in the stdout when the etcd is first initialised.

etcdserver: starting member c0f27f3c63dd09c6 in cluster bd535900b5473128
dayuloli
  • 16,205
  • 16
  • 71
  • 126

1 Answers1

3

The RPC responses from the server have headers that contains the cluster id. By changing the output format, you can display the header information.

For example:

$ etcdctl member list -w fields
"ClusterID" : 14841639068965178418
"MemberID" : 10276657743932975437
"Revision" : 0
"RaftTerm" : 3
"ID" : 10276657743932975437
"Name" : "default"
"PeerURL" : "http://localhost:2380"
"ClientURL" : "http://localhost:2379"

or

$ etcdctl member list -w json
{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"raft_term":3},"members":[{"ID":10276657743932975437,"name":"default","peerURLs":["http://localhost:2380"],"clientURLs":["http://localhost:2379"]}]}