2016-07-14 05:01:19 +00:00
|
|
|
package collectors
|
|
|
|
|
|
|
|
import (
|
2018-06-14 18:40:46 +00:00
|
|
|
"bytes"
|
2016-07-14 05:01:19 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2020-06-15 20:52:22 +00:00
|
|
|
"math"
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2018-06-14 18:40:46 +00:00
|
|
|
"strings"
|
2018-06-24 17:16:09 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2018-06-14 18:40:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
osdLabelFormat = "osd.%v"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
scrubStateIdle = 0
|
|
|
|
scrubStateScrubbing = 1
|
|
|
|
scrubStateDeepScrubbing = 2
|
2016-07-14 05:01:19 +00:00
|
|
|
)
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
// OSDCollector displays statistics about OSD in the Ceph cluster.
|
2019-12-10 19:34:52 +00:00
|
|
|
// An important aspect of monitoring OSDs is to ensure that when the cluster is
|
|
|
|
// up and running that all OSDs that are in the cluster are up and running, too
|
2016-07-29 03:04:55 +00:00
|
|
|
type OSDCollector struct {
|
2016-07-14 05:01:19 +00:00
|
|
|
conn Conn
|
|
|
|
|
2018-06-14 18:40:46 +00:00
|
|
|
// osdScrubCache holds the cache of previous PG scrubs
|
|
|
|
osdScrubCache map[int]int
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
// osdLabelsCache holds a cache of osd labels
|
|
|
|
osdLabelsCache map[int64]*cephOSDLabel
|
|
|
|
|
|
|
|
// osdObjectsBackfilledCache holds the cache of previous increase in number
|
|
|
|
// of objects backfilled of all OSDs
|
|
|
|
osdObjectsBackfilledCache map[int64]int64
|
|
|
|
|
|
|
|
// pgStateCache holds the cache of previous states of all PGs
|
|
|
|
pgStateCache map[string]string
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// pgObjectsRecoveredCache holds the cache of previous number of objects
|
|
|
|
// recovered of all PGs
|
|
|
|
pgObjectsRecoveredCache map[string]int64
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
// pgBackfillTargetsCache holds the cache of previous backfill targets OSDs
|
|
|
|
// of all PGs
|
|
|
|
pgBackfillTargetsCache map[string]map[int64]int64
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// pgDumpBrief holds the content of PG dump brief
|
|
|
|
pgDumpBrief cephPGDumpBrief
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// CrushWeight is a persistent setting, and it affects how CRUSH assigns data to OSDs.
|
|
|
|
// It displays the CRUSH weight for the OSD
|
2016-07-14 05:01:19 +00:00
|
|
|
CrushWeight *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// Depth displays the OSD's level of hierarchy in the CRUSH map
|
2016-07-14 05:01:19 +00:00
|
|
|
Depth *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// Reweight sets an override weight on the OSD.
|
|
|
|
// It displays value within 0 to 1.
|
2016-07-14 05:01:19 +00:00
|
|
|
Reweight *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// Bytes displays the total bytes available in the OSD
|
2016-07-27 09:48:54 +00:00
|
|
|
Bytes *prometheus.GaugeVec
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// UsedBytes displays the total used bytes in the OSD
|
2016-07-27 09:48:54 +00:00
|
|
|
UsedBytes *prometheus.GaugeVec
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// AvailBytes displays the total available bytes in the OSD
|
2016-07-27 09:48:54 +00:00
|
|
|
AvailBytes *prometheus.GaugeVec
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// Utilization displays current utilization of the OSD
|
2016-07-14 05:01:19 +00:00
|
|
|
Utilization *prometheus.GaugeVec
|
|
|
|
|
2016-10-19 09:45:05 +00:00
|
|
|
// Variance displays current variance of the OSD from the standard utilization
|
|
|
|
Variance *prometheus.GaugeVec
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// Pgs displays total number of placement groups in the OSD.
|
2016-07-29 03:04:55 +00:00
|
|
|
// Available in Ceph Jewel version.
|
2016-07-14 05:01:19 +00:00
|
|
|
Pgs *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// CommitLatency displays in seconds how long it takes for an operation to be applied to disk
|
2016-07-14 05:01:19 +00:00
|
|
|
CommitLatency *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// ApplyLatency displays in seconds how long it takes to get applied to the backing filesystem
|
2016-07-14 05:01:19 +00:00
|
|
|
ApplyLatency *prometheus.GaugeVec
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// OSDIn displays the In state of the OSD
|
|
|
|
OSDIn *prometheus.GaugeVec
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// OSDUp displays the Up state of the OSD
|
|
|
|
OSDUp *prometheus.GaugeVec
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// OSDFull flags if an OSD is full
|
2019-05-28 16:42:01 +00:00
|
|
|
OSDFull *prometheus.GaugeVec
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// OSDNearfull flags if an OSD is near full
|
2019-05-28 16:42:01 +00:00
|
|
|
OSDNearFull *prometheus.GaugeVec
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// OSDBackfillFull flags if an OSD is backfill full
|
2019-05-28 16:42:01 +00:00
|
|
|
OSDBackfillFull *prometheus.GaugeVec
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
// OSDDownDesc displays OSDs present in the cluster in "down" state
|
|
|
|
OSDDownDesc *prometheus.Desc
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// TotalBytes displays total bytes in all OSDs
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalBytes prometheus.Gauge
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// TotalUsedBytes displays total used bytes in all OSDs
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalUsedBytes prometheus.Gauge
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// TotalAvailBytes displays total available bytes in all OSDs
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalAvailBytes prometheus.Gauge
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
// AverageUtil displays average utilization in all OSDs
|
2016-07-14 05:01:19 +00:00
|
|
|
AverageUtil prometheus.Gauge
|
2018-06-14 18:40:46 +00:00
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// ScrubbingStateDesc depicts if an OSD is being scrubbed
|
|
|
|
// labeled by OSD
|
2018-06-14 18:40:46 +00:00
|
|
|
ScrubbingStateDesc *prometheus.Desc
|
2019-12-10 19:34:52 +00:00
|
|
|
|
|
|
|
// PGObjectsRecoveredDesc displays total number of objects recovered in a PG
|
|
|
|
PGObjectsRecoveredDesc *prometheus.Desc
|
2020-06-15 20:52:22 +00:00
|
|
|
|
|
|
|
// OSDObjectsBackfilled displays average number of objects backfilled in an OSD
|
|
|
|
OSDObjectsBackfilled *prometheus.CounterVec
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// This ensures OSDCollector implements interface prometheus.Collector.
|
|
|
|
var _ prometheus.Collector = &OSDCollector{}
|
|
|
|
|
|
|
|
// NewOSDCollector creates an instance of the OSDCollector and instantiates the
|
|
|
|
// individual metrics that show information about the OSD.
|
2017-03-23 20:20:25 +00:00
|
|
|
func NewOSDCollector(conn Conn, cluster string) *OSDCollector {
|
|
|
|
labels := make(prometheus.Labels)
|
|
|
|
labels["cluster"] = cluster
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels := []string{"osd", "device_class", "host", "rack", "root"}
|
2017-03-23 20:20:25 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
return &OSDCollector{
|
2020-06-15 20:52:22 +00:00
|
|
|
conn: conn,
|
|
|
|
|
|
|
|
osdScrubCache: make(map[int]int),
|
|
|
|
osdLabelsCache: make(map[int64]*cephOSDLabel),
|
|
|
|
osdObjectsBackfilledCache: make(map[int64]int64),
|
|
|
|
pgStateCache: make(map[string]string),
|
|
|
|
pgObjectsRecoveredCache: make(map[string]int64),
|
|
|
|
pgBackfillTargetsCache: make(map[string]map[int64]int64),
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
CrushWeight: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_crush_weight",
|
|
|
|
Help: "OSD Crush Weight",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
Depth: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_depth",
|
|
|
|
Help: "OSD Depth",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
Reweight: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_reweight",
|
|
|
|
Help: "OSD Reweight",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
Bytes: prometheus.NewGaugeVec(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_bytes",
|
|
|
|
Help: "OSD Total Bytes",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
UsedBytes: prometheus.NewGaugeVec(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_used_bytes",
|
|
|
|
Help: "OSD Used Storage in Bytes",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
AvailBytes: prometheus.NewGaugeVec(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_avail_bytes",
|
|
|
|
Help: "OSD Available Storage in Bytes",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
Utilization: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_utilization",
|
|
|
|
Help: "OSD Utilization",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-10-19 09:45:05 +00:00
|
|
|
Variance: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_variance",
|
|
|
|
Help: "OSD Variance",
|
|
|
|
ConstLabels: labels,
|
2016-10-19 09:45:05 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-10-19 09:45:05 +00:00
|
|
|
),
|
|
|
|
|
2016-07-14 05:01:19 +00:00
|
|
|
Pgs: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_pgs",
|
|
|
|
Help: "OSD Placement Group Count",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalBytes: prometheus.NewGauge(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_total_bytes",
|
|
|
|
Help: "OSD Total Storage Bytes",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
|
|
|
),
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalUsedBytes: prometheus.NewGauge(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_total_used_bytes",
|
|
|
|
Help: "OSD Total Used Storage Bytes",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
TotalAvailBytes: prometheus.NewGauge(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_total_avail_bytes",
|
|
|
|
Help: "OSD Total Available Storage Bytes ",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
AverageUtil: prometheus.NewGauge(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_average_utilization",
|
|
|
|
Help: "OSD Average Utilization",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
CommitLatency: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_perf_commit_latency_seconds",
|
|
|
|
Help: "OSD Perf Commit Latency",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
ApplyLatency: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_perf_apply_latency_seconds",
|
|
|
|
Help: "OSD Perf Apply Latency",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
OSDIn: prometheus.NewGaugeVec(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_in",
|
|
|
|
Help: "OSD In Status",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
OSDUp: prometheus.NewGaugeVec(
|
2016-07-14 05:01:19 +00:00
|
|
|
prometheus.GaugeOpts{
|
2017-03-23 20:20:25 +00:00
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_up",
|
|
|
|
Help: "OSD Up Status",
|
|
|
|
ConstLabels: labels,
|
2016-07-14 05:01:19 +00:00
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2016-07-14 05:01:19 +00:00
|
|
|
),
|
2019-05-28 16:42:01 +00:00
|
|
|
|
|
|
|
OSDFull: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_full",
|
|
|
|
Help: "OSD Full Status",
|
|
|
|
ConstLabels: labels,
|
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2019-05-28 16:42:01 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
OSDNearFull: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_near_full",
|
|
|
|
Help: "OSD Near Full Status",
|
|
|
|
ConstLabels: labels,
|
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2019-05-28 16:42:01 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
OSDBackfillFull: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_backfill_full",
|
|
|
|
Help: "OSD Backfill Full Status",
|
|
|
|
ConstLabels: labels,
|
|
|
|
},
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2019-05-28 16:42:01 +00:00
|
|
|
),
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
OSDDownDesc: prometheus.NewDesc(
|
|
|
|
fmt.Sprintf("%s_osd_down", cephNamespace),
|
2019-12-10 19:34:52 +00:00
|
|
|
"Number of OSDs down in the cluster",
|
2020-06-15 20:52:22 +00:00
|
|
|
append([]string{"status"}, osdLabels...),
|
2018-06-24 17:16:09 +00:00
|
|
|
labels,
|
|
|
|
),
|
2019-12-10 19:34:52 +00:00
|
|
|
|
2018-06-14 18:40:46 +00:00
|
|
|
ScrubbingStateDesc: prometheus.NewDesc(
|
|
|
|
fmt.Sprintf("%s_osd_scrub_state", cephNamespace),
|
|
|
|
"State of OSDs involved in a scrub",
|
2020-06-15 20:52:22 +00:00
|
|
|
osdLabels,
|
2018-06-14 18:40:46 +00:00
|
|
|
labels,
|
|
|
|
),
|
2019-12-10 19:34:52 +00:00
|
|
|
|
|
|
|
PGObjectsRecoveredDesc: prometheus.NewDesc(
|
|
|
|
fmt.Sprintf("%s_pg_objects_recovered", cephNamespace),
|
|
|
|
"Number of objects recovered in a PG",
|
|
|
|
[]string{"pgid"},
|
|
|
|
labels,
|
|
|
|
),
|
2020-06-15 20:52:22 +00:00
|
|
|
|
|
|
|
OSDObjectsBackfilled: prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: cephNamespace,
|
|
|
|
Name: "osd_objects_backfilled",
|
|
|
|
Help: "Average number of objects backfilled in an OSD",
|
|
|
|
ConstLabels: labels,
|
|
|
|
},
|
|
|
|
append([]string{"pgid"}, osdLabels...),
|
|
|
|
),
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) collectorList() []prometheus.Collector {
|
2016-07-14 05:01:19 +00:00
|
|
|
return []prometheus.Collector{
|
|
|
|
o.CrushWeight,
|
|
|
|
o.Depth,
|
|
|
|
o.Reweight,
|
2016-07-27 09:48:54 +00:00
|
|
|
o.Bytes,
|
|
|
|
o.UsedBytes,
|
|
|
|
o.AvailBytes,
|
2016-07-14 05:01:19 +00:00
|
|
|
o.Utilization,
|
2016-10-19 09:45:05 +00:00
|
|
|
o.Variance,
|
2016-07-14 05:01:19 +00:00
|
|
|
o.Pgs,
|
2016-07-27 09:48:54 +00:00
|
|
|
o.TotalBytes,
|
|
|
|
o.TotalUsedBytes,
|
|
|
|
o.TotalAvailBytes,
|
2016-07-14 05:01:19 +00:00
|
|
|
o.AverageUtil,
|
|
|
|
o.CommitLatency,
|
|
|
|
o.ApplyLatency,
|
2016-07-29 03:04:55 +00:00
|
|
|
o.OSDIn,
|
|
|
|
o.OSDUp,
|
2019-05-28 16:42:01 +00:00
|
|
|
o.OSDFull,
|
|
|
|
o.OSDNearFull,
|
|
|
|
o.OSDBackfillFull,
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDObjectsBackfilled,
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
type cephOSDDF struct {
|
|
|
|
OSDNodes []struct {
|
2016-07-14 05:01:19 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
CrushWeight json.Number `json:"crush_weight"`
|
|
|
|
Depth json.Number `json:"depth"`
|
|
|
|
Reweight json.Number `json:"reweight"`
|
|
|
|
KB json.Number `json:"kb"`
|
|
|
|
UsedKB json.Number `json:"kb_used"`
|
|
|
|
AvailKB json.Number `json:"kb_avail"`
|
|
|
|
Utilization json.Number `json:"utilization"`
|
2016-10-19 09:45:05 +00:00
|
|
|
Variance json.Number `json:"var"`
|
2016-07-14 05:01:19 +00:00
|
|
|
Pgs json.Number `json:"pgs"`
|
|
|
|
} `json:"nodes"`
|
|
|
|
|
|
|
|
Summary struct {
|
|
|
|
TotalKB json.Number `json:"total_kb"`
|
|
|
|
TotalUsedKB json.Number `json:"total_kb_used"`
|
|
|
|
TotalAvailKB json.Number `json:"total_kb_avail"`
|
|
|
|
AverageUtil json.Number `json:"average_utilization"`
|
|
|
|
} `json:"summary"`
|
|
|
|
}
|
|
|
|
|
2020-04-20 20:43:45 +00:00
|
|
|
type cephPerfStat struct {
|
2016-07-14 05:01:19 +00:00
|
|
|
PerfInfo []struct {
|
2016-07-27 09:48:54 +00:00
|
|
|
ID json.Number `json:"id"`
|
2016-07-14 05:01:19 +00:00
|
|
|
Stats struct {
|
|
|
|
CommitLatency json.Number `json:"commit_latency_ms"`
|
|
|
|
ApplyLatency json.Number `json:"apply_latency_ms"`
|
|
|
|
} `json:"perf_stats"`
|
|
|
|
} `json:"osd_perf_infos"`
|
|
|
|
}
|
|
|
|
|
2020-04-20 20:43:45 +00:00
|
|
|
type CephOSDPerfStat struct {
|
|
|
|
cephPerfStat `json:"osdstats"`
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
type cephOSDDump struct {
|
|
|
|
OSDs []struct {
|
2019-05-28 16:42:01 +00:00
|
|
|
OSD json.Number `json:"osd"`
|
|
|
|
Up json.Number `json:"up"`
|
|
|
|
In json.Number `json:"in"`
|
|
|
|
State []string `json:"state"`
|
2016-07-14 05:01:19 +00:00
|
|
|
} `json:"osds"`
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
type cephOSDTree struct {
|
|
|
|
Nodes []struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Class string `json:"device_class"`
|
|
|
|
CrushWeight float64 `json:"crush_weight"`
|
|
|
|
Children []int64 `json:"children"`
|
|
|
|
} `json:"nodes"`
|
|
|
|
Stray []struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
CrushWeight float64 `json:"crush_weight"`
|
|
|
|
Children []int `json:"children"`
|
|
|
|
} `json:"stray"`
|
|
|
|
}
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
type cephOSDTreeDown struct {
|
|
|
|
Nodes []struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
} `json:"nodes"`
|
|
|
|
Stray []struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
} `json:"stray"`
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
type cephPGDumpBrief struct {
|
|
|
|
PGStats []struct {
|
|
|
|
PGID string `json:"pgid"`
|
|
|
|
ActingPrimary int64 `json:"acting_primary"`
|
|
|
|
Acting []int `json:"acting"`
|
|
|
|
State string `json:"state"`
|
|
|
|
} `json:"pg_stats"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type cephPGQuery struct {
|
|
|
|
State string `json:"state"`
|
|
|
|
Info struct {
|
|
|
|
Stats struct {
|
|
|
|
StatSum struct {
|
|
|
|
NumObjectsRecovered int64 `json:"num_objects_recovered"`
|
|
|
|
} `json:"stat_sum"`
|
|
|
|
} `json:"stats"`
|
2020-06-12 21:26:49 +00:00
|
|
|
} `json:"info"`
|
2019-12-10 19:34:52 +00:00
|
|
|
RecoveryState []struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
EnterTime string `json:"enter_time"`
|
|
|
|
RecoverProgress *struct {
|
|
|
|
BackfillTargets []string `json:"backfill_targets"`
|
|
|
|
} `json:"recovery_progress"`
|
|
|
|
} `json:"recovery_state"`
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
type cephOSDLabel struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
DeviceClass string `json:"device_class"`
|
|
|
|
CrushWeight float64 `json:"crush_weight"`
|
|
|
|
Root string `json:"host"`
|
|
|
|
Rack string `json:"rack"`
|
|
|
|
Host string `json:"host"`
|
|
|
|
parent int64 // parent id when building tables
|
|
|
|
}
|
|
|
|
|
|
|
|
// backfillTargets returns a map from PG query result containing OSDs and
|
|
|
|
// corresponding shards that are being backfilled.
|
|
|
|
func (c cephPGQuery) backfillTargets() map[int64]int64 {
|
|
|
|
osdRegExp := regexp.MustCompile(`^(\d+)\((\d+)\)$`)
|
|
|
|
targets := make(map[int64]int64)
|
|
|
|
|
|
|
|
for _, state := range c.RecoveryState {
|
|
|
|
if state.RecoverProgress == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, osd := range state.RecoverProgress.BackfillTargets {
|
|
|
|
m := osdRegExp.FindStringSubmatch(osd)
|
|
|
|
if m == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
osdID, err := strconv.ParseInt(m[1], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
shard, err := strconv.ParseInt(m[2], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
targets[osdID] = shard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return targets
|
|
|
|
}
|
2019-12-10 19:34:52 +00:00
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
func (o *OSDCollector) collectOSDDF() error {
|
2016-07-29 03:04:55 +00:00
|
|
|
cmd := o.cephOSDDFCommand()
|
2016-07-15 09:37:38 +00:00
|
|
|
|
2016-07-14 05:01:19 +00:00
|
|
|
buf, _, err := o.conn.MonCommand(cmd)
|
2016-07-15 09:37:38 +00:00
|
|
|
if err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
2016-07-15 09:37:38 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// Workaround for Ceph Jewel after 10.2.5 produces invalid json when OSD is out
|
2017-04-21 01:32:37 +00:00
|
|
|
buf = bytes.Replace(buf, []byte("-nan"), []byte("0"), -1)
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
osdDF := &cephOSDDF{}
|
|
|
|
if err := json.Unmarshal(buf, osdDF); err != nil {
|
2016-07-14 05:01:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
for _, node := range osdDF.OSDNodes {
|
2020-06-15 20:52:22 +00:00
|
|
|
lb := o.getOSDLabelFromName(node.Name)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
crushWeight, err := node.CrushWeight.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.CrushWeight.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(crushWeight)
|
2016-07-14 05:01:19 +00:00
|
|
|
depth, err := node.Depth.Float64()
|
|
|
|
if err != nil {
|
2016-07-15 09:37:38 +00:00
|
|
|
|
2016-07-14 05:01:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Depth.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(depth)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
reweight, err := node.Reweight.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Reweight.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(reweight)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
osdKB, err := node.KB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Bytes.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(osdKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
usedKB, err := node.UsedKB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.UsedBytes.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(usedKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
availKB, err := node.AvailKB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.AvailBytes.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(availKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
util, err := node.Utilization.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Utilization.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(util)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-10-19 09:45:05 +00:00
|
|
|
variance, err := node.Variance.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Variance.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(variance)
|
2016-10-19 09:45:05 +00:00
|
|
|
|
2016-07-14 05:01:19 +00:00
|
|
|
pgs, err := node.Pgs.Float64()
|
|
|
|
if err != nil {
|
2016-07-21 09:30:58 +00:00
|
|
|
continue
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.Pgs.WithLabelValues(node.Name, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(pgs)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
totalKB, err := osdDF.Summary.TotalKB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
2016-07-15 09:37:38 +00:00
|
|
|
return err
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
o.TotalBytes.Set(totalKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
totalUsedKB, err := osdDF.Summary.TotalUsedKB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
o.TotalUsedBytes.Set(totalUsedKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
totalAvailKB, err := osdDF.Summary.TotalAvailKB.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-27 09:48:54 +00:00
|
|
|
o.TotalAvailBytes.Set(totalAvailKB * 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
averageUtil, err := osdDF.Summary.AverageUtil.Float64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
2016-07-15 09:37:38 +00:00
|
|
|
return err
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
o.AverageUtil.Set(averageUtil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) collectOSDPerf() error {
|
2019-12-10 19:34:52 +00:00
|
|
|
cmd := o.cephOSDPerfCommand()
|
|
|
|
buf, _, err := o.conn.MonCommand(cmd)
|
2016-07-15 09:37:38 +00:00
|
|
|
if err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
2016-07-15 09:37:38 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2020-04-20 20:43:45 +00:00
|
|
|
osdPerf := &CephOSDPerfStat{}
|
2016-07-14 05:01:19 +00:00
|
|
|
if err := json.Unmarshal(buf, osdPerf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, perfStat := range osdPerf.PerfInfo {
|
2016-07-27 09:48:54 +00:00
|
|
|
osdID, err := perfStat.ID.Int64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-06-14 18:40:46 +00:00
|
|
|
osdName := fmt.Sprintf(osdLabelFormat, osdID)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
lb := o.getOSDLabelFromID(osdID)
|
|
|
|
|
2016-07-14 05:01:19 +00:00
|
|
|
commitLatency, err := perfStat.Stats.CommitLatency.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-15 20:52:22 +00:00
|
|
|
o.CommitLatency.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(commitLatency / 1e3)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
applyLatency, err := perfStat.Stats.ApplyLatency.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-15 20:52:22 +00:00
|
|
|
o.ApplyLatency.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(applyLatency / 1e3)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildOSDLabels(data []byte) (map[int64]*cephOSDLabel, error) {
|
|
|
|
nodeList := &cephOSDTree{}
|
|
|
|
if err := json.Unmarshal(data, nodeList); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeMap := make(map[int64]*cephOSDLabel)
|
|
|
|
for _, node := range nodeList.Nodes {
|
|
|
|
label := cephOSDLabel{
|
|
|
|
ID: node.ID,
|
|
|
|
Name: node.Name,
|
|
|
|
Type: node.Type,
|
|
|
|
Status: node.Status,
|
|
|
|
DeviceClass: node.Class,
|
|
|
|
CrushWeight: node.CrushWeight,
|
|
|
|
parent: math.MaxInt64,
|
|
|
|
}
|
|
|
|
nodeMap[node.ID] = &label
|
|
|
|
}
|
|
|
|
// now that we built a lookup table, fill in the parents
|
|
|
|
for _, node := range nodeList.Nodes {
|
|
|
|
for _, child := range node.Children {
|
|
|
|
if label, ok := nodeMap[child]; ok {
|
|
|
|
label.parent = node.ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var findParent func(from *cephOSDLabel, kind string) (*cephOSDLabel, bool)
|
|
|
|
findParent = func(from *cephOSDLabel, kind string) (*cephOSDLabel, bool) {
|
|
|
|
if parent, ok := nodeMap[from.parent]; ok {
|
|
|
|
if parent.Type == kind {
|
|
|
|
return parent, true
|
|
|
|
}
|
|
|
|
return findParent(parent, kind)
|
|
|
|
}
|
|
|
|
return nil, false
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
// Now that we have parents filled in walk our map, and build a map of just osds.
|
|
|
|
for k := range nodeMap {
|
|
|
|
osdLabel := nodeMap[k]
|
|
|
|
if host, ok := findParent(osdLabel, "host"); ok {
|
|
|
|
osdLabel.Host = host.Name
|
|
|
|
}
|
|
|
|
if rack, ok := findParent(osdLabel, "rack"); ok {
|
|
|
|
osdLabel.Rack = rack.Name
|
|
|
|
}
|
|
|
|
if root, ok := findParent(osdLabel, "root"); ok {
|
|
|
|
osdLabel.Root = root.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range nodeMap {
|
|
|
|
osdLabel := nodeMap[k]
|
|
|
|
if osdLabel.Type != "osd" {
|
|
|
|
delete(nodeMap, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodeMap, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OSDCollector) buildOSDLabelCache() error {
|
|
|
|
cmd := o.cephOSDTreeCommand()
|
|
|
|
data, _, err := o.conn.MonCommand(cmd)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cache, err := buildOSDLabels(data)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed to decode OSD lables: %s", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
o.osdLabelsCache = cache
|
2016-07-14 05:01:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
func (o *OSDCollector) getOSDLabelFromID(id int64) *cephOSDLabel {
|
|
|
|
if label, ok := o.osdLabelsCache[id]; ok {
|
|
|
|
return label
|
|
|
|
}
|
|
|
|
return &cephOSDLabel{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OSDCollector) getOSDLabelFromName(osdid string) *cephOSDLabel {
|
|
|
|
var id int64
|
|
|
|
c, err := fmt.Sscanf(osdid, "osd.%d", &id)
|
|
|
|
if err != nil || c != 1 {
|
|
|
|
return &cephOSDLabel{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return o.getOSDLabelFromID(id)
|
|
|
|
}
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
func (o *OSDCollector) collectOSDTreeDown(ch chan<- prometheus.Metric) error {
|
2019-12-10 19:34:52 +00:00
|
|
|
cmd := o.cephOSDTreeCommand("down")
|
|
|
|
buff, _, err := o.conn.MonCommand(cmd)
|
2018-06-24 17:16:09 +00:00
|
|
|
if err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
2018-06-24 17:16:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
osdDown := &cephOSDTreeDown{}
|
|
|
|
if err := json.Unmarshal(buff, osdDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
downItems := append(osdDown.Nodes, osdDown.Stray...)
|
|
|
|
|
|
|
|
for _, downItem := range downItems {
|
|
|
|
if downItem.Type != "osd" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
osdName := downItem.Name
|
2020-06-15 20:52:22 +00:00
|
|
|
lb := o.getOSDLabelFromName(osdName)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(o.OSDDownDesc, prometheus.GaugeValue, 1,
|
|
|
|
downItem.Status,
|
|
|
|
osdName,
|
|
|
|
lb.DeviceClass,
|
|
|
|
lb.Host,
|
|
|
|
lb.Root,
|
|
|
|
lb.Rack)
|
2018-06-24 17:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) collectOSDDump() error {
|
2019-12-10 19:34:52 +00:00
|
|
|
cmd := o.cephOSDDump()
|
|
|
|
buff, _, err := o.conn.MonCommand(cmd)
|
2016-07-15 09:37:38 +00:00
|
|
|
if err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
2016-07-15 09:37:38 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-07-14 05:01:19 +00:00
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
osdDump := cephOSDDump{}
|
|
|
|
if err := json.Unmarshal(buff, &osdDump); err != nil {
|
2016-07-14 05:01:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
for _, dumpInfo := range osdDump.OSDs {
|
|
|
|
osdID, err := dumpInfo.OSD.Int64()
|
2016-07-14 05:01:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-06-14 18:40:46 +00:00
|
|
|
osdName := fmt.Sprintf(osdLabelFormat, osdID)
|
2020-06-15 20:52:22 +00:00
|
|
|
lb := o.getOSDLabelFromID(osdID)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
in, err := dumpInfo.In.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDIn.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(in)
|
2016-07-14 05:01:19 +00:00
|
|
|
|
|
|
|
up, err := dumpInfo.Up.Float64()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDUp.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(up)
|
2019-05-28 16:42:01 +00:00
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(0)
|
|
|
|
o.OSDNearFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(0)
|
|
|
|
o.OSDBackfillFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(0)
|
2019-05-28 16:42:01 +00:00
|
|
|
for _, state := range dumpInfo.State {
|
|
|
|
switch state {
|
|
|
|
case "full":
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(1)
|
2019-05-28 16:42:01 +00:00
|
|
|
case "nearfull":
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDNearFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(1)
|
2019-05-28 16:42:01 +00:00
|
|
|
case "backfillfull":
|
2020-06-15 20:52:22 +00:00
|
|
|
o.OSDBackfillFull.WithLabelValues(osdName, lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Set(1)
|
2019-05-28 16:42:01 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
func (o *OSDCollector) performPGDumpBrief() error {
|
2018-06-14 18:40:46 +00:00
|
|
|
cmd := o.cephPGDumpCommand()
|
|
|
|
buf, _, err := o.conn.MonCommand(cmd)
|
|
|
|
if err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Printf("failed sending Mon command %s: %s", cmd, err)
|
2018-06-14 18:40:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
o.pgDumpBrief = cephPGDumpBrief{}
|
|
|
|
if err := json.Unmarshal(buf, &o.pgDumpBrief); err != nil {
|
2018-06-14 18:40:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OSDCollector) performPGQuery(pgid string) (*cephPGQuery, error) {
|
|
|
|
cmd := o.cephPGQueryCommand(pgid)
|
|
|
|
buf, _, err := o.conn.PGCommand([]byte(pgid), cmd)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("failed sending PG command %s: %s", cmd, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pgQuery := cephPGQuery{}
|
|
|
|
if err := json.Unmarshal(buf, &pgQuery); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pgQuery, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *OSDCollector) collectOSDScrubState(ch chan<- prometheus.Metric) error {
|
|
|
|
// need to reset the PG scrub state since the scrub might have ended within
|
|
|
|
// the last prom scrape interval.
|
|
|
|
// This forces us to report scrub state on all previously discovered OSDs We
|
|
|
|
// may be able to remove the "cache" when using Prometheus 2.0 if we can
|
|
|
|
// tune how unreported/abandoned gauges are treated (ie set to 0).
|
2018-06-14 18:40:46 +00:00
|
|
|
for i := range o.osdScrubCache {
|
|
|
|
o.osdScrubCache[i] = scrubStateIdle
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
for _, pg := range o.pgDumpBrief.PGStats {
|
2018-06-14 18:40:46 +00:00
|
|
|
if strings.Contains(pg.State, "scrubbing") {
|
|
|
|
scrubState := scrubStateScrubbing
|
|
|
|
if strings.Contains(pg.State, "deep") {
|
|
|
|
scrubState = scrubStateDeepScrubbing
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, osd := range pg.Acting {
|
|
|
|
o.osdScrubCache[osd] = scrubState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, v := range o.osdScrubCache {
|
2020-06-15 20:52:22 +00:00
|
|
|
lb := o.getOSDLabelFromID(int64(i))
|
2018-06-14 18:40:46 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
o.ScrubbingStateDesc,
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(v),
|
2020-06-15 20:52:22 +00:00
|
|
|
fmt.Sprintf(osdLabelFormat, i),
|
|
|
|
lb.DeviceClass,
|
|
|
|
lb.Host,
|
|
|
|
lb.Root,
|
|
|
|
lb.Root)
|
2018-06-14 18:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
func (o *OSDCollector) collectPGRecoveryState(ch chan<- prometheus.Metric) error {
|
|
|
|
for _, pg := range o.pgDumpBrief.PGStats {
|
2020-06-15 20:52:22 +00:00
|
|
|
|
|
|
|
// We need previous PG state in order to update the metric when a PG has
|
|
|
|
// completed recovery or backfill. Or it could be an empty string if
|
|
|
|
// unknown.
|
|
|
|
prevPGState, prevPGStateFound := o.pgStateCache[pg.PGID]
|
|
|
|
prevNumObjectsRecovered := o.pgObjectsRecoveredCache[pg.PGID]
|
|
|
|
prevBackfillTargets := o.pgBackfillTargetsCache[pg.PGID]
|
|
|
|
|
|
|
|
if !prevPGStateFound || strings.Contains(prevPGState, "recovering") || strings.Contains(pg.State, "recovering") ||
|
|
|
|
strings.Contains(prevPGState, "backfilling") || strings.Contains(pg.State, "backfilling") {
|
2019-12-10 19:34:52 +00:00
|
|
|
query, err := o.performPGQuery(pg.PGID)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
o.pgStateCache[pg.PGID] = pg.State
|
2019-12-10 19:34:52 +00:00
|
|
|
o.pgObjectsRecoveredCache[pg.PGID] = query.Info.Stats.StatSum.NumObjectsRecovered
|
2020-06-15 20:52:22 +00:00
|
|
|
o.pgBackfillTargetsCache[pg.PGID] = query.backfillTargets()
|
|
|
|
|
|
|
|
// There is no previous backfill_targets, and we have just cached
|
|
|
|
// it. Wait for the next time so that we can know the increased
|
|
|
|
// number of objects backfilled for this entire PG and compute the
|
|
|
|
// average increased number of objects backfilled for each OSD in
|
|
|
|
// the backfill_targets.
|
|
|
|
if prevBackfillTargets == nil || len(prevBackfillTargets) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Average out the total number of objects backfilled to each OSD
|
|
|
|
// The average number rounds to the nearest integer, rounding half
|
|
|
|
// away from zero.
|
|
|
|
eachOSDIncrease := math.Round(float64(o.pgObjectsRecoveredCache[pg.PGID]-prevNumObjectsRecovered) / float64(len(prevBackfillTargets)))
|
|
|
|
|
|
|
|
for osdID := range prevBackfillTargets {
|
|
|
|
lb := o.getOSDLabelFromID(osdID)
|
|
|
|
// It is possible that osdID has gone from the backfill_targets
|
|
|
|
// this time if backfill has completed on it. In this case we
|
|
|
|
// still count the increase to this OSD.
|
|
|
|
o.OSDObjectsBackfilled.WithLabelValues(pg.PGID, fmt.Sprintf(osdLabelFormat, osdID), lb.DeviceClass, lb.Host, lb.Rack, lb.Root).Add(eachOSDIncrease)
|
|
|
|
}
|
2019-12-10 19:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
for pgid, v := range o.pgObjectsRecoveredCache {
|
2019-12-10 19:34:52 +00:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
o.PGObjectsRecoveredDesc,
|
|
|
|
prometheus.GaugeValue,
|
2020-06-15 20:52:22 +00:00
|
|
|
float64(v),
|
2019-12-10 19:34:52 +00:00
|
|
|
pgid)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) cephOSDDump() []byte {
|
2016-07-14 05:01:19 +00:00
|
|
|
cmd, err := json.Marshal(map[string]interface{}{
|
|
|
|
"prefix": "osd dump",
|
2019-12-10 19:34:52 +00:00
|
|
|
"format": jsonFormat,
|
2016-07-14 05:01:19 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) cephOSDDFCommand() []byte {
|
2016-07-14 05:01:19 +00:00
|
|
|
cmd, err := json.Marshal(map[string]interface{}{
|
|
|
|
"prefix": "osd df",
|
2019-12-10 19:34:52 +00:00
|
|
|
"format": jsonFormat,
|
2016-07-14 05:01:19 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2016-07-20 12:16:11 +00:00
|
|
|
panic(err)
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
2016-07-20 12:16:11 +00:00
|
|
|
return cmd
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) cephOSDPerfCommand() []byte {
|
2016-07-14 05:01:19 +00:00
|
|
|
cmd, err := json.Marshal(map[string]interface{}{
|
|
|
|
"prefix": "osd perf",
|
2019-12-10 19:34:52 +00:00
|
|
|
"format": jsonFormat,
|
2016-07-14 05:01:19 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
func (o *OSDCollector) cephOSDTreeCommand(states ...string) []byte {
|
2020-06-15 20:52:22 +00:00
|
|
|
req := map[string]interface{}{
|
2018-06-24 17:16:09 +00:00
|
|
|
"prefix": "osd tree",
|
2019-12-10 19:34:52 +00:00
|
|
|
"format": jsonFormat,
|
2020-06-15 20:52:22 +00:00
|
|
|
}
|
|
|
|
if len(states) > 0 {
|
|
|
|
req["states"] = states
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd, err := json.Marshal(req)
|
2018-06-24 17:16:09 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-06-14 18:40:46 +00:00
|
|
|
func (o *OSDCollector) cephPGDumpCommand() []byte {
|
|
|
|
cmd, err := json.Marshal(map[string]interface{}{
|
|
|
|
"prefix": "pg dump",
|
|
|
|
"dumpcontents": []string{"pgs_brief"},
|
|
|
|
"format": jsonFormat,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
func (o *OSDCollector) cephPGQueryCommand(pgid string) []byte {
|
|
|
|
cmd, err := json.Marshal(map[string]interface{}{
|
|
|
|
"prefix": "query",
|
|
|
|
"pgid": pgid,
|
|
|
|
"format": jsonFormat,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Describe sends the descriptors of each OSDCollector related metrics we have
|
|
|
|
// defined to the provided Prometheus channel.
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) Describe(ch chan<- *prometheus.Desc) {
|
2016-07-14 05:01:19 +00:00
|
|
|
for _, metric := range o.collectorList() {
|
|
|
|
metric.Describe(ch)
|
|
|
|
}
|
2019-12-10 19:34:52 +00:00
|
|
|
ch <- o.OSDDownDesc
|
2018-06-14 18:40:46 +00:00
|
|
|
ch <- o.ScrubbingStateDesc
|
2019-12-10 19:34:52 +00:00
|
|
|
ch <- o.PGObjectsRecoveredDesc
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
// Collect sends all the collected metrics to the provided Prometheus channel.
|
2016-07-27 09:48:54 +00:00
|
|
|
// It requires the caller to handle synchronization.
|
2016-07-29 03:04:55 +00:00
|
|
|
func (o *OSDCollector) Collect(ch chan<- prometheus.Metric) {
|
2018-09-13 12:12:15 +00:00
|
|
|
|
2019-05-28 16:42:01 +00:00
|
|
|
// Reset daemon specifc metrics; daemons can leave the cluster
|
|
|
|
o.CrushWeight.Reset()
|
|
|
|
o.Depth.Reset()
|
|
|
|
o.Reweight.Reset()
|
|
|
|
o.Bytes.Reset()
|
|
|
|
o.UsedBytes.Reset()
|
|
|
|
o.AvailBytes.Reset()
|
|
|
|
o.Utilization.Reset()
|
|
|
|
o.Variance.Reset()
|
|
|
|
o.Pgs.Reset()
|
|
|
|
o.CommitLatency.Reset()
|
|
|
|
o.ApplyLatency.Reset()
|
|
|
|
o.OSDIn.Reset()
|
|
|
|
o.OSDUp.Reset()
|
2020-06-15 20:52:22 +00:00
|
|
|
o.buildOSDLabelCache()
|
2018-09-13 12:12:15 +00:00
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
if err := o.collectOSDPerf(); err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Println("failed collecting OSD perf metrics:", err)
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 03:04:55 +00:00
|
|
|
if err := o.collectOSDDump(); err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Println("failed collecting OSD dump metrics:", err)
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 17:16:09 +00:00
|
|
|
if err := o.collectOSDDF(); err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Println("failed collecting OSD df metrics:", err)
|
2018-06-24 17:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := o.collectOSDTreeDown(ch); err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Println("failed collecting OSD tree down metrics:", err)
|
2016-07-15 09:37:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:34:52 +00:00
|
|
|
if err := o.performPGDumpBrief(); err != nil {
|
|
|
|
log.Println("failed performing PG dump brief:", err)
|
|
|
|
}
|
|
|
|
|
2018-06-14 18:40:46 +00:00
|
|
|
if err := o.collectOSDScrubState(ch); err != nil {
|
2019-12-10 19:34:52 +00:00
|
|
|
log.Println("failed collecting OSD scrub metrics:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := o.collectPGRecoveryState(ch); err != nil {
|
|
|
|
log.Println("failed collecting PG recovery metrics:", err)
|
|
|
|
}
|
|
|
|
|
2020-06-15 20:52:22 +00:00
|
|
|
for _, metric := range o.collectorList() {
|
|
|
|
metric.Collect(ch)
|
2018-06-14 18:40:46 +00:00
|
|
|
}
|
2016-07-14 05:01:19 +00:00
|
|
|
}
|