Skip to content

Commit

Permalink
Merge c0934d4 into df1d1cb
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreedl committed Jun 17, 2020
2 parents df1d1cb + c0934d4 commit d96515a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
19 changes: 18 additions & 1 deletion collectors/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,25 @@ func (n *NoopConn) MonCommand(args []byte) ([]byte, string, error) {

case "osd dump":
return []byte(n.cmdOut[n.iteration]["ceph osd dump"]), "", nil
}

case "osd erasure-code-profile get ec-4-2":
ec42Return :=
`{
"crush-device-class": "",
"crush-failure-domain": "host",
"crush-root": "objectdata",
"jerasure-per-chunk-alignment": "false",
"k": "4",
"m": "2",
"plugin": "jerasure",
"technique": "reed_sol_van",
"w": "8"
}`
return []byte(ec42Return), "", nil

case "osd erasure-code-profile get replicated-ruleset":
return []byte("{}"), "", nil
}
return []byte(n.output), "", nil
}

Expand Down
77 changes: 65 additions & 12 deletions collectors/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ package collectors

import (
"encoding/json"
"fmt"
"log"
"math"
"strconv"

"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -54,6 +57,9 @@ type PoolInfoCollector struct {

// StripeWidth contains width of a RADOS object in a pool.
StripeWidth *prometheus.GaugeVec

// ExpansionFactor Contains a float >= 1 that defines the EC or replication multiplier of a pool
ExpansionFactor *prometheus.GaugeVec
}

// NewPoolInfoCollector displays information about each pool in the cluster.
Expand Down Expand Up @@ -139,6 +145,16 @@ func NewPoolInfoCollector(conn Conn, cluster string) *PoolInfoCollector {
},
poolLabels,
),
ExpansionFactor: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: cephNamespace,
Subsystem: subSystem,
Name: "expansion_factor",
Help: "Data expansion multiplier for a pool",
ConstLabels: labels,
},
poolLabels,
),
}
}

Expand All @@ -151,22 +167,25 @@ func (p *PoolInfoCollector) collectorList() []prometheus.Collector {
p.QuotaMaxBytes,
p.QuotaMaxObjects,
p.StripeWidth,
p.ExpansionFactor,
}
}

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"`
}

type cephPoolInfo struct {
Pools []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"`
}
Pools []poolInfo
}

func (p *PoolInfoCollector) collect() error {
Expand All @@ -189,6 +208,7 @@ func (p *PoolInfoCollector) collect() error {
p.QuotaMaxBytes.Reset()
p.QuotaMaxObjects.Reset()
p.StripeWidth.Reset()
p.ExpansionFactor.Reset()

for _, pool := range stats.Pools {
if pool.Type == poolReplicated {
Expand All @@ -201,6 +221,7 @@ func (p *PoolInfoCollector) collect() error {
p.QuotaMaxBytes.WithLabelValues(pool.Name, pool.Profile).Set(pool.QuotaMaxBytes)
p.QuotaMaxObjects.WithLabelValues(pool.Name, pool.Profile).Set(pool.QuotaMaxObjects)
p.StripeWidth.WithLabelValues(pool.Name, pool.Profile).Set(pool.StripeWidth)
p.ExpansionFactor.WithLabelValues(pool.Name, pool.Profile).Set(p.getExpansionCommand(pool))
}

return nil
Expand Down Expand Up @@ -240,3 +261,35 @@ func (p *PoolInfoCollector) Collect(ch chan<- prometheus.Metric) {
metric.Collect(ch)
}
}

func (p *PoolInfoCollector) getExpansionCommand(pool poolInfo) float64 {
prefix := fmt.Sprintf("osd erasure-code-profile get %s", pool.Profile)
cmd, err := json.Marshal(map[string]interface{}{
"prefix": prefix,
"detail": "detail",
"format": "json",
})

buf, _, err := p.conn.MonCommand(cmd)
if err != nil {
return -1
}

type ecInfo struct {
K string `json:"k"`
M string `json:"m"`
}

ecStats := ecInfo{}
err = json.Unmarshal(buf, &ecStats)
if err != nil || ecStats.K == "" || ecStats.M == "" {
return pool.ActualSize
}

k, _ := strconv.ParseFloat(ecStats.K, 64)
m, _ := strconv.ParseFloat(ecStats.M, 64)

expansionFactor := (k + m) / k
roundedExpansion := math.Round(expansionFactor*100) / 100
return roundedExpansion
}
2 changes: 2 additions & 0 deletions collectors/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestPoolInfoCollector(t *testing.T) {
regexp.MustCompile(`pool_quota_max_bytes{cluster="ceph",pool="rbd",profile="ec-4-2"} 1024`),
regexp.MustCompile(`pool_quota_max_objects{cluster="ceph",pool="rbd",profile="ec-4-2"} 2048`),
regexp.MustCompile(`pool_stripe_width{cluster="ceph",pool="rbd",profile="ec-4-2"} 4096`),
regexp.MustCompile(`pool_expansion_factor{cluster="ceph",pool="rbd",profile="ec-4-2"} 1.5`),

regexp.MustCompile(`pool_size{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 3`),
regexp.MustCompile(`pool_min_size{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 2`),
Expand All @@ -54,6 +55,7 @@ func TestPoolInfoCollector(t *testing.T) {
regexp.MustCompile(`pool_quota_max_bytes{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 512`),
regexp.MustCompile(`pool_quota_max_objects{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 1024`),
regexp.MustCompile(`pool_stripe_width{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 4096`),
regexp.MustCompile(`pool_expansion_factor{cluster="ceph",pool="rbd",profile="replicated-ruleset"} 3`),
},
reUnmatch: []*regexp.Regexp{},
},
Expand Down

0 comments on commit d96515a

Please sign in to comment.