Skip to content

Commit fb24f00

Browse files
Value conversion & 4 nodes cluster support (#3)
* Support for more than 2 nodes cluster (HyperSwap...) * Parsing total_drive_raw_capacity_bytes as a Bytes string or as a Float --------- Co-authored-by: Charles <[email protected]>
1 parent 4e6177a commit fb24f00

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

collector/node_stats_collector.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,14 @@ func (c *nodeStatsCollector) Collect(sClient utils.SpectrumClient, ch chan<- pro
169169
// ]
170170

171171
nodeStatsArray := gjson.Parse(nodeStatsResp).Array()
172+
nodesNumber := len(nodeStatsArray) / len(nodeStats_metrics)
173+
172174
for i, nodeStats_metric := range nodeStats_metrics {
173-
labelvalues := []string{sClient.Hostname, nodeStatsArray[i].Get("node_name").String()}
174-
labelvalues_a := []string{sClient.Hostname, nodeStatsArray[len(nodeStatsArray)-len(nodeStats_metrics)+i].Get("node_name").String()}
175-
if len(utils.ExtraLabelValues) > 0 {
176-
labelvalues = append(labelvalues, utils.ExtraLabelValues...)
177-
labelvalues_a = append(labelvalues_a, utils.ExtraLabelValues...)
175+
for node := 0; node < nodesNumber; node++ {
176+
index := len(nodeStats_metrics)*node + i
177+
labelvalues := []string{sClient.Hostname, nodeStatsArray[index].Get("node_name").String()}
178+
ch <- prometheus.MustNewConstMetric(nodeStats_metric, prometheus.GaugeValue, nodeStatsArray[index].Get("stat_current").Float(), labelvalues...)
178179
}
179-
ch <- prometheus.MustNewConstMetric(nodeStats_metric, prometheus.GaugeValue, nodeStatsArray[i].Get("stat_current").Float(), labelvalues...)
180-
ch <- prometheus.MustNewConstMetric(nodeStats_metric, prometheus.GaugeValue, nodeStatsArray[len(nodeStatsArray)-len(nodeStats_metrics)+i].Get("stat_current").Float(), labelvalues_a...)
181180
}
182181
logger.Debugln("exit NodeStats collector")
183182
return nil

collector/system_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ func (c *systemCollector) Collect(sClient utils.SpectrumClient, ch chan<- promet
304304
}
305305
ch <- prometheus.MustNewConstMetric(compression_uncompressed_capacity, prometheus.GaugeValue, float64(compression_uncompressed_capacity_bytes), labelvalues...)
306306

307-
total_drive_raw_capacity_bytes, err := strconv.ParseFloat(gjson.Get(systemMetrics, "total_drive_raw_capacity").String(), 64)
307+
total_drive_raw_capacity_bytes, err := utils.ToBytes(gjson.Get(systemMetrics, "total_drive_raw_capacity").String())
308308
if err != nil {
309-
logger.Errorf("Parsing string as float failed: %s", err.Error())
309+
logger.Errorf("Converting capacity unit failed: %s", err.Error())
310310
}
311311
ch <- prometheus.MustNewConstMetric(total_drive_raw_capacity, prometheus.GaugeValue, float64(total_drive_raw_capacity_bytes), labelvalues...)
312312

0 commit comments

Comments
 (0)