Use the Log Analytics API to quickly build custom reports and dashboards for your team by combining information from your business and other services alongside log data.
Use of the Log Analytics API requires an API key and an application key. The user who created the application key must have the appropriate permission to access the data. To use the examples below, replace <DATADOG_API_KEY> and <DATADOG_APP_KEY> with your Datadog API key and your Datadog application key, respectively.
This guide also assumes that you have a terminal with curl.
With the following API call, build a table with avg of values in a metric such as @http.response_time grouped by the field status. The type must be total.
Similarly, you can build an avg timeseries by setting type as timeseries.
With the following API call, build a table with sum of values in a metric such as @http.response_time grouped by the field service. The type must be total.
With the following API call, build a table with min of values in a metric such as @http.response_time grouped by the field service. The type must be total.
With the following API call, build a table with max of values in a metric such as @http.response_time grouped by the field service. The type must be total.
With the following API call, build a table with percentiles of values in a metric such as @http.response_time grouped by the field service. The type must be total. The different percentile values available are pc75,pc90,pc95,pc98,and pc99.
With the following API call, build a table to display the breakdown of your log data by facets such as OS and Browser and calculate different metrics such as unique count of useragent, pc90 of metric duration, avg of metric network.bytes_written, and the total count of log events.
{"meta":{"status":"done","request_id":"dkt3bGhON0lSOEdCVWFqa3pyUEtNUXxzU0p5RG1qN3MwNk45aExrazFGTTR3","elapsed":1299},"data":{"buckets":[{"computes":{"c3":534310,"c2":29855.686900195342,"c1":289880482.9557167,"c0":430},"by":{"@http.useragent_details.browser.family":"Chrome","@http.useragent_details.os.family":"Mac OS X"}},{"computes":{"c3":47973,"c2":25117.50770936209,"c1":270379443.2579185,"c0":64},"by":{"@http.useragent_details.browser.family":"Firefox","@http.useragent_details.os.family":"Mac OS X"}},{"computes":{"c3":901506,"c2":9170.975124352715,"c1":235075236.08510733,"c0":342},"by":{"@http.useragent_details.browser.family":"Other","@http.useragent_details.os.family":"Other"}},{"computes":{"c3":2734,"c2":953181.3177150192,"c1":200800000.00000006,"c0":45},"by":{"@http.useragent_details.browser.family":"Apache-HttpClient","@http.useragent_details.os.family":"Other"}}]}}
In the response, c0 represents the unique count of useragent, c1 represents the pc90 of metric duration, c2 represents the avg of metric network.bytes_written, and c3 represents the total count of log events.
The following API call builds a table to display the breakdown of your log data by facets (such as service and status), sorts the results by service in ascending order, and paginates over the result set using limit.
Note: Paging is only supported if sort is alphabetical for at least one facet as shown in above example. To build a report with multiple group-bys with high cardinality facets, make separate API calls. For example, to build a report showing different metrics for url paths for every session id, make separate API calls. The first call would return all sessions ids sorted and you would use these results to get the metrics for url paths for each session id.