From 7dd7018835f20b4b232bfdd33bb07ec6cacfe483 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 7 Jun 2018 10:44:51 -0700 Subject: [PATCH 1/2] etcdserver: add "etcd_server_quota_backend_bytes" Signed-off-by: Gyuho Lee --- etcdserver/metrics.go | 7 +++++++ etcdserver/quota.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/etcdserver/metrics.go b/etcdserver/metrics.go index b1f85e78ff6..60e5395a300 100644 --- a/etcdserver/metrics.go +++ b/etcdserver/metrics.go @@ -84,6 +84,12 @@ var ( Name: "lease_expired_total", Help: "The total number of expired leases.", }) + quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "etcd", + Subsystem: "server", + Name: "quota_backend_bytes", + Help: "Current backend storage quota size in bytes.", + }) currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "etcd", Subsystem: "server", @@ -104,6 +110,7 @@ func init() { prometheus.MustRegister(proposalsPending) prometheus.MustRegister(proposalsFailed) prometheus.MustRegister(leaseExpired) + prometheus.MustRegister(quotaBackendBytes) prometheus.MustRegister(currentVersion) currentVersion.With(prometheus.Labels{ diff --git a/etcdserver/quota.go b/etcdserver/quota.go index 1662c4b5b21..737abfe11ef 100644 --- a/etcdserver/quota.go +++ b/etcdserver/quota.go @@ -62,6 +62,7 @@ const ( func NewBackendQuota(s *EtcdServer, name string) Quota { lg := s.getLogger() + quotaBackendBytes.Set(float64(s.Cfg.QuotaBackendBytes)) if s.Cfg.QuotaBackendBytes < 0 { // disable quotas if negative @@ -87,6 +88,7 @@ func NewBackendQuota(s *EtcdServer, name string) Quota { zap.String("quota-size", humanize.Bytes(uint64(DefaultQuotaBytes))), ) } + quotaBackendBytes.Set(float64(DefaultQuotaBytes)) return &backendQuota{s, DefaultQuotaBytes} } From 184372cd1be4ced42b3864713cb586d9aa15bf72 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 7 Jun 2018 10:48:16 -0700 Subject: [PATCH 2/2] integration: add "TestMetricQuotaBackendBytes" Signed-off-by: Gyuho Lee --- integration/metrics_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/integration/metrics_test.go b/integration/metrics_test.go index 3dccd220af1..31d4b4b4007 100644 --- a/integration/metrics_test.go +++ b/integration/metrics_test.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "github.com/coreos/etcd/etcdserver" + pb "github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/pkg/testutil" ) @@ -137,3 +139,21 @@ func TestMetricDbSizeDefrag(t *testing.T) { t.Fatalf("db size in use (%d) is expected less than db size (%d) after defrag", adiu, av) } } + +func TestMetricQuotaBackendBytes(t *testing.T) { + defer testutil.AfterTest(t) + clus := NewClusterV3(t, &ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + qs, err := clus.Members[0].Metric("etcd_server_quota_backend_bytes") + if err != nil { + t.Fatal(err) + } + qv, err := strconv.ParseFloat(qs, 64) + if err != nil { + t.Fatal(err) + } + if int64(qv) != etcdserver.DefaultQuotaBytes { + t.Fatalf("expected %d, got %f", etcdserver.DefaultQuotaBytes, qv) + } +}