Skip to content

Commit

Permalink
Merge pull request #9820 from gyuho/quota-size
Browse files Browse the repository at this point in the history
*: add "etcd_server_quota_backend_bytes" metric
  • Loading branch information
gyuho authored Jun 7, 2018
2 parents a9aafc8 + 184372c commit d6ff23e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions etcdserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions etcdserver/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
}

Expand Down
20 changes: 20 additions & 0 deletions integration/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -145,3 +147,21 @@ func testMetricDbSizeDefrag(t *testing.T, name string) {
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)
}
}

0 comments on commit d6ff23e

Please sign in to comment.