Retrieve Operations Count and Days to Reset?

On the dashboard it’s possible to see the Operations Count and the Days to Reset.

Is it possible to obtain these numbers programatically so usage can be monitored without manually going in to the dashboard?

Hello @janetaubman!

You can retrieve the operations count metric from the Monitoring API, as such:

curl -X GET \
     -H "X-Algolia-API-Key: ${MONITORING_API_KEY}" \
     -H "X-Algolia-Application-Id: ${APPLICATION_ID}" \
     --compressed \
    "https://status.algolia.com/1/usage/total_operations/period/month"

This will return the last 30 days of values.

There is currently no way to programmatically retrieve the number of days left in your application’s billing month, but it always ends on the same date so you should be able to hardcode it in your scripts.

Let me know if you need any further assistance with this!

Cheers

Thanks for that. Am I correct in thinking the Monitoring API is only available with an Enterprise account.

I get a “blank” string back if I call the routine with my application id and monitoring key

Using PHP

function httpPost($url,$headers = null)
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    if ($headers != null) {
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
 }
    $response = curl_exec($curl);
    if (!$response) {
    var_dump(curl_error($curl));
    exit ;
    }
    curl_close($curl);
    return $response;
}

$url = 'https://status.algolia.com/1/usage/total_operations/period/month';
$headers =  array(
               'X-Algolia-Application-Id: '.'plSIJRKTUUU7',
               'X-Algolia-API-Key: '.'monitoring key',
                );

$result = httpPost($url,$headers);
var_dump($result);

Hey @janetaubman,

is this still happening?

I just tried using curl and it works fine:

curl -X GET \
  https://status.algolia.com/1/usage/total_operations/period/month \
  -H 'x-algolia-api-key: ALGOLIA_MONITORING_KEY' \
  -H 'x-algolia-application-id: plSIJRKTUUU7'

Still get nothing back, I assumed it was because I am on a free account so am not allowed monitoring tools. I get no response, but the curl error is blank, suggesting it ran through.

If I change the monitoring key to an invalid one I get invalid credentials back which suggests it’s calling the right place.

OK in that case, can you contact support@algolia.com , link this post for context and mention your APPID and the last 5 digits of your monitoring API key?

Thanks

Hello Jane,

As explained via our support, the issue comes from your PHP code trying to access the endpoint via a POST instead of a GET.

Have a nice day,

Thanks very much all resolved.