| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package ceph |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/pkg/web" |
| 9 | ) |
| 10 | |
| 11 | func (c *Collector) collectPools(mx map[string]int64) error { |
| 12 | req, err := web.NewHTTPRequestWithPath(c.RequestConfig, urlPathApiPool) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | |
| 17 | req.URL.RawQuery = urlQueryApiPool |
| 18 | req.Header.Set("Accept", hdrAcceptVersion) |
| 19 | req.Header.Set("Content-Type", hdrContentTypeJson) |
| 20 | req.Header.Set("Authorization", "Bearer "+c.token) |
| 21 | |
| 22 | var pools []apiPoolResponse |
| 23 | |
| 24 | if err := c.webClient().RequestJSON(req, &pools); err != nil { |
| 25 | return err |
| 26 | } |
| 27 | |
| 28 | seen := make(map[string]bool) |
| 29 | |
| 30 | for _, pool := range pools { |
| 31 | px := fmt.Sprintf("pool_%s_", pool.PoolName) |
| 32 | |
| 33 | seen[pool.PoolName] = true |
| 34 | if !c.seenPools[pool.PoolName] { |
| 35 | c.seenPools[pool.PoolName] = true |
| 36 | c.addPoolCharts(pool.PoolName) |
| 37 | } |
| 38 | |
| 39 | mx[px+"objects"] = int64(pool.Stats.Objects.Latest) |
| 40 | mx[px+"size"] = int64(pool.Stats.AvailRaw.Latest) |
| 41 | mx[px+"space_used_bytes"] = int64(pool.Stats.BytesUsed.Latest) |
| 42 | mx[px+"space_avail_bytes"] = int64(pool.Stats.AvailRaw.Latest - pool.Stats.BytesUsed.Latest) |
| 43 | mx[px+"space_utilization"] = int64(pool.Stats.PercentUsed.Latest * precision) |
| 44 | mx[px+"read_ops"] = int64(pool.Stats.Reads.Latest) |
| 45 | mx[px+"read_bytes"] = int64(pool.Stats.ReadBytes.Latest) |
| 46 | mx[px+"write_ops"] = int64(pool.Stats.Writes.Latest) |
| 47 | mx[px+"written_bytes"] = int64(pool.Stats.WrittenBytes.Latest) |
| 48 | } |
| 49 | |
| 50 | for name := range c.seenPools { |
| 51 | if !seen[name] { |
| 52 | delete(c.seenPools, name) |
| 53 | c.removeCharts(fmt.Sprintf("pool_%s_", name)) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return nil |
| 58 | } |