Skip to content

Commit 0c1f17a

Browse files
committed
fixup! Skip metrics when standby JSON cached
Describe now exports a static superset of descriptors to avoid unregistered descriptor errors when metrics are conditionally skipped.
1 parent f51105e commit 0c1f17a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ type SMARTctlManagerCollector struct {
5757

5858
// Describe sends the super-set of all possible descriptors of metrics
5959
func (i *SMARTctlManagerCollector) Describe(ch chan<- *prometheus.Desc) {
60-
prometheus.DescribeByCollect(i, ch)
60+
for _, desc := range allMetricDescs {
61+
ch <- desc
62+
}
6163
}
6264

6365
// Collect is called by the Prometheus registry when collecting metrics.

metrics.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,45 @@ var (
362362
},
363363
nil,
364364
)
365+
allMetricDescs = []*prometheus.Desc{
366+
metricSmartctlVersion,
367+
metricDeviceModel,
368+
metricDeviceCount,
369+
metricDeviceCapacityBlocks,
370+
metricDeviceCapacityBytes,
371+
metricDeviceTotalCapacityBytes,
372+
metricDeviceBlockSize,
373+
metricDeviceInterfaceSpeed,
374+
metricDeviceAttribute,
375+
metricDevicePowerOnSeconds,
376+
metricDeviceRotationRate,
377+
metricDeviceTemperature,
378+
metricDevicePowerCycleCount,
379+
metricDevicePercentageUsed,
380+
metricDeviceAvailableSpare,
381+
metricDeviceAvailableSpareThreshold,
382+
metricDeviceCriticalWarning,
383+
metricDeviceMediaErrors,
384+
metricDeviceNumErrLogEntries,
385+
metricDeviceBytesRead,
386+
metricDeviceBytesWritten,
387+
metricDeviceSmartStatus,
388+
metricDeviceExitStatus,
389+
metricDeviceState,
390+
metricDevicePowerMode,
391+
metricDeviceStatistics,
392+
metricDeviceErrorLogCount,
393+
metricDeviceSelfTestLogCount,
394+
metricDeviceSelfTestLogErrorCount,
395+
metricDeviceERCSeconds,
396+
metricSCSIGrownDefectList,
397+
metricReadErrorsCorrectedByRereadsRewrites,
398+
metricReadErrorsCorrectedByEccFast,
399+
metricReadErrorsCorrectedByEccDelayed,
400+
metricReadTotalUncorrectedErrors,
401+
metricWriteErrorsCorrectedByRereadsRewrites,
402+
metricWriteErrorsCorrectedByEccFast,
403+
metricWriteErrorsCorrectedByEccDelayed,
404+
metricWriteTotalUncorrectedErrors,
405+
}
365406
)

0 commit comments

Comments
 (0)