StorageMetrics
数据结构
| 字节索引 | 类型 | 字段含义 |
|---|---|---|
| 0-3 | float32 | 磁盘空间使用率 [%] |
| 4-7 | uint32 | 已使用空间 [MiB] |
| 8-11 | uint32 | 可用空间 [MiB] |
| 12-15 | uint32 | 每秒物理读磁盘次数 |
| 16-19 | uint32 | 每秒物理写磁盘次数 |
| 20-23 | float32 | 实时读取带宽 [MiB/s] |
| 24-27 | float32 | 实时写入带宽 [MiB/s] |
| 28-31 | float32 | CPU I/O 等待时间占比 [%] |
StorageMetrics 固定为 32 字节
示例
C++ 示例
struct StorageMetrics {
float space_usage;
uint32_t used_space;
uint32_t available_space;
uint32_t read_iops;
uint32_t write_iops;
float read_throughput;
float write_throughput;
float io_wait;
};
Rust 示例
#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct StorageMetrics {
pub space_usage: f32,
pub used_space: u32,
pub available_space: u32,
pub read_iops: u32,
pub write_iops: u32,
pub read_throughput: f32,
pub write_throughput: f32,
pub io_wait: f32,
}
const _: () = {
assert!(core::mem::size_of::<StorageMetrics>() == 32);
assert!(core::mem::align_of::<StorageMetrics>() == 4);
};
Dart 示例
import 'dart:typed_data';
final class StorageMetricsView {
static const int byteLength = 32;
final ByteData data;
StorageMetricsView(ByteBuffer buffer, [int offsetInBytes = 0])
: data = ByteData.view(buffer, offsetInBytes, byteLength);
double get spaceUsage => data.getFloat32(0, Endian.little);
int get usedSpace => data.getUint32(4, Endian.little);
int get availableSpace => data.getUint32(8, Endian.little);
int get readIops => data.getUint32(12, Endian.little);
int get writeIops => data.getUint32(16, Endian.little);
double get readThroughput => data.getFloat32(20, Endian.little);
double get writeThroughput => data.getFloat32(24, Endian.little);
double get ioWait => data.getFloat32(28, Endian.little);
}
Java 示例
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public final class StorageMetricsView {
public static final int BYTE_LENGTH = 32;
private final ByteBuffer buffer;
private final int offset;
public StorageMetricsView(ByteBuffer buffer, int offset) {
if (offset < 0 || offset + BYTE_LENGTH > buffer.capacity()) {
throw new IndexOutOfBoundsException("StorageMetrics payload requires 32 bytes");
}
this.buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
this.offset = offset;
}
public float spaceUsage() { return buffer.getFloat(offset); }
public long usedSpace() { return Integer.toUnsignedLong(buffer.getInt(offset + 4)); }
public long availableSpace() { return Integer.toUnsignedLong(buffer.getInt(offset + 8)); }
public long readIops() { return Integer.toUnsignedLong(buffer.getInt(offset + 12)); }
public long writeIops() { return Integer.toUnsignedLong(buffer.getInt(offset + 16)); }
public float readThroughput() { return buffer.getFloat(offset + 20); }
public float writeThroughput() { return buffer.getFloat(offset + 24); }
public float ioWait() { return buffer.getFloat(offset + 28); }
}