From bc09387c9ab9b323504d36425076434f0ae6b993 Mon Sep 17 00:00:00 2001 From: Marvin Date: Tue, 17 Mar 2020 13:50:41 -0500 Subject: [PATCH] new metric for tracking which node a volume is on (#12) * new metric for tracking which node a volume is on --- pkg/prom/collector.go | 11 +++++++++++ pkg/prom/metrics.go | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/prom/collector.go b/pkg/prom/collector.go index 61af1da..f7ba293 100644 --- a/pkg/prom/collector.go +++ b/pkg/prom/collector.go @@ -163,6 +163,7 @@ func (c *solidfireCollector) Describe(ch chan<- *prometheus.Desc) { ch <- MetricDescriptions.ListDrivesCapacity ch <- MetricDescriptions.NodeISCSISessionsTotal + ch <- MetricDescriptions.NodeISCSIVolumes } func (c *solidfireCollector) Collect(ch chan<- prometheus.Metric) { @@ -1186,6 +1187,7 @@ func (c *solidfireCollector) Collect(ch chan<- prometheus.Metric) { for node, v := range sessions { for vol, val := range v { + ch <- prometheus.MustNewConstMetric( MetricDescriptions.NodeISCSISessionsTotal, prometheus.GaugeValue, @@ -1195,6 +1197,15 @@ func (c *solidfireCollector) Collect(ch chan<- prometheus.Metric) { strconv.Itoa(vol), volumeNamesByID[vol], ) + + ch <- prometheus.MustNewConstMetric( + MetricDescriptions.NodeISCSIVolumes, + prometheus.GaugeValue, + float64(node), + strconv.Itoa(vol), + volumeNamesByID[vol], + ) + } } diff --git a/pkg/prom/metrics.go b/pkg/prom/metrics.go index 2ae6f2e..54aadbb 100644 --- a/pkg/prom/metrics.go +++ b/pkg/prom/metrics.go @@ -144,6 +144,7 @@ type Descriptions struct { ListDrivesCapacity *prometheus.Desc NodeISCSISessionsTotal *prometheus.Desc + NodeISCSIVolumes *prometheus.Desc } func NewMetricDescriptions(namespace string) *Descriptions { @@ -957,5 +958,12 @@ func NewMetricDescriptions(namespace string) *Descriptions { nil, ) + d.NodeISCSIVolumes = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "volume_node_id"), + "The node id where the volume is hosted.", + []string{"volume_id", "volume_name"}, + nil, + ) + return &d }