From 06a56c1c62c3cd55d94682dfff2a8df305b7596f Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Sat, 11 Aug 2018 22:13:41 -0700 Subject: [PATCH] etcdserver: add "etcd_server_id" metric ``` etcd_server_id{server_id="8e9e05c52164694d"} 1 ``` Useful for automating membership change operations, no need to run "endpoint status" or "member list" command to get member IDs. Also, useful for "etcd_network" metrics with "To/From" labels. Signed-off-by: Gyuho Lee --- etcdserver/metrics.go | 8 ++++++++ etcdserver/server.go | 2 ++ 2 files changed, 10 insertions(+) diff --git a/etcdserver/metrics.go b/etcdserver/metrics.go index afc994c3f47f..58147c430441 100644 --- a/etcdserver/metrics.go +++ b/etcdserver/metrics.go @@ -112,6 +112,13 @@ var ( Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.", }, []string{"server_go_version"}) + serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "etcd", + Subsystem: "server", + Name: "id", + Help: "Server or member ID in hexadecimal format (1 for 'server_id' label with current ID)", + }, + []string{"server_id"}) ) func init() { @@ -129,6 +136,7 @@ func init() { prometheus.MustRegister(quotaBackendBytes) prometheus.MustRegister(currentVersion) prometheus.MustRegister(currentGoVersion) + prometheus.MustRegister(serverID) currentVersion.With(prometheus.Labels{ "server_version": version.Version, diff --git a/etcdserver/server.go b/etcdserver/server.go index 0df0354f9898..7b569f20c935 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -60,6 +60,7 @@ import ( "github.com/coreos/go-semver/semver" "github.com/coreos/pkg/capnslog" humanize "github.com/dustin/go-humanize" + "github.com/prometheus/client_golang/prometheus" "go.uber.org/zap" ) @@ -511,6 +512,7 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) { forceVersionC: make(chan struct{}), AccessController: &AccessController{CORS: cfg.CORS, HostWhitelist: cfg.HostWhitelist}, } + serverID.With(prometheus.Labels{"server_id": id.String()}).Set(1) srv.applyV2 = &applierV2store{store: srv.v2store, cluster: srv.cluster}