| 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) collectOsds(mx map[string]int64) error { |
| 12 | req, err := web.NewHTTPRequestWithPath(c.RequestConfig, urlPathApiOsd) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | |
| 17 | req.Header.Set("Accept", hdrAcceptVersion) |
| 18 | req.Header.Set("Content-Type", hdrContentTypeJson) |
| 19 | req.Header.Set("Authorization", "Bearer "+c.token) |
| 20 | |
| 21 | var osds []apiOsdResponse |
| 22 | |
| 23 | if err := c.webClient().RequestJSON(req, &osds); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | seen := make(map[string]bool) |
| 28 | |
| 29 | for _, osd := range osds { |
| 30 | px := fmt.Sprintf("osd_%s_", osd.UUID) |
| 31 | |
| 32 | seen[osd.UUID] = true |
| 33 | if !c.seenOsds[osd.UUID] { |
| 34 | c.seenOsds[osd.UUID] = true |
| 35 | c.addOsdCharts(osd.UUID, osd.Tree.DeviceClass, osd.Tree.Name) |
| 36 | } |
| 37 | |
| 38 | mx[px+"status_up"], mx[px+"status_down"] = 1, 0 |
| 39 | if osd.Up == 0 { |
| 40 | mx[px+"status_up"], mx[px+"status_down"] = 0, 1 |
| 41 | } |
| 42 | mx[px+"status_in"], mx[px+"status_out"] = 1, 0 |
| 43 | if osd.In == 0 { |
| 44 | mx[px+"status_in"], mx[px+"status_out"] = 0, 1 |
| 45 | } |
| 46 | |
| 47 | mx[px+"size_bytes"] = osd.OsdStats.Statfs.Total |
| 48 | mx[px+"space_used_bytes"] = osd.OsdStats.Statfs.Total - osd.OsdStats.Statfs.Available |
| 49 | mx[px+"space_avail_bytes"] = osd.OsdStats.Statfs.Available |
| 50 | mx[px+"read_ops"] = int64(osd.Stats.OpR) |
| 51 | mx[px+"read_bytes"] = int64(osd.Stats.OpOutBytes) |
| 52 | mx[px+"write_ops"] = int64(osd.Stats.OpW) |
| 53 | mx[px+"written_bytes"] = int64(osd.Stats.OpInBytes) |
| 54 | mx[px+"commit_latency_ms"] = int64(osd.OsdStats.PerfStat.CommitLatencyMs) |
| 55 | mx[px+"apply_latency_ms"] = int64(osd.OsdStats.PerfStat.ApplyLatencyMs) |
| 56 | } |
| 57 | |
| 58 | for uuid := range c.seenOsds { |
| 59 | if !seen[uuid] { |
| 60 | delete(c.seenOsds, uuid) |
| 61 | c.removeCharts(fmt.Sprintf("osd_%s_", uuid)) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return nil |
| 66 | } |