@@ -158,47 +158,48 @@ def main():
158158
159159 for device in device_list ["Devices" ]:
160160 device_path = device ["DevicePath" ]
161+ device_name = os .path .basename (device_path )
161162
162163 metrics ["device_info" ].labels (
163- device_path ,
164+ device_name ,
164165 device ["ModelNumber" ],
165166 device ["Firmware" ],
166167 device ["SerialNumber" ].strip (),
167168 )
168169
169- metrics ["sector_size" ].labels (device_path ).set (device ["SectorSize" ])
170- metrics ["physical_size" ].labels (device_path ).set (device ["PhysicalSize" ])
171- metrics ["used_bytes" ].labels (device_path ).set (device ["UsedBytes" ])
170+ metrics ["sector_size" ].labels (device_name ).set (device ["SectorSize" ])
171+ metrics ["physical_size" ].labels (device_name ).set (device ["PhysicalSize" ])
172+ metrics ["used_bytes" ].labels (device_name ).set (device ["UsedBytes" ])
172173
173174 smart_log = exec_nvme_json ("smart-log" , device_path )
174175
175176 # Various counters in the NVMe specification are 128-bit, which would have to discard
176177 # resolution if converted to a JSON number (i.e., float64_t). Instead, nvme-cli marshals
177178 # them as strings. As such, they need to be explicitly cast to int or float when using them
178179 # in Counter metrics.
179- metrics ["data_units_read" ].labels (device_path ).inc (int (smart_log ["data_units_read" ]))
180- metrics ["data_units_written" ].labels (device_path ).inc (int (smart_log ["data_units_written" ]))
181- metrics ["host_read_commands" ].labels (device_path ).inc (int (smart_log ["host_read_commands" ]))
182- metrics ["host_write_commands" ].labels (device_path ).inc (
180+ metrics ["data_units_read" ].labels (device_name ).inc (int (smart_log ["data_units_read" ]))
181+ metrics ["data_units_written" ].labels (device_name ).inc (int (smart_log ["data_units_written" ]))
182+ metrics ["host_read_commands" ].labels (device_name ).inc (int (smart_log ["host_read_commands" ]))
183+ metrics ["host_write_commands" ].labels (device_name ).inc (
183184 int (smart_log ["host_write_commands" ])
184185 )
185- metrics ["avail_spare" ].labels (device_path ).set (smart_log ["avail_spare" ] / 100 )
186- metrics ["spare_thresh" ].labels (device_path ).set (smart_log ["spare_thresh" ] / 100 )
187- metrics ["percent_used" ].labels (device_path ).set (smart_log ["percent_used" ] / 100 )
188- metrics ["critical_warning" ].labels (device_path ).set (smart_log ["critical_warning" ])
189- metrics ["media_errors" ].labels (device_path ).inc (int (smart_log ["media_errors" ]))
190- metrics ["num_err_log_entries" ].labels (device_path ).inc (
186+ metrics ["avail_spare" ].labels (device_name ).set (smart_log ["avail_spare" ] / 100 )
187+ metrics ["spare_thresh" ].labels (device_name ).set (smart_log ["spare_thresh" ] / 100 )
188+ metrics ["percent_used" ].labels (device_name ).set (smart_log ["percent_used" ] / 100 )
189+ metrics ["critical_warning" ].labels (device_name ).set (smart_log ["critical_warning" ])
190+ metrics ["media_errors" ].labels (device_name ).inc (int (smart_log ["media_errors" ]))
191+ metrics ["num_err_log_entries" ].labels (device_name ).inc (
191192 int (smart_log ["num_err_log_entries" ])
192193 )
193- metrics ["power_cycles" ].labels (device_path ).inc (int (smart_log ["power_cycles" ]))
194- metrics ["power_on_hours" ].labels (device_path ).inc (int (smart_log ["power_on_hours" ]))
195- metrics ["controller_busy_time" ].labels (device_path ).inc (
194+ metrics ["power_cycles" ].labels (device_name ).inc (int (smart_log ["power_cycles" ]))
195+ metrics ["power_on_hours" ].labels (device_name ).inc (int (smart_log ["power_on_hours" ]))
196+ metrics ["controller_busy_time" ].labels (device_name ).inc (
196197 int (smart_log ["controller_busy_time" ])
197198 )
198- metrics ["unsafe_shutdowns" ].labels (device_path ).inc (int (smart_log ["unsafe_shutdowns" ]))
199+ metrics ["unsafe_shutdowns" ].labels (device_name ).inc (int (smart_log ["unsafe_shutdowns" ]))
199200
200201 # NVMe reports temperature in kelvins; convert it to degrees Celsius.
201- metrics ["temperature" ].labels (device_path ).set (smart_log ["temperature" ] - 273 )
202+ metrics ["temperature" ].labels (device_name ).set (smart_log ["temperature" ] - 273 )
202203
203204
204205if __name__ == "__main__" :
0 commit comments