Skip to content

Commit e1e8f1c

Browse files
committed
lssystemstats collector update to support lssystemstats api update
1 parent c1422c1 commit e1e8f1c

File tree

1 file changed

+76
-62
lines changed

1 file changed

+76
-62
lines changed

collector/system_stats_collector.go

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525
const prefix_stats = "spectrum_systemstats_"
2626

2727
var (
28-
metrics [49]*prometheus.Desc
28+
metricsPromDescMap map[string]*prometheus.Desc
29+
metricsDescMap map[string]string
2930
)
3031

3132
type systemStatsCollector struct {
@@ -34,87 +35,99 @@ type systemStatsCollector struct {
3435
func init() {
3536
registerCollector("lssystemstats", defaultEnabled, NewSystemStatsCollector)
3637
}
37-
func NewSystemStatsCollector() (Collector, error) {
38-
labelnames := []string{"resource"}
39-
if len(utils.ExtraLabelNames) > 0 {
40-
labelnames = append(labelnames, utils.ExtraLabelNames...)
41-
}
42-
metrics = [49]*prometheus.Desc{
43-
prometheus.NewDesc(prefix_stats+"compression_cpu_pc", "The percentage of allocated CPU capacity that is used for compression.", labelnames, nil),
44-
prometheus.NewDesc(prefix_stats+"cpu_pc", "The percentage of allocated CPU capacity that is used for the system.", labelnames, nil),
4538

46-
prometheus.NewDesc(prefix_stats+"fc_mb", "The total number of megabytes transferred per second (MBps) for Fibre Channel traffic on the system. This value includes host I/O and any bandwidth that is used for communication within the system.", labelnames, nil),
47-
prometheus.NewDesc(prefix_stats+"fc_io", "The total input/output (I/O) operations that are transferred per seconds for Fibre Channel traffic on the system. This value includes host I/O and any bandwidth that is used for communication within the system.", labelnames, nil),
39+
func InitmetricsDescMap() {
40+
metricsDescMap = make(map[string]string)
41+
metricsDescMap["compression_cpu_pc"] = "The percentage of allocated CPU capacity that is used for compression."
42+
metricsDescMap["cpu_pc"] = "The percentage of allocated CPU capacity that is used for the system."
43+
44+
metricsDescMap["fc_mb"] = "The total number of megabytes transferred per second (MBps) for Fibre Channel traffic on the system. This value includes host I/O and any bandwidth that is used for communication within the system."
45+
metricsDescMap["fc_io"] = "The total input/output (I/O) operations that are transferred per seconds for Fibre Channel traffic on the system. This value includes host I/O and any bandwidth that is used for communication within the system."
46+
47+
metricsDescMap["sas_mb"] = "The total number of megabytes transferred per second (MBps) for serial-attached SCSI (SAS) traffic on the system. This value includes host I/O and bandwidth that is used for background RAID activity."
48+
metricsDescMap["sas_io"] = "The total I/O operations that are transferred per second for SAS traffic on the system. This value includes host I/O and bandwidth that is used for background RAID activity."
4849

49-
prometheus.NewDesc(prefix_stats+"sas_mb", "The total number of megabytes transferred per second (MBps) for serial-attached SCSI (SAS) traffic on the system. This value includes host I/O and bandwidth that is used for background RAID activity.", labelnames, nil),
50-
prometheus.NewDesc(prefix_stats+"sas_io", "The total I/O operations that are transferred per second for SAS traffic on the system. This value includes host I/O and bandwidth that is used for background RAID activity.", labelnames, nil),
50+
metricsDescMap["iscsi_mb"] = "The total number of megabytes transferred per second (MBps) for iSCSI traffic on the system."
51+
metricsDescMap["iscsi_io"] = "The total I/O operations that are transferred per second for iSCSI traffic on the system."
5152

52-
prometheus.NewDesc(prefix_stats+"iscsi_mb", "The total number of megabytes transferred per second (MBps) for iSCSI traffic on the system.", labelnames, nil),
53-
prometheus.NewDesc(prefix_stats+"iscsi_io", "The total I/O operations that are transferred per second for iSCSI traffic on the system.", labelnames, nil),
53+
metricsDescMap["write_cache_pc"] = "The percentage of the write cache usage for the node."
54+
metricsDescMap["total_cache_pc"] = "The total percentage for both the write and read cache usage for the node."
5455

55-
prometheus.NewDesc(prefix_stats+"write_cache_pc", "The percentage of the write cache usage for the node.", labelnames, nil),
56-
prometheus.NewDesc(prefix_stats+"total_cache_pc", "The total percentage for both the write and read cache usage for the node.", labelnames, nil),
56+
metricsDescMap["vdisk_mb"] = "The average number of megabytes transferred per second (MBps) for read and write operations to volumes during the sample period."
57+
metricsDescMap["vdisk_io"] = "The average number of I/O operations that are transferred per second for read and write operations to volumes during the sample period."
58+
metricsDescMap["vdisk_ms"] = "The average amount of time in milliseconds that the system takes to respond to read and write requests to volumes over the sample period."
5759

58-
prometheus.NewDesc(prefix_stats+"vdisk_mb", "The average number of megabytes transferred per second (MBps) for read and write operations to volumes during the sample period.", labelnames, nil),
59-
prometheus.NewDesc(prefix_stats+"vdisk_io", "The average number of I/O operations that are transferred per second for read and write operations to volumes during the sample period.", labelnames, nil),
60-
prometheus.NewDesc(prefix_stats+"vdisk_ms", "The average amount of time in milliseconds that the system takes to respond to read and write requests to volumes over the sample period.", labelnames, nil),
60+
metricsDescMap["mdisk_mb"] = "The average number of megabytes transferred per second (MBps) for read and write operations to MDisks during the sample period."
61+
metricsDescMap["mdisk_io"] = "The average number of I/O operations that are transferred per second for read and write operations to MDisks during the sample period."
62+
metricsDescMap["mdisk_ms"] = "The average amount of time in milliseconds that the system takes to respond to read and write requests to MDisks over the sample period."
6163

62-
prometheus.NewDesc(prefix_stats+"mdisk_mb", "The average number of megabytes transferred per second (MBps) for read and write operations to MDisks during the sample period.", labelnames, nil),
63-
prometheus.NewDesc(prefix_stats+"mdisk_io", "The average number of I/O operations that are transferred per second for read and write operations to MDisks during the sample period.", labelnames, nil),
64-
prometheus.NewDesc(prefix_stats+"mdisk_ms", "The average amount of time in milliseconds that the system takes to respond to read and write requests to MDisks over the sample period.", labelnames, nil),
64+
metricsDescMap["drive_mb"] = "The average number of megabytes transferred per second (MBps) for read and write operations to drives during the sample period."
65+
metricsDescMap["drive_io"] = "The average number of I/O operations that are transferred per second for read and write operations to drives during the sample period."
66+
metricsDescMap["drive_ms"] = "The average amount of time in milliseconds that the system takes to respond to read and write requests to drives over the sample period."
6567

66-
prometheus.NewDesc(prefix_stats+"drive_mb", "The average number of megabytes transferred per second (MBps) for read and write operations to drives during the sample period.", labelnames, nil),
67-
prometheus.NewDesc(prefix_stats+"drive_io", "The average number of I/O operations that are transferred per second for read and write operations to drives during the sample period.", labelnames, nil),
68-
prometheus.NewDesc(prefix_stats+"drive_ms", "The average amount of time in milliseconds that the system takes to respond to read and write requests to drives over the sample period.", labelnames, nil),
68+
metricsDescMap["vdisk_r_mb"] = "The average number of megabytes transferred per second (MBps) for read operations to volumes during the sample period."
69+
metricsDescMap["vdisk_r_io"] = "The average number of I/O operations that are transferred per second for read operations to volumes during the sample period."
70+
metricsDescMap["vdisk_r_ms"] = "The average amount of time in milliseconds that the system takes to respond to read requests to volumes over the sample period."
6971

70-
prometheus.NewDesc(prefix_stats+"vdisk_r_mb", "The average number of megabytes transferred per second (MBps) for read operations to volumes during the sample period.", labelnames, nil),
71-
prometheus.NewDesc(prefix_stats+"vdisk_r_io", "The average number of I/O operations that are transferred per second for read operations to volumes during the sample period.", labelnames, nil),
72-
prometheus.NewDesc(prefix_stats+"vdisk_r_ms", "The average amount of time in milliseconds that the system takes to respond to read requests to volumes over the sample period.", labelnames, nil),
72+
metricsDescMap["vdisk_w_mb"] = "The average number of megabytes transferred per second (MBps) for read and write operations to volumes during the sample period."
73+
metricsDescMap["vdisk_w_io"] = "The average number of I/O operations that are transferred per second for write operations to volumes during the sample period."
74+
metricsDescMap["vdisk_w_ms"] = "The average amount of time in milliseconds that the system takes to respond to write requests to volumes over the sample period."
7375

74-
prometheus.NewDesc(prefix_stats+"vdisk_w_mb", "The average number of megabytes transferred per second (MBps) for read and write operations to volumes during the sample period.", labelnames, nil),
75-
prometheus.NewDesc(prefix_stats+"vdisk_w_io", "The average number of I/O operations that are transferred per second for write operations to volumes during the sample period.", labelnames, nil),
76-
prometheus.NewDesc(prefix_stats+"vdisk_w_ms", "The average amount of time in milliseconds that the system takes to respond to write requests to volumes over the sample period.", labelnames, nil),
76+
metricsDescMap["mdisk_r_mb"] = "The average number of megabytes transferred per second (MBps) for read operations to MDisks during the sample period."
77+
metricsDescMap["mdisk_r_io"] = "The average number of I/O operations that are transferred per second for read operations to MDisks during the sample period."
78+
metricsDescMap["mdisk_r_ms"] = "The average amount of time in milliseconds that the system takes to respond to read requests to MDisks over the sample period."
7779

78-
prometheus.NewDesc(prefix_stats+"mdisk_r_mb", "The average number of megabytes transferred per second (MBps) for read operations to MDisks during the sample period.", labelnames, nil),
79-
prometheus.NewDesc(prefix_stats+"mdisk_r_io", "The average number of I/O operations that are transferred per second for read operations to MDisks during the sample period.", labelnames, nil),
80-
prometheus.NewDesc(prefix_stats+"mdisk_r_ms", "The average amount of time in milliseconds that the system takes to respond to read requests to MDisks over the sample period.", labelnames, nil),
80+
metricsDescMap["mdisk_w_mb"] = "The average number of megabytes transferred per second (MBps) for write operations to MDisks during the sample period."
81+
metricsDescMap["mdisk_w_io"] = "TThe average number of I/O operations that are transferred per second for write operations to MDisks during the sample period."
82+
metricsDescMap["mdisk_w_ms"] = "the average amount of time in milliseconds that the system takes to respond to write requests to MDisks over the sample period."
8183

82-
prometheus.NewDesc(prefix_stats+"mdisk_w_mb", "The average number of megabytes transferred per second (MBps) for write operations to MDisks during the sample period.", labelnames, nil),
83-
prometheus.NewDesc(prefix_stats+"mdisk_w_io", "TThe average number of I/O operations that are transferred per second for write operations to MDisks during the sample period.", labelnames, nil),
84-
prometheus.NewDesc(prefix_stats+"mdisk_w_ms", "the average amount of time in milliseconds that the system takes to respond to write requests to MDisks over the sample period.", labelnames, nil),
84+
metricsDescMap["drive_r_mb"] = "The average number of megabytes transferred per second (MBps) for read operations to drives during the sample period."
85+
metricsDescMap["drive_r_io"] = "The average number of I/O operations that are transferred per second for read operations to drives during the sample period."
86+
metricsDescMap["drive_r_ms"] = "The average amount of time in milliseconds that the system takes to respond to read requests to drives over the sample period."
8587

86-
prometheus.NewDesc(prefix_stats+"drive_r_mb", "The average number of megabytes transferred per second (MBps) for read operations to drives during the sample period.", labelnames, nil),
87-
prometheus.NewDesc(prefix_stats+"drive_r_io", "The average number of I/O operations that are transferred per second for read operations to drives during the sample period.", labelnames, nil),
88-
prometheus.NewDesc(prefix_stats+"drive_r_ms", "The average amount of time in milliseconds that the system takes to respond to read requests to drives over the sample period.", labelnames, nil),
88+
metricsDescMap["drive_w_mb"] = "The average number of megabytes transferred per second (MBps) for write operations to drives during the sample period."
89+
metricsDescMap["drive_w_io"] = "The average number of I/O operations that are transferred per second for write operations to drives during the sample period."
90+
metricsDescMap["drive_w_ms"] = "The average amount of time in milliseconds that the system takes to respond write requests to drives over the sample period."
8991

90-
prometheus.NewDesc(prefix_stats+"drive_w_mb", "The average number of megabytes transferred per second (MBps) for write operations to drives during the sample period.", labelnames, nil),
91-
prometheus.NewDesc(prefix_stats+"drive_w_io", "The average number of I/O operations that are transferred per second for write operations to drives during the sample period.", labelnames, nil),
92-
prometheus.NewDesc(prefix_stats+"drive_w_ms", "The average amount of time in milliseconds that the system takes to respond write requests to drives over the sample period.", labelnames, nil),
92+
metricsDescMap["power_w"] = "the power that is consumed in watts."
93+
metricsDescMap["temp_c"] = " the ambient temperature in Celsius."
94+
metricsDescMap["temp_f"] = "the ambient temperature in Fahrenheit."
9395

94-
prometheus.NewDesc(prefix_stats+"power_w", "the power that is consumed in watts.", labelnames, nil),
95-
prometheus.NewDesc(prefix_stats+"temp_c", " the ambient temperature in Celsius.", labelnames, nil),
96-
prometheus.NewDesc(prefix_stats+"temp_f", "the ambient temperature in Fahrenheit.", labelnames, nil),
96+
metricsDescMap["iplink_mb"] = "The average number of megabytes requested to be transferred per second (MBps) over the IP partnership link during the sample period. This value is calculated before any compression of the data takes place. This value does not include iSCSI host input/output (I/O) operations."
97+
metricsDescMap["iplink_io"] = "TThe total input/output (I/O) operations that are transferred per second for IP partnership traffic on the system."
98+
metricsDescMap["iplink_comp_mb"] = "The average number of compressed megabytes transferred per second (MBps) over the IP Replication link during the sample period. This value is calculated after any compression of |the data takes place. This value does not include iSCSI host I/O operations."
9799

98-
prometheus.NewDesc(prefix_stats+"iplink_mb", "The average number of megabytes requested to be transferred per second (MBps) over the IP partnership link during the sample period. This value is calculated before any compression of the data takes place. This value does not include iSCSI host input/output (I/O) operations.", labelnames, nil),
99-
prometheus.NewDesc(prefix_stats+"iplink_io", "TThe total input/output (I/O) operations that are transferred per second for IP partnership traffic on the system.", labelnames, nil),
100-
prometheus.NewDesc(prefix_stats+"iplink_comp_mb", "The average number of compressed megabytes transferred per second (MBps) over the IP Replication link during the sample period. This value is calculated after any compression of |the data takes place. This value does not include iSCSI host I/O operations.", labelnames, nil),
100+
metricsDescMap["cloud_up_mb"] = "The average number of megabytes transferred per second (Mbps) for upload operations to a cloud account during the sample period."
101+
metricsDescMap["cloud_up_ms"] = "The average amount of time (in milliseconds) it takes for the system to respond to upload requests to a cloud account during the sample period."
102+
metricsDescMap["cloud_down_mb"] = "The average number of Mbps for download operations to a cloud account during the sample period."
103+
metricsDescMap["cloud_down_ms"] = "The average amount of time (in milliseconds) it takes for the system to respond to download requests to a cloud account during the sample period."
101104

102-
prometheus.NewDesc(prefix_stats+"cloud_up_mb", "The average number of megabytes transferred per second (Mbps) for upload operations to a cloud account during the sample period.", labelnames, nil),
103-
prometheus.NewDesc(prefix_stats+"cloud_up_ms", "The average amount of time (in milliseconds) it takes for the system to respond to upload requests to a cloud account during the sample period.", labelnames, nil),
104-
prometheus.NewDesc(prefix_stats+"cloud_down_mb", "The average number of Mbps for download operations to a cloud account during the sample period.", labelnames, nil),
105-
prometheus.NewDesc(prefix_stats+"cloud_down_ms", "The average amount of time (in milliseconds) it takes for the system to respond to download requests to a cloud account during the sample period.", labelnames, nil),
105+
metricsDescMap["iser_mb"] = "The total number of megabytes transferred per second (MBps) for iSER traffic on the system."
106+
metricsDescMap["iser_io"] = "The total I/O operations that are transferred per second for iSER traffic on the system."
107+
metricsDescMap["nvme_rdma_mb"] = "The total number of megabytes transferred per second (MBps) for NVMe over RDMA traffic on the system."
108+
metricsDescMap["nvme_rdma_io"] = "The total I/O operations that are transferred per second for NVMe over RDMA traffic on the system."
109+
metricsDescMap["nvme_tcp_mb"] = "The total number of megabytes transferred per second (MBps) for NVMe over TCP traffic on the system."
110+
metricsDescMap["nvme_tcp_io"] = "The total I/O operations that are transferred per second for NVMe over TCP traffic on the system."
111+
}
106112

107-
prometheus.NewDesc(prefix_stats+"iser_mb", "The total number of megabytes transferred per second (MBps) for iSER traffic on the system.", labelnames, nil),
108-
prometheus.NewDesc(prefix_stats+"iser_io", "The total I/O operations that are transferred per second for iSER traffic on the system.", labelnames, nil),
113+
func NewSystemStatsCollector() (Collector, error) {
114+
InitmetricsDescMap()
115+
labelnames := []string{"resource"}
116+
if len(utils.ExtraLabelNames) > 0 {
117+
labelnames = append(labelnames, utils.ExtraLabelNames...)
118+
}
119+
metricsPromDescMap = make(map[string]*prometheus.Desc)
120+
for statName, statDef := range metricsDescMap {
121+
metricsPromDescMap[statName] = prometheus.NewDesc(prefix_stats+statName, statDef, labelnames, nil)
109122
}
110123

111124
return &systemStatsCollector{}, nil
112125
}
113126

114-
// Describe describes the metrics
127+
// Describe describes the metricsPromDescMap
115128
func (*systemStatsCollector) Describe(ch chan<- *prometheus.Desc) {
116129

117-
for _, metric := range metrics {
130+
for _, metric := range metricsPromDescMap {
118131
ch <- metric
119132
}
120133

@@ -162,10 +175,11 @@ func (c *systemStatsCollector) Collect(sClient utils.SpectrumClient, ch chan<- p
162175
}
163176

164177
systemStats := gjson.Parse(systemStatsResp).Array()
165-
for i, systemStat := range systemStats {
166-
// ignore the fields greater than 49
167-
if i < 49 {
168-
ch <- prometheus.MustNewConstMetric(metrics[i], prometheus.GaugeValue, systemStat.Get("stat_current").Float(), labelvalues...)
178+
for _, systemStat := range systemStats {
179+
180+
mrtricDesc, isExist := metricsPromDescMap[systemStat.Get("stat_name").String()]
181+
if isExist {
182+
ch <- prometheus.MustNewConstMetric(mrtricDesc, prometheus.GaugeValue, systemStat.Get("stat_current").Float(), labelvalues...)
169183
}
170184
}
171185
logger.Debugln("exit SystemStats collector")

0 commit comments

Comments
 (0)