How can I get the number of records in a SOW topic?
There several ways to get the number of records in a SOW topic without pulling every record into the client. Here are the best ways in order of preference:
You can request a
stats
acknowledgement with aTopN
value of 0 in asow
query. This will execute a SOW query against the topic, but not return any records to your client. After the query is complete, AMPS will return astats
acknowledgement to your client containing the total number of messages evaluated for the query. If you're using just a single topic (not a regex pattern covering multiple topics) then this number is the number of records within the SOW topic. This approach has the advantage that you can run the exact query that you need information on, including content filtering and regex topics.You can subscribe to the
/AMPS/SOWStats
topic (or query it if you're capturing it to its own SOW topic). AMPS publishes statistics information to this topic. You can find more details on this approach in the AMPS User Guide. With this approach, you only get information about whole topics, and you need to monitor, and store messages from the subscription (or the results of the query) to be able to use the information.You can issue a HTTP GET request to the Administrative interface programmatically and get the number of "valid_keys" for the SOW topic. More information on that approach is available in the AMPS Monitoring Reference. This may be the best way to get the information if you need the number of records for an application (like a dashboard) that is already using the Administrative interface, and that doesn't otherwise use the AMPS client libraries.
The Galvanometer shows the currently valid keys for the topic. In recent versions of AMPS, the Galvanometer also supports running a query (using the Javascript client application included in the Galvanometer) that can receive a
stats
acknowledgement to show the number of records that match a particular filter.
The bottom line is that there are several ways to get the information. AMPS supports both providing the total number of keys in the topic and running a query without delivering messages to determine the number of records that match a specific filter.
Last updated