Skip to content

Commit

Permalink
collector/diskstats: add block device rotational
Browse files Browse the repository at this point in the history
Add metric to indicate if a device is rotational or not.

Fixes: #2956
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
  • Loading branch information
rexagod committed Aug 13, 2024
1 parent b9d0932 commit bac46b7
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 0 deletions.
25 changes: 25 additions & 0 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type diskstatsCollector struct {
filesystemInfoDesc typedFactorDesc
deviceMapperInfoDesc typedFactorDesc
ataDescs map[string]typedFactorDesc
queueDescs []typedFactorDesc
logger log.Logger
getUdevDeviceProperties func(uint32, uint32) (udevInfo, error)
}
Expand Down Expand Up @@ -257,6 +258,16 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) {
), valueType: prometheus.GaugeValue,
},
},
queueDescs: []typedFactorDesc{
{
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, diskSubsystem, "rotational"),
"Rotational indicates whether the device is a rotational disk (1) or not (0).",
diskLabelNames,
nil,
), valueType: prometheus.GaugeValue,
},
},
logger: logger,
}

Expand Down Expand Up @@ -366,6 +377,20 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
}
}
}

queueStats, err := c.fs.SysBlockDeviceQueueStats(dev)
// Block Device Queue stats may not exist for all devices.
if err != nil && !os.IsNotExist(err) {
level.Debug(c.logger).Log("msg", "Failed to get queue stats", "err", err)
}
for i, val := range []float64{
float64(queueStats.Rotational),
} {
if i >= len(c.queueDescs) {
break
}
ch <- c.queueDescs[i].mustNewConstMetric(val, dev)
}
}
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions collector/diskstats_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ node_disk_written_bytes_total{device="sdb"} 1.01012736e+09
node_disk_written_bytes_total{device="sdc"} 8.852736e+07
node_disk_written_bytes_total{device="sr0"} 0
node_disk_written_bytes_total{device="vda"} 1.0938236928e+11
# HELP node_disk_rotational Rotational indicates whether the device is a rotational disk (1) or not (0).
# TYPE node_disk_rotational gauge
node_disk_rotational{device="dm-0"} 0
node_disk_rotational{device="dm-1"} 0
node_disk_rotational{device="dm-2"} 0
node_disk_rotational{device="dm-3"} 0
node_disk_rotational{device="dm-4"} 0
node_disk_rotational{device="dm-5"} 0
node_disk_rotational{device="mmcblk0"} 0
node_disk_rotational{device="mmcblk0p1"} 0
node_disk_rotational{device="mmcblk0p2"} 0
node_disk_rotational{device="nvme0n1"} 0
node_disk_rotational{device="sda"} 1
node_disk_rotational{device="sdb"} 0
node_disk_rotational{device="sdc"} 0
node_disk_rotational{device="sr0"} 0
node_disk_rotational{device="vda"} 0
`

logger := log.NewLogfmtLogger(os.Stderr)
Expand Down
237 changes: 237 additions & 0 deletions collector/fixtures/sys.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,243 @@
Directory: sys
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/block
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/block/sda
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/block/sda/queue
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/add_random
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/chunk_sectors
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/dax
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/discard_granularity
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/discard_max_bytes
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/discard_max_hw_bytes
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/discard_zeroes_data
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/fua
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/hw_sector_size
Lines: 1
512
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/io_poll
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/io_poll_delay
Lines: 1
-1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/io_timeout
Lines: 1
30000
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/block/sda/queue/iosched
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/back_seek_max
Lines: 1
16384
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/back_seek_penalty
Lines: 1
2
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/fifo_expire_async
Lines: 1
250
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/fifo_expire_sync
Lines: 1
125
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/low_latency
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/max_budget
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/slice_idle
Lines: 1
8
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/slice_idle_us
Lines: 1
8000
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/strict_guarantees
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iosched/timeout_sync
Lines: 1
125
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/iostats
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/logical_block_size
Lines: 1
512
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_discard_segments
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_hw_sectors_kb
Lines: 1
32767
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_integrity_segments
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_sectors_kb
Lines: 1
1280
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_segment_size
Lines: 1
65536
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/max_segments
Lines: 1
168
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/minimum_io_size
Lines: 1
512
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/nomerges
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/nr_requests
Lines: 1
64
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/nr_zones
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/optimal_io_size
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/physical_block_size
Lines: 1
512
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/read_ahead_kb
Lines: 1
128
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/rotational
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/rq_affinity
Lines: 1
1
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/scheduler
Lines: 1
mq-deadline kyber [bfq] none
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/wbt_lat_usec
Lines: 1
75000
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/write_cache
Lines: 1
write back
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/write_same_max_bytes
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/write_zeroes_max_bytes
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/block/sda/queue/zoned
Lines: 1
none
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/bus
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down

0 comments on commit bac46b7

Please sign in to comment.