GET Logs Usage
You can use the "GET Logs Usage" request method to retrieve data usage for all logs in the specified time range. The results will be sorted in ascending order of data received. Note that this API call returns the value of all log usage in bytes.
Authentication
Before you start, make sure that you have an API key with Read/Write privileges.
URL
Use the following URL format for your API call:
1https://REGION.rest.logs.insight.rapid7.com/usage/organizations/logs?time_range=Last7Days&interval=day
Change REGION
to match the data center for your account, such as us
, eu
, ca
or au
.
URL Parameters
Change from
and to
to match the date range you want to use. Date values must be in ISO 8601 form, such as the following:
- from = YYYY-MM-DD
- to = YYYY-MM-DD
Aggregated usage data is available for the last seven days. Alternatively, you can specify a relative time range using time_range=Last7Days
. At this time, only Day
is available as a supported interval.
However, if a log has not received data, it will not appear in the results for that day.
Success Response
The success response code for this API call is HTTP 200. The content of the successful response looks similar to the following:
1{2"per_day_usage": {3"usage": [4{5"interval": "2018-12-16",6"log_usage": [7{8"usage": 8267539,9"id": "b2f37a6f-"10},11{12"usage": 9289532,13"id": "cec3450b-"14},15{16"usage": 12627779,17"id": "adc221c6-"18}19...20]21},22{23"interval": "2018-12-17",24"log_usage": [25{26"usage": 7648949,27"id": "50499f85-"28},29{30"usage": 7764258,31"id": "b2f37a6f-"32}33...34]35},36{37"interval": "2018-12-18",38"log_usage": [39{40"usage": 8388395,41"id": "50499f85-"42},43{44"usage": 8596388,45"id": "cec3450b-"46},47{48"usage": 12257438,49"id": "adc221c6-"50}51...52]53}54],55"period": {56"to": "2018-12-18",57"from": "2018-12-16"58},59"usage_units": "bytes",60"report_interval": "day"61}62}
Sample Call
The following is a sample API call for GET Logs Usage:
1import requests2import json3import time456API_KEY = 'Read/Write API Key'78def handle_response(resp):9response = resp10time.sleep(1)11if response.status_code == 200:12print json.dumps(resp.json(), indent=4)13else:14print response.status_code1516def make_request(provided_url=None):17headers = {'x-api-key': API_KEY}18url = "https://us.rest.logs.insight.rapid7.com/usage/organizations/logs?time_range=Last3Days&interval=day"19req = requests.get(url, headers=headers)20return req212223def get_usage():24req = make_request()25handle_response(req)2627def start():28get_usage()293031if __name__ == '__main__':32start()