# Monitoring Database Storage in Java

> Java applications can obtain database page statistics directly from the Connection class properties `FreePages`, `TotalPages` and `DbPageSize`. Also, the Connection methods `getClassStats()` and `getIndexStat()` return the class and index statistics, and property `IndexStatCount` gives the number of indexes in the database.

> The following code snippet from sample "`samples/java/Statistics`" demonstrates how these statistics can be retrieved:

>         System.out.format("Total pages:    %d", con.getTotalPages());
>         System.out.println();
>         System.out.format("Free pages:     %d", con.getFreePages());
>         System.out.println();
>         System.out.format("Page size:      %d", con.getDbPageSize());
>         System.out.println();

>         con.startTransaction(TransactionType.ReadOnly);
>         for (int cls = 1; cls <= params.classes.length; cls++)
>         {
>             ClassStat stat = con.getClassStat(cls);
>             System.out.format("Class %d: %d objects, %d pages, %d blob pages",
>                     cls, stat.ObjectsCount, stat.CorePageCount, stat.BlobPages);
>             System.out.println();
>         }
>         con.rollbackTransaction();

>         System.out.println();
>         con.startTransaction(TransactionType.ReadOnly);
>         short idx_num = con.getIndexStatCount();
>         for (short idx = 0; idx < idx_num; idx++)
>         {
>             Statistic.IndexStat stat = con.getIndexStat(idx);
>             System.out.format("%s: %d key(s) %d page(s) ", stat.Label, stat.KeysCount, stat.PagesCount);
>             System.out.println();
>         }
>         con.rollbackTransaction();

> ## Persistent Databases

> Java applications can obtain information about database storage on persistent media directly from the Connection class method `getDiskInfo()` which returns properties `DataFileSize`, `UsedDatabaseSize` and `LogFileSize`.

> The following code snippet from sample "`samples/java/Statistics`" demonstrates how these sizes can be retrieved:

>         Statistic.DiskInfo di = con.getDiskInfo();
>         System.out.format("Disk file size: %d, Used: %d, Transaction log file size: %d",
>                     di.DataFileSize, di.LogFileSize, di.LogFileSize);