# mco_stat_get_disk_stats
RT

> Retrieve and optionally reset I/O statistics for disk operations on a specific database connection or aggregated across all connections.

### Prototype

        MCO_RET mco_stat_get_disk_stats(
            /*IN*/  const char *db_name,
            /*IN*/  int conn_no,
            /*OUT*/ mco_disk_stat_t *ret,
            /*IN*/  mco_bool reset
        );

### Arguments

`db_name`
Name of the target database.
`conn_no`
Connection identifier:

- A non-negative integer — retrieves stats for a specific connection,
- `-1` — aggregates stats across all active connections in the database.

`ret`
Pointer to a `mco_disk_stat_t` structure that will receive the aggregated I/O statistics.
`reset`
Flag indicating whether to clear the per-connection disk statistics after reading:

- `MCO_NO` — read only,
- `MCO_YES` — read and reset counters to zero.

### Description

> This function collects low-level disk I/O metrics for a database, including counts and timing data for read, write, and synchronization operations. It is available only when `MCO_CFG_SUPPORT_DISK_OBJECTS` is enabled at build time.

> When `conn_no = -1`, statistics from all active connections are summed. When a specific connection ID is provided, only that connection’s data is returned.

> The `mco_disk_stat_t` structure includes:

> - Operation counts (`db_total_read`, `db_total_write`, `db_sync_count`),
> - Total time spent in each operation type,
> - Maximum (peak) time observed for a single operation.

> If `reset = MCO_YES`, the underlying per-connection counters are cleared after aggregation, enabling delta-based monitoring.

> Note: The database must be open, and the specified connection (if not -1) must be active.

### Return Codes

`MCO_S_OK`
Disk statistics successfully retrieved (and optionally reset).
`MCO_S_NOTFOUND`
The specified database or connection does not exist.
`MCO_S_CURSOR_END`
No active connections found (when `conn_no = -1` and all connections are free).
Other error codes
May include registry access errors or internal system failures.

### Example

        mco_disk_stat_t disk_stats;
        MCO_RET rc;

        // Get aggregated disk stats for "mydb" and reset counters
        rc = mco_stat_get_disk_stats("mydb", -1, &disk_stats, MCO_YES);
        if (rc == MCO_S_OK) {
            printf("Total reads: %llu\n", disk_stats.db_total_read);
            printf("Max write time: %llu µs\n", disk_stats.db_max_write_time);
            printf("Sync operations: %llu\n", disk_stats.db_sync_count);
        }

### Files

Header file:
mcostatrt.h
Source file:
mcostat.c
Library:
libmcolib.a