diff --git a/METRICS.md b/METRICS.md index 3bb387b..14575fb 100644 --- a/METRICS.md +++ b/METRICS.md @@ -46,6 +46,7 @@ Labels: - `pool`: pool name - `root`: CRUSH root of the pool - `profile`: `replicated` or EC profile being used +- `application`: comma-separated list of applications enabled on the pool (e.g. `rbd`, `rgw`, `cephfs`), empty if none are enabled Metrics: - `ceph_pool_pg_num`: The total count of PGs alotted to a pool diff --git a/ceph/pool.go b/ceph/pool.go index d92e956..84b8df6 100644 --- a/ceph/pool.go +++ b/ceph/pool.go @@ -18,7 +18,9 @@ import ( "encoding/json" "errors" "math" + "sort" "strconv" + "strings" "sync" "github.com/prometheus/client_golang/prometheus" @@ -68,7 +70,7 @@ type PoolInfoCollector struct { func NewPoolInfoCollector(exporter *Exporter) *PoolInfoCollector { var ( subSystem = "pool" - poolLabels = []string{"pool", "profile", "root"} + poolLabels = []string{"pool", "profile", "root", "application"} ) labels := make(prometheus.Labels) @@ -175,17 +177,18 @@ func (p *PoolInfoCollector) collectorList() []prometheus.Collector { } type poolInfo struct { - Name string `json:"pool_name"` - ActualSize float64 `json:"size"` - MinSize float64 `json:"min_size"` - PGNum float64 `json:"pg_num"` - PlacementPGNum float64 `json:"pg_placement_num"` - QuotaMaxBytes float64 `json:"quota_max_bytes"` - QuotaMaxObjects float64 `json:"quota_max_objects"` - Profile string `json:"erasure_code_profile"` - Type int64 `json:"type"` - StripeWidth float64 `json:"stripe_width"` - CrushRule int64 `json:"crush_rule"` + Name string `json:"pool_name"` + ActualSize float64 `json:"size"` + MinSize float64 `json:"min_size"` + PGNum float64 `json:"pg_num"` + PlacementPGNum float64 `json:"pg_placement_num"` + QuotaMaxBytes float64 `json:"quota_max_bytes"` + QuotaMaxObjects float64 `json:"quota_max_objects"` + Profile string `json:"erasure_code_profile"` + Type int64 `json:"type"` + StripeWidth float64 `json:"stripe_width"` + CrushRule int64 `json:"crush_rule"` + ApplicationMetadata map[string]interface{} `json:"application_metadata"` } type cephPoolInfo struct { @@ -241,7 +244,7 @@ func (p *PoolInfoCollector) collect() error { if pool.Type == poolReplicated { pool.Profile = "replicated" } - labelValues := []string{pool.Name, pool.Profile, ruleToRootMappings[pool.CrushRule]} + labelValues := []string{pool.Name, pool.Profile, ruleToRootMappings[pool.CrushRule], applicationLabel(pool.ApplicationMetadata)} p.PGNum.WithLabelValues(labelValues...).Set(pool.PGNum) p.PlacementPGNum.WithLabelValues(labelValues...).Set(pool.PlacementPGNum) p.MinSize.WithLabelValues(labelValues...).Set(pool.MinSize) @@ -289,6 +292,22 @@ func (p *PoolInfoCollector) Collect(ch chan<- prometheus.Metric, version *Versio } } +// applicationLabel derives a comma-separated "application" label value +// (e.g. "rbd", "rgw", "cephfs") from a pool's application_metadata. +func applicationLabel(applicationMetadata map[string]interface{}) string { + if len(applicationMetadata) == 0 { + return "" + } + + apps := make([]string, 0, len(applicationMetadata)) + for app := range applicationMetadata { + apps = append(apps, app) + } + sort.Strings(apps) + + return strings.Join(apps, ",") +} + func (p *PoolInfoCollector) getExpansionFactor(pool poolInfo) float64 { ef, err := p.getECExpansionFactor(pool) if err == nil { diff --git a/ceph/pool_test.go b/ceph/pool_test.go index 35b4d48..2f9fb98 100644 --- a/ceph/pool_test.go +++ b/ceph/pool_test.go @@ -39,23 +39,23 @@ func TestPoolInfoCollector(t *testing.T) { { version: `{"version":"ceph version 16.2.11-22-wasd (1984a8c33225d70559cdf27dbab81e3ce153f6ac) pacific (stable)"}`, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`pool_size{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 6`), - regexp.MustCompile(`pool_min_size{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 4`), - regexp.MustCompile(`pool_pg_num{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 8192`), - regexp.MustCompile(`pool_pgp_num{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 8192`), - regexp.MustCompile(`pool_quota_max_bytes{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 1024`), - regexp.MustCompile(`pool_quota_max_objects{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 2048`), - regexp.MustCompile(`pool_stripe_width{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 4096`), - regexp.MustCompile(`pool_expansion_factor{cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 1.5`), - - regexp.MustCompile(`pool_size{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 3`), - regexp.MustCompile(`pool_min_size{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 2`), - regexp.MustCompile(`pool_pg_num{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 16384`), - regexp.MustCompile(`pool_pgp_num{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 16384`), - regexp.MustCompile(`pool_quota_max_bytes{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 512`), - regexp.MustCompile(`pool_quota_max_objects{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 1024`), - regexp.MustCompile(`pool_stripe_width{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 4096`), - regexp.MustCompile(`pool_expansion_factor{cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 3`), + regexp.MustCompile(`pool_size{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 6`), + regexp.MustCompile(`pool_min_size{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 4`), + regexp.MustCompile(`pool_pg_num{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 8192`), + regexp.MustCompile(`pool_pgp_num{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 8192`), + regexp.MustCompile(`pool_quota_max_bytes{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 1024`), + regexp.MustCompile(`pool_quota_max_objects{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 2048`), + regexp.MustCompile(`pool_stripe_width{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 4096`), + regexp.MustCompile(`pool_expansion_factor{application="rbd",cluster="ceph",pool="rbd",profile="ec-4-2",root="non-default-root"} 1.5`), + + regexp.MustCompile(`pool_size{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 3`), + regexp.MustCompile(`pool_min_size{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 2`), + regexp.MustCompile(`pool_pg_num{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 16384`), + regexp.MustCompile(`pool_pgp_num{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 16384`), + regexp.MustCompile(`pool_quota_max_bytes{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 512`), + regexp.MustCompile(`pool_quota_max_objects{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 1024`), + regexp.MustCompile(`pool_stripe_width{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 4096`), + regexp.MustCompile(`pool_expansion_factor{application="",cluster="ceph",pool="rbd",profile="replicated-ruleset",root="default"} 3`), }, reUnmatch: []*regexp.Regexp{}, }, @@ -75,8 +75,8 @@ func TestPoolInfoCollector(t *testing.T) { }) })).Return([]byte(` [ - {"pool_name": "rbd", "crush_rule": 1, "size": 6, "min_size": 4, "pg_num": 8192, "pg_placement_num": 8192, "quota_max_bytes": 1024, "quota_max_objects": 2048, "erasure_code_profile": "ec-4-2", "stripe_width": 4096}, - {"pool_name": "rbd", "crush_rule": 0, "size": 3, "min_size": 2, "pg_num": 16384, "pg_placement_num": 16384, "quota_max_bytes": 512, "quota_max_objects": 1024, "erasure_code_profile": "replicated-ruleset", "stripe_width": 4096} + {"pool_name": "rbd", "crush_rule": 1, "size": 6, "min_size": 4, "pg_num": 8192, "pg_placement_num": 8192, "quota_max_bytes": 1024, "quota_max_objects": 2048, "erasure_code_profile": "ec-4-2", "stripe_width": 4096, "application_metadata": {"rbd": {}}}, + {"pool_name": "rbd", "crush_rule": 0, "size": 3, "min_size": 2, "pg_num": 16384, "pg_placement_num": 16384, "quota_max_bytes": 512, "quota_max_objects": 1024, "erasure_code_profile": "replicated-ruleset", "stripe_width": 4096, "application_metadata": {}} ]`, ), "", nil)