Skip to content

Commit 5a30bb5

Browse files
committed
feat: add func BdevGetIostat
Signed-off-by: jinhong.kim0 <[email protected]>
1 parent eabe34a commit 5a30bb5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

pkg/spdk/client/basic.go

+24
Original file line numberDiff line numberDiff line change
@@ -1313,3 +1313,27 @@ func (c *Client) BdevVirtioDetachController(name string) (deleted bool, err erro
13131313

13141314
return deleted, json.Unmarshal(cmdOutput, &deleted)
13151315
}
1316+
1317+
// BdevGetIostat get I/O statistics of block devices (bdevs).
1318+
//
1319+
// "name": Optional. If this is not specified, the function will list all block devices.
1320+
//
1321+
// "per_channel": Optional. Display per channel data for specified block device.
1322+
func (c *Client) BdevGetIostat(name string, perChannel bool) (resp *spdktypes.BdevIostatResponse, err error) {
1323+
req := spdktypes.BdevIostatRequest{
1324+
Name: name,
1325+
PerChannel: perChannel,
1326+
}
1327+
1328+
cmdOutput, err := c.jsonCli.SendCommand("bdev_get_iostat", req)
1329+
if err != nil {
1330+
return nil, fmt.Errorf("failed to execute bdev_get_iostat: %v", err)
1331+
}
1332+
1333+
resp = &spdktypes.BdevIostatResponse{}
1334+
if err := json.Unmarshal(cmdOutput, resp); err != nil {
1335+
return nil, fmt.Errorf("failed to parse bdev_get_iostat response: %v", err)
1336+
}
1337+
1338+
return resp, nil
1339+
}

pkg/spdk/types/bdev.go

+26
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,29 @@ type BdevLvolFragmap struct {
135135
NumAllocatedClusters uint64 `json:"num_allocated_clusters"`
136136
Fragmap string `json:"fragmap"`
137137
}
138+
139+
type BdevIostatRequest struct {
140+
Name string `json:"name,omitempty"`
141+
PerChannel bool `json:"per_channel,omitempty"`
142+
}
143+
144+
type BdevIostatResponse struct {
145+
TickRate uint64 `json:"tick_rate"`
146+
Bdevs []BdevStats `json:"bdevs"`
147+
}
148+
149+
type BdevStats struct {
150+
Name string `json:"name"`
151+
BytesRead uint64 `json:"bytes_read"`
152+
NumReadOps uint64 `json:"num_read_ops"`
153+
BytesWritten uint64 `json:"bytes_written"`
154+
NumWriteOps uint64 `json:"num_write_ops"`
155+
BytesUnmapped uint64 `json:"bytes_unmapped"`
156+
NumUnmapOps uint64 `json:"num_unmap_ops"`
157+
ReadLatencyTicks uint64 `json:"read_latency_ticks"`
158+
WriteLatencyTicks uint64 `json:"write_latency_ticks"`
159+
UnmapLatencyTicks uint64 `json:"unmap_latency_ticks"`
160+
QueueDepth uint64 `json:"queue_depth"`
161+
IoTime uint64 `json:"io_time"`
162+
WeightedIoTime uint64 `json:"weighted_io_time"`
163+
}

0 commit comments

Comments
 (0)