org.forgerock.openam.monitoring.session.CtsSessionsImpl offers a means of getting a count of the number of sessions stored in CTS: getSumCTSSessions.
This method delegates to org.forgerock.openam.cts.monitoring.impl.persistence.CtsPersistenceOperationsMonitor#getTotalCount() which performs the following call to OpenDJ:
There appear to be a number of problems with this approach:
1) It's likely to be very slow and may even fail to run: Reading the ID attribute of all CTS tokens and then taking a count of the number entries returns may hit OpenDJ read limits or time limits and leads to far more data being transmitted from OpenDJ to OpenAM than is necessary. The same result could be obtained far more efficiently by asking for the numSubOrdinates operation attribute from the CTS root DN.
2) It answers the wrong question: Given that CtsSessionsImpl should likely be answering the question "how many sessions are stored in CTS" or even "how many active sessions are stored in CTS". Unfortunately, neither of these questions can be answered with a simple numSubOrdinates read.