StorageStatistics class final
Represents comprehensive storage statistics.
Provides detailed information about a storage instance including:
- Entity counts and size metrics
- Memory and disk usage
- Performance statistics
- Index information
Usage
final stats = await storage.getStatistics();
print('Entities: ${stats.entityCount}');
print('Memory: ${stats.humanReadableMemoryUsage}');
print('Disk: ${stats.humanReadableDiskUsage}');
if (stats.fragmentationRatio > 0.3) {
await storage.compact();
}
Monitoring
// Collect statistics periodically
Timer.periodic(Duration(minutes: 5), (_) async {
final stats = await storage.getStatistics();
logger.info('Storage stats: ${stats.toMap()}');
if (stats.memoryUsageBytes > maxMemory) {
await storage.evictCache();
}
});
- Implemented types
Constructors
-
StorageStatistics({String? id, required String storageName, required DateTime collectedAt, required int entityCount, int memoryUsageBytes = 0, int diskUsageBytes = 0, int indexCount = 0, int readOperations = 0, int writeOperations = 0, int avgReadLatencyMicros = 0, int avgWriteLatencyMicros = 0, double cacheHitRatio = 0.0, double fragmentationRatio = 0.0, bool isOpen = true, bool supportsTransactions = false, Map<
String, dynamic> customMetrics = const {}}) -
Creates a new storage statistics instance.
const
- StorageStatistics.basic({String? id, required String storageName, required int entityCount, int memoryUsageBytes = 0, bool isOpen = true})
-
Creates statistics with basic counts only.
factory
- StorageStatistics.empty({String? id, required String storageName, bool isOpen = true, bool supportsTransactions = false})
-
Creates statistics for an empty or newly initialized storage.
factory
-
StorageStatistics.fromMap(String id, Map<
String, dynamic> map) -
Creates statistics from a stored map.
factory
Properties
- avgReadLatencyMicros → int
-
Average read latency in microseconds.
final
- avgWriteLatencyMicros → int
-
Average write latency in microseconds.
final
- cacheHitRatio → double
-
Cache hit ratio (0.0 to 1.0).
final
- collectedAt → DateTime
-
Timestamp when statistics were collected.
final
-
customMetrics
→ Map<
String, dynamic> -
Additional storage-specific metrics.
final
- diskUsageBytes → int
-
Current disk usage in bytes (if applicable).
final
- entityCount → int
-
Number of entities currently stored.
final
- fragmentationRatio → double
-
Fragmentation ratio (0.0 to 1.0).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- humanReadableDiskUsage → String
-
Returns human-readable disk usage.
no setter
- humanReadableMemoryUsage → String
-
Returns human-readable memory usage.
no setter
- id → String?
-
Unique identifier for this statistics snapshot.
final
- indexCount → int
-
Number of indexes on this storage.
final
- isOpen → bool
-
Whether the storage is currently open.
final
- memoryUsageBytes → int
-
Current memory usage in bytes.
final
- readOperations → int
-
Total number of read operations since startup.
final
- readWriteRatio → double
-
Read/write ratio.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storageName → String
-
Name of the storage instance.
final
- supportsTransactions → bool
-
Whether the storage supports transactions.
final
- totalOperations → int
-
Total operations (read + write).
no setter
- writeOperations → int
-
Total number of write operations since startup.
final
Methods
-
copyWith(
{String? id, String? storageName, DateTime? collectedAt, int? entityCount, int? memoryUsageBytes, int? diskUsageBytes, int? indexCount, int? readOperations, int? writeOperations, int? avgReadLatencyMicros, int? avgWriteLatencyMicros, double? cacheHitRatio, double? fragmentationRatio, bool? isOpen, bool? supportsTransactions, Map< String, dynamic> ? customMetrics}) → StorageStatistics - Creates a copy with updated fields.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toMap(
) → Map< String, dynamic> -
Converts this entity to a map for storage.
override
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited