@@ -132,6 +132,23 @@ func (smart *SMARTctl) mineExitStatus() {
132132}
133133
134134func (smart * SMARTctl ) mineDevice () {
135+ hasInfo := false
136+ for _ , key := range []string {
137+ "model_name" ,
138+ "scsi_vendor" ,
139+ "scsi_product" ,
140+ "serial_number" ,
141+ "firmware_version" ,
142+ "model_family" ,
143+ } {
144+ if smart .json .Get (key ).Exists () {
145+ hasInfo = true
146+ break
147+ }
148+ }
149+ if ! hasInfo {
150+ return
151+ }
135152 smart .ch <- prometheus .MustNewConstMetric (
136153 metricDeviceModel ,
137154 prometheus .GaugeValue ,
@@ -171,18 +188,27 @@ func (smart *SMARTctl) mineCapacity() {
171188 // The user_capacity exists only when NVMe have single namespace. Otherwise,
172189 // for NVMe devices with multiple namespaces, when device name used without
173190 // namespace number (exporter case) user_capacity will be absent
174- smart .ch <- prometheus .MustNewConstMetric (
175- metricDeviceCapacityBlocks ,
176- prometheus .GaugeValue ,
177- smart .json .Get ("user_capacity.blocks" ).Float (),
178- smart .device .device ,
179- )
180- smart .ch <- prometheus .MustNewConstMetric (
181- metricDeviceCapacityBytes ,
182- prometheus .GaugeValue ,
183- smart .json .Get ("user_capacity.bytes" ).Float (),
184- smart .device .device ,
185- )
191+ userCapacity := smart .json .Get ("user_capacity" )
192+ if userCapacity .Exists () {
193+ blocks := userCapacity .Get ("blocks" )
194+ if blocks .Exists () {
195+ smart .ch <- prometheus .MustNewConstMetric (
196+ metricDeviceCapacityBlocks ,
197+ prometheus .GaugeValue ,
198+ blocks .Float (),
199+ smart .device .device ,
200+ )
201+ }
202+ bytes := userCapacity .Get ("bytes" )
203+ if bytes .Exists () {
204+ smart .ch <- prometheus .MustNewConstMetric (
205+ metricDeviceCapacityBytes ,
206+ prometheus .GaugeValue ,
207+ bytes .Float (),
208+ smart .device .device ,
209+ )
210+ }
211+ }
186212 nvme_total_capacity := smart .json .Get ("nvme_total_capacity" )
187213 if nvme_total_capacity .Exists () {
188214 smart .ch <- prometheus .MustNewConstMetric (
@@ -196,10 +222,14 @@ func (smart *SMARTctl) mineCapacity() {
196222
197223func (smart * SMARTctl ) mineBlockSize () {
198224 for _ , blockType := range []string {"logical" , "physical" } {
225+ blockSize := smart .json .Get (fmt .Sprintf ("%s_block_size" , blockType ))
226+ if ! blockSize .Exists () {
227+ continue
228+ }
199229 smart .ch <- prometheus .MustNewConstMetric (
200230 metricDeviceBlockSize ,
201231 prometheus .GaugeValue ,
202- smart . json . Get ( fmt . Sprintf ( "%s_block_size" , blockType )) .Float (),
232+ blockSize .Float (),
203233 smart .device .device ,
204234 blockType ,
205235 )
@@ -342,55 +372,79 @@ func (smart *SMARTctl) mineDeviceSCTStatus() {
342372}
343373
344374func (smart * SMARTctl ) mineNvmePercentageUsed () {
375+ percentageUsed := smart .json .Get ("nvme_smart_health_information_log.percentage_used" )
376+ if ! percentageUsed .Exists () {
377+ return
378+ }
345379 smart .ch <- prometheus .MustNewConstMetric (
346380 metricDevicePercentageUsed ,
347381 prometheus .CounterValue ,
348- smart . json . Get ( "nvme_smart_health_information_log.percentage_used" ) .Float (),
382+ percentageUsed .Float (),
349383 smart .device .device ,
350384 )
351385}
352386
353387func (smart * SMARTctl ) mineNvmeAvailableSpare () {
388+ availableSpare := smart .json .Get ("nvme_smart_health_information_log.available_spare" )
389+ if ! availableSpare .Exists () {
390+ return
391+ }
354392 smart .ch <- prometheus .MustNewConstMetric (
355393 metricDeviceAvailableSpare ,
356394 prometheus .CounterValue ,
357- smart . json . Get ( "nvme_smart_health_information_log.available_spare" ) .Float (),
395+ availableSpare .Float (),
358396 smart .device .device ,
359397 )
360398}
361399
362400func (smart * SMARTctl ) mineNvmeAvailableSpareThreshold () {
401+ availableSpareThreshold := smart .json .Get ("nvme_smart_health_information_log.available_spare_threshold" )
402+ if ! availableSpareThreshold .Exists () {
403+ return
404+ }
363405 smart .ch <- prometheus .MustNewConstMetric (
364406 metricDeviceAvailableSpareThreshold ,
365407 prometheus .CounterValue ,
366- smart . json . Get ( "nvme_smart_health_information_log.available_spare_threshold" ) .Float (),
408+ availableSpareThreshold .Float (),
367409 smart .device .device ,
368410 )
369411}
370412
371413func (smart * SMARTctl ) mineNvmeCriticalWarning () {
414+ criticalWarning := smart .json .Get ("nvme_smart_health_information_log.critical_warning" )
415+ if ! criticalWarning .Exists () {
416+ return
417+ }
372418 smart .ch <- prometheus .MustNewConstMetric (
373419 metricDeviceCriticalWarning ,
374420 prometheus .CounterValue ,
375- smart . json . Get ( "nvme_smart_health_information_log.critical_warning" ) .Float (),
421+ criticalWarning .Float (),
376422 smart .device .device ,
377423 )
378424}
379425
380426func (smart * SMARTctl ) mineNvmeMediaErrors () {
427+ mediaErrors := smart .json .Get ("nvme_smart_health_information_log.media_errors" )
428+ if ! mediaErrors .Exists () {
429+ return
430+ }
381431 smart .ch <- prometheus .MustNewConstMetric (
382432 metricDeviceMediaErrors ,
383433 prometheus .CounterValue ,
384- smart . json . Get ( "nvme_smart_health_information_log.media_errors" ) .Float (),
434+ mediaErrors .Float (),
385435 smart .device .device ,
386436 )
387437}
388438
389439func (smart * SMARTctl ) mineNvmeNumErrLogEntries () {
440+ numErrLogEntries := smart .json .Get ("nvme_smart_health_information_log.num_err_log_entries" )
441+ if ! numErrLogEntries .Exists () {
442+ return
443+ }
390444 smart .ch <- prometheus .MustNewConstMetric (
391445 metricDeviceNumErrLogEntries ,
392446 prometheus .CounterValue ,
393- smart . json . Get ( "nvme_smart_health_information_log.num_err_log_entries" ) .Float (),
447+ numErrLogEntries .Float (),
394448 smart .device .device ,
395449 )
396450}
0 commit comments