From c8e1779ba32185fd52e0d452ba6243f4ebc0cb44 Mon Sep 17 00:00:00 2001 From: Marvin Date: Thu, 12 Mar 2020 16:12:38 -0500 Subject: [PATCH] refactor list_drives metrics (#9) * refactor list_drives metrics --- pkg/prom/collector.go | 85 +++++++++++++----------------------------- pkg/prom/metrics.go | 28 +++++--------- pkg/solidfire/types.go | 6 +-- 3 files changed, 38 insertions(+), 81 deletions(-) diff --git a/pkg/prom/collector.go b/pkg/prom/collector.go index 1ecd24a..b00545a 100644 --- a/pkg/prom/collector.go +++ b/pkg/prom/collector.go @@ -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) { @@ -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 diff --git a/pkg/prom/metrics.go b/pkg/prom/metrics.go index 6903c26..759b7e5 100644 --- a/pkg/prom/metrics.go +++ b/pkg/prom/metrics.go @@ -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 { @@ -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, ) diff --git a/pkg/solidfire/types.go b/pkg/solidfire/types.go index 3dc9fda..71efe23 100644 --- a/pkg/solidfire/types.go +++ b/pkg/solidfire/types.go @@ -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"`