Skip to content

Commit

Permalink
refactor list_drives metrics (#9)
Browse files Browse the repository at this point in the history
* refactor list_drives metrics
  • Loading branch information
mjavier2k authored Mar 12, 2020
1 parent 70f78c4 commit c8e1779
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 81 deletions.
85 changes: 25 additions & 60 deletions pkg/prom/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func (c *solidfireCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- MetricDescriptions.ClusterThresholdSumUsedClusterBytes
ch <- MetricDescriptions.ClusterThresholdSumUsedMetadataClusterBytes

ch <- MetricDescriptions.ListDrivesByStatusTotal
ch <- MetricDescriptions.ListDrivesByNodeTotal
ch <- MetricDescriptions.ListDrivesByTypeTotal
ch <- MetricDescriptions.ListDrivesStatus
ch <- MetricDescriptions.ListDrivesCapacity

}

func (c *solidfireCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -1155,67 +1155,32 @@ func (c *solidfireCollector) Collect(ch chan<- prometheus.Metric) {
log.Errorln(err)
}

driveStatus := make(map[int]map[string]float64)
driveTypes := make(map[int]map[string]float64)
driveNodes := make(map[int]float64)

for _, f := range ListDrives.Result.Drives {
if driveStatus[f.NodeID] == nil {
driveStatus[f.NodeID] = map[string]float64{
"available": 0,
"active": 0,
"erasing": 0,
"failed": 0,
"removing": 0,
}
}
if driveTypes[f.NodeID] == nil {
driveTypes[f.NodeID] = map[string]float64{
"volume": 0,
"block": 0,
"unknown": 0,
}
}

driveStatus[f.NodeID][f.Status]++
driveTypes[f.NodeID][f.Type]++
driveNodes[f.NodeID]++
}

for k, v := range driveNodes {
for _, d := range ListDrives.Result.Drives {
ch <- prometheus.MustNewConstMetric(
MetricDescriptions.ListDrivesByNodeTotal,
MetricDescriptions.ListDrivesStatus,
prometheus.GaugeValue,
v,
strconv.Itoa(k),
nodesNamesByID[k],
1,
strconv.Itoa(d.NodeID),
nodesNamesByID[d.NodeID],
strconv.Itoa(d.DriveID),
d.Serial,
strconv.Itoa(d.Slot),
d.Status,
d.Type,
)
}

for n, s := range driveStatus {
for k, v := range s {
ch <- prometheus.MustNewConstMetric(
MetricDescriptions.ListDrivesByStatusTotal,
prometheus.GaugeValue,
v,
strconv.Itoa(n),
nodesNamesByID[n],
k,
)
}
}

for n, t := range driveTypes {
for k, v := range t {
ch <- prometheus.MustNewConstMetric(
MetricDescriptions.ListDrivesByTypeTotal,
prometheus.GaugeValue,
v,
strconv.Itoa(n),
nodesNamesByID[n],
k,
)
}
ch <- prometheus.MustNewConstMetric(
MetricDescriptions.ListDrivesCapacity,
prometheus.GaugeValue,
d.Capacity,
strconv.Itoa(d.NodeID),
nodesNamesByID[d.NodeID],
strconv.Itoa(d.DriveID),
d.Serial,
strconv.Itoa(d.Slot),
d.Status,
d.Type,
)
}

// Set scrape success metric to scrapeSuccess
Expand Down
28 changes: 10 additions & 18 deletions pkg/prom/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ type Descriptions struct {
ClusterThresholdSumUsedClusterBytes *prometheus.Desc
ClusterThresholdSumUsedMetadataClusterBytes *prometheus.Desc

ListDrivesByStatusTotal *prometheus.Desc
ListDrivesByNodeTotal *prometheus.Desc
ListDrivesByTypeTotal *prometheus.Desc
ListDrivesStatus *prometheus.Desc
ListDrivesCapacity *prometheus.Desc
}

func NewMetricDescriptions(namespace string) *Descriptions {
Expand Down Expand Up @@ -959,24 +958,17 @@ func NewMetricDescriptions(namespace string) *Descriptions {
nil,
)

d.ListDrivesByStatusTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "list_drives_by_status_count"),
"Number of drives per node and status",
[]string{"node_id", "node_name", "status"},
d.ListDrivesStatus = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "drives_status"),
"The drive status for each individual drives in the cluster's active nodes",
[]string{"node_id", "node_name", "drive_id", "serial", "slot", "status", "type"},
nil,
)

d.ListDrivesByNodeTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "list_drives_by_node_total"),
"Total number of drives per node",
[]string{"node_id", "node_name"},
nil,
)

d.ListDrivesByTypeTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "list_drives_by_type_count"),
"Number of drives per node and type",
[]string{"node_id", "node_name", "type"},
d.ListDrivesCapacity = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "drives_capacity"),
"The drive capacity for each individual drives in the cluster's active nodes",
[]string{"node_id", "node_name", "drive_id", "serial", "slot", "status", "type"},
nil,
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/solidfire/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ type ListDrivesResponse struct {
Drives []struct {
Attributes struct {
} `json:"attributes"`
Capacity int64 `json:"capacity"`
DriveID float64 `json:"driveID"`
Capacity float64 `json:"capacity"`
DriveID int `json:"driveID"`
NodeID int `json:"nodeID"`
Serial string `json:"serial"`
Slot float64 `json:"slot"`
Slot int `json:"slot"`
Status string `json:"status"`
Type string `json:"type"`
} `json:"drives"`
Expand Down

0 comments on commit c8e1779

Please sign in to comment.