Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add "etcd_server_quota_backend_bytes" metric #9820

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
}
}