The stats schema is a special schema that contains virtual tables which are read-only and can be queried to get statistical real-time information about the cluster.
The stats schema contains a table called shards. This table can be queried for gathering real-time shard statistics of one, multiple or all tables:
cr> select * from stats.shards where table_name not like 'my_table%' and num_docs > 0
... order by table_name, size
+------------------------+-----------+----------+---------+-----------------+----------+------+---------+------------+
| node_id | node_name | num_docs | primary | relocating_node | shard_id | size | state | table_name |
+------------------------+-----------+----------+---------+-----------------+----------+------+---------+------------+
| ... | crate | 6 | True | NULL | 1 | ... | STARTED | locations |
| ... | crate | 7 | True | NULL | 0 | ... | STARTED | locations |
| ... | crate | 1 | True | NULL | 1 | ... | STARTED | quotes |
| ... | crate | 2 | True | NULL | 0 | ... | STARTED | quotes |
+------------------------+-----------+----------+---------+-----------------+----------+------+---------+------------+
SELECT 4 rows in set (... sec)
Aggregate functions are supported with grouping:
cr> select count(*), table_name from stats.shards where table_name not like 'my_table%'
... group by table_name order by table_name
+----------+------------+
| COUNT(*) | table_name |
+----------+------------+
| 10 | documents |
| 2 | locations |
| 6 | myblobs |
| 2 | quotes |
+----------+------------+
SELECT 4 rows in set (... sec)
..and without:
cr> select max(num_docs) from stats.shards where table_name = 'locations' and state = 'STARTED'
+---------------+
| MAX(num_docs) |
+---------------+
| 7 |
+---------------+
SELECT 1 row in set (... sec)