Database Logs API

Overview

The Database Logs API enables secure retrieval of log data stored in the Log Archive.

The Database Logs API is accessed by REST client.

The Database Logs API is part of the Observability API.

Authentication

Generate an API Key

Before using the Logs API, a SkySQL API Key must be generated. The SkySQL API Key must have the Observability API: Read key scope.

For additional information, see "Generate a SkySQL API Key".

Obtain a Bearer Token

The SkySQL API Key is not used directly with the Logs API. Instead, the SkySQL API Key is used to request a short-lived bearer token from MariaDB ID, and the short-lived bearer token is used with the Logs API.

For example, to request a bearer token using cURL with the output piped to jq for readability:

$ curl --location --request POST \
   --header 'Authorization: Token SKYSQL_API_KEY' \
   --header 'Content-length: 0' \
   https://id.mariadb.com/api/v1/token/ \
   | jq .

For additional information, see "Request a Bearer Token".

Make API calls

When making API calls, the short-lived bearer token must be provided in a header using the format Authorization: Bearer SKYSQL_BEARER_TOKEN, where SKYSQL_BEARER_TOKEN is the short-lived bearer token.

For example, to call the Log List endpoint using cURL:

$ curl --location --request GET \
   --header "Authorization: Bearer SKYSQL_BEARER_TOKEN" \
   'https://api.mariadb.com/observability/v1/logs'

Supported Log Types

The following log types are supported by the Database Logs API.

See log-specific documentation for details on log format and steps to configure logging.

Log Type

Description

audit-log

MariaDB Enterprise Audit Logs

error-log

Error Logs

slow-query-log

Slow Query Logs

maxscale-log

MaxScale Logs

List Servers with Logs

Detail

Description

Endpoint

https://api.mariadb.com/observability/v1/logs/servers

Method

GET

Behavior

  • Returns JSON with an array of servers.

  • Request parameters define criteria for servers to return.

  • If no request parameters are supplied, all known servers with logs are returned.

Parameters

  • logType - log types to return, multiple values comma-separated or one value

  • fromDate - start of time range to return, example: fromDate=2021-07-16T01:16:18Z

  • toDate - end of time range to return, example: toDate=2021-08-16T01:16:18Z

Response Code

200 - Success (expected)

Sample Request

https://api.mariadb.com/observability/v1/logs/servers?logType=error-log,slow-query-log&fromDate=2022-05-31T21:00:00.000Z&toDate=2022-07-31T21:00:00.000Z

Command-Line Example

$ curl --location --request GET \
   --header "Authorization: Bearer SKYSQL_BEARER_TOKEN" \
   'https://api.mariadb.com/observability/v1/logs/servers?logType=error-log,slow-query-log&fromDate=2022-05-31T21:00:00.000Z&toDate=2022-07-31T21:00:00.000Z' \
  | jq .

Sample Response

{
  "servers": [
    {
      "service": "cs",
      "server": "cs-node-1",
      "serverDataSourceId": "db00012334/cs-node-1"
    }
  ]
}

List Logs

Detail

Description

Endpoint

https://api.mariadb.com/observability/v1/logs

Method

GET

Behavior

  • Returns JSON with one object per log.

  • Request parameters define criteria for logs to return.

  • If no request parameters are supplied, all known logs are returned.

Parameters

  • limit - maximum count of log objects to return

  • offset - enables pagination when combined with limit

  • logType - log types to return, multiple values comma-separated or one value

  • fromDate - start of time range to return, example: fromDate=2021-07-16T01:16:18Z

  • toDate - end of time range to return, example: toDate=2021-08-16T01:16:18Z

  • serverContext - server name, multiple values comma-separated or one value, example: db00012334/cs-node-1

Response Code

200 - Success (expected)

Sample Request

https://api.mariadb.com/observability/v1/logs?limit=20&offset=0&fromDate=2021-07-16T01:16:18Z&toDate=2021-08-16T01:16:18Z&serverContext=db00012334/cs-node-1

Command-Line Example

$ curl --location --request GET \
   --header "Authorization: Bearer SKYSQL_BEARER_TOKEN" \
   'https://api.mariadb.com/observability/v1/logs?limit=20&offset=0&fromDate=2021-07-16T01:16:18Z&toDate=2021-08-16T01:16:18Z&serverContext=db00012334/cs-node-1' \
  | jq .

Sample Response

{
  "count": 2,
  "logs": [
    {
      "id": "eda604f7c5160b14d3223d5ae7737964d6efad66fe635d1509a4b7331f3ab838",
      "name": "error-log_2022-07-30.log",
      "logType": "error-log",
      "service": "cs",
      "server": "cs-node-1",
      "serverDataSourceId": "db00012334/cs-node-1",
      "size": 18788,
      "startTime": "2022-07-30T00:00:00Z",
      "endTime": "2022-07-30T23:59:59Z"
    },
    {
      "id": "ee310a1c7f5c684f1c85f78648c898a7b8f28757901db93ab93e4455c5fd7d3f",
      "name": "error-log_2022-07-22.log",
      "logType": "error-log",
      "service": "cs",
      "server": "cs-node-1",
      "serverDataSourceId": "db00012334/cs-node-1",
      "size": 18950,
      "startTime": "2022-07-22T00:00:00Z",
      "endTime": "2022-07-22T23:59:59Z"
    }
  ]
}

Download a Log Archive

Detail

Description

Endpoint

https://api.mariadb.com/observability/v1/logs/archive

Method

GET

Behavior

  • Returns binary data in .zip archive format. The .zip archive contains the requested logs.

  • Request parameters define criteria for logs to return.

Parameters

  • logIds (required) - list of logs to be archived. If the parameter is not provided, the API returns error code 400. The maximum number of logs that could be archived is 100. If the maximum number is reached, the API returns an error.

  • logFormat - possible values raw or json (multiple values are allowed in comma-separated format). If the parameter is missing, the default format is json.

  • expireIn - interval in minutes setting how long the signed URL will be available.

Response Code

200 - Success (expected)

Sample Request

https://api.mariadb.com/observability/v1/logs/archive?logsIds=eda604f7c5160b14d3223d5ae7737964d6efad66fe635d1509a4b7331f3ab838,iee310a1c7f5c684f1c85f78648c898a7b8f28757901db93ab93e4455c5fd7d3f&logFormat=raw,json

Command-Line Example

$ curl --location --request GET \
   --header "Authorization: Bearer SKYSQL_BEARER_TOKEN" \
   -o archive_file.zip \
   'https://api.mariadb.com/observability/v1/logs/archive?logsIds=eda604f7c5160b14d3223d5ae7737964d6efad66fe635d1509a4b7331f3ab838,iee310a1c7f5c684f1c85f78648c898a7b8f28757901db93ab93e4455c5fd7d3f&logFormat=raw,json'

Sample Response

Binary data in the form of a .zip archive containing the requested logs.