diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index ed5d044a61..d90b6862a8 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -85,6 +85,7 @@ type diskstatsCollector struct { filesystemInfoDesc typedFactorDesc deviceMapperInfoDesc typedFactorDesc ataDescs map[string]typedFactorDesc + diskSizeDesc typedFactorDesc logger log.Logger getUdevDeviceProperties func(uint32, uint32) (udevInfo, error) } @@ -257,6 +258,12 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { ), valueType: prometheus.GaugeValue, }, }, + diskSizeDesc: typedFactorDesc{ + desc: prometheus.NewDesc(prometheus.BuildFQName(namespace, diskSubsystem, "size_bytes"), + "Size of the disk in bytes.", + diskLabelNames, nil, + ), valueType: prometheus.GaugeValue, + }, logger: logger, } @@ -366,6 +373,13 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { } } } + + sizeBytes, err := c.fs.SysBlockDeviceSizeBytes(dev) + if err != nil { + level.Error(c.logger).Log("msg", "Failed to get device size", "err", err) + continue + } + ch <- c.diskSizeDesc.mustNewConstMetric(float64(sizeBytes), dev) } return nil } diff --git a/collector/diskstats_linux_test.go b/collector/diskstats_linux_test.go index 88d8c8265e..19ee5e3b75 100644 --- a/collector/diskstats_linux_test.go +++ b/collector/diskstats_linux_test.go @@ -247,6 +247,10 @@ node_disk_reads_merged_total{device="sdb"} 841 node_disk_reads_merged_total{device="sdc"} 141 node_disk_reads_merged_total{device="sr0"} 0 node_disk_reads_merged_total{device="vda"} 15386 +# HELP node_disk_size_bytes Size of the disk in bytes. +# TYPE node_disk_size_bytes gauge +node_disk_size_bytes{device="nvme0n1"} 1.073741824e+10 +node_disk_size_bytes{device="nvme1n1"} 9e+11 # HELP node_disk_write_time_seconds_total This is the total number of seconds spent by all writes. # TYPE node_disk_write_time_seconds_total counter node_disk_write_time_seconds_total{device="dm-0"} 1.1585578e+06