Warning: You are viewing an old version (0.8) of this documentation. We recommend you view the latest version 1.2.
REST Client Library API

Statistics

The Ably service retains usage statistics per application and per account at 1 minute intervals. Your application statistics are available programmatically through our client libraries at 1 minute intervals, or aggregated up to the hour, day, or month.

Your most recent statistics are delayed by up to 6 seconds.

Your application and account statistics are also available as graphs, tabular data or downloads in your application dashboard.

The Ably service aggregates your application statistics by minute, hour, day and month, both at an application level and at an account level. Account level statistics are not available via the client library APIs and must be viewed using your account dashboard. Your monthly quota and any potential overages are calculated using the account level statistics. Find out what happens if you exceed your package limits.

Getting started

The Ably Rest client library provides a straightforward API for retrieving application statistics:

var rest = new Ably.Rest('xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w');
rest.stats({ unit: 'hour' }, function(err, resultPage) {
  var thisHour = resultPage.items[0];
  console.log(this.hour) // => {all: a, inbound: f, outbound: f, …}
);
var rest = new Ably.Rest('xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w');
rest.stats({ unit: 'hour' }, function(err, resultPage) {
  var thisHour = resultPage.items[0];
  console.log(this.hour) // => {all: a, inbound: f, outbound: f, …}
);
rest = Ably::Rest.new('xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w')
result_page = rest.stats(unit: 'hour')
this_hour = result_page.items.first
puts this_hour # => #<Ably::Models::Stat:…
rest = AblyRest('xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w')
result_page = rest.stats(unit='hour')
this_hour = result_page.items[0]
print(this_hour) # => ably.types.stats.Stats
$rest = new Ably\AblyRest('xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w');
$resultPage = $rest->stats(array('unit' => 'hour'));
$thisHour = $resultPage->items[0];
echo('Published this hour ' . $thisHour->inbound->all->all->count);
AblyRest rest = new AblyRest("xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w");
Params options = new Param[]{ new Param("unit", "hour") }
PaginatedResult<Stats> results = rest.stats(options);
Stats thisHour = results.items[0];
System.out.println("Published this hour " + thisHour.inbound.all.all.count);
AblyRest rest = new AblyRest("xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w");
StatsRequestParams query = new StatsRequestParams() { Unit = StatsIntervalGranularity.Hour };
PaginatedResult<Stats> results = await rest.StatsAsync(query);
Stats thisHour = results.Items[0];
Console.WriteLine("Published this hour " + thisHour.Inbound.All.All.Count);
ARTRest *rest = [[ARTRest alloc] initWithKey:@"xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w"];
ARTStatsQuery *query = [[ARTStatsQuery alloc] init];
query.unit = ARTStatsGranularityHour;
[rest stats:query callback:^(ARTPaginatedResult<ARTStats *> *result, ARTErrorInfo *error) {
    ARTStats *thisHour = result.items[0];
    NSLog(@"Published this hour %lu", thisHour.inbound.all.all.count);
} error:nil];
let rest = ARTRest(key: "xVLyHw.vKcU5Q:aZcyqRAf--kjGlwrJ8n_vNShtnVp8jQC8cFWNy4Im1w")
let query = ARTStatsQuery()
query.unit = .Hour
try! rest.stats(query) { results, error in
    let thisHour = results!.items[0]
    print("Published this hour \(thisHour.inbound.all.all.count)")
}

API Reference

View the Statistics API Reference.


Need help?

If you need any help with your implementation or if you have encountered any problems, do get in touch. You can also quickly find answers from our knowledge base, and blog.