Metrics API

Retrieve metrics and monitoring data for branches

The Metrics API allows you to retrieve performance and monitoring metrics for your database branches, including CPU, memory, and disk usage. All endpoints require authentication via API key or OIDC.

Authentication

All endpoints require authentication. You can authenticate using:

  • API Key: Include your API key in the Authorization header: Authorization: Bearer <your-api-key>
  • OIDC: Use OIDC tokens for authentication

Required scopes for different operations:

  • metrics:read: Access to metrics and monitoring data

Get branch metrics

Retrieves metrics for a specific branch over a time period.

POST /organizations/{organizationID}/projects/{projectID}/branches/{branchID}/metrics

Summary

Returns time-series metrics data for CPU, memory, and disk usage across branch instances. Supports multiple aggregation types and can filter by specific instances.

Path parameters

ParameterTypeRequiredDescription
organizationIDstringYesUnique identifier for the organization
projectIDstringYesUnique identifier for the project
branchIDstringYesUnique identifier for the branch

Request body

{
  "start": "2024-01-01T00:00:00Z",
  "end": "2024-01-01T23:59:59Z",
  "metric": "cpu",
  "instances": ["inst_123", "inst_456"],
  "aggregations": ["avg", "max", "min"]
}

Request body parameters

ParameterTypeRequiredDescription
startstring (date-time)YesStart time for the metrics query
endstring (date-time)YesEnd time for the metrics query
metricstringYesMetric name to query. Options: cpu, memory, disk
instancesarrayYesList of instance IDs to query
aggregationsarrayYesList of aggregations to apply. Options: avg, max, min

Response

Status: 200 OK

{
  "start": "2024-01-01T00:00:00Z",
  "end": "2024-01-01T23:59:59Z",
  "metric": "cpu",
  "unit": "percentage",
  "series": [
    {
      "instance": "inst_123",
      "aggregation": "avg",
      "data": [
        {
          "timestamp": "2024-01-01T00:00:00Z",
          "value": 25.5
        },
        {
          "timestamp": "2024-01-01T01:00:00Z",
          "value": 30.2
        }
      ]
    },
    {
      "instance": "inst_123",
      "aggregation": "max",
      "data": [
        {
          "timestamp": "2024-01-01T00:00:00Z",
          "value": 45.0
        },
        {
          "timestamp": "2024-01-01T01:00:00Z",
          "value": 52.1
        }
      ]
    }
  ]
}

Response schema

FieldTypeDescription
startstring (date-time)Start time of the metrics period
endstring (date-time)End time of the metrics period
metricstringThe metric type that was queried
unitstringThe unit of measurement (percentage, bytes, ms, etc.)
seriesarrayArray of metric series, one per instance and aggregation

Metric types

  • cpu: CPU usage percentage
  • memory: Memory usage in bytes
  • disk: Disk usage in bytes

Aggregation types

  • avg: Average value over the time interval
  • max: Maximum value over the time interval
  • min: Minimum value over the time interval

Error Handling

The API uses standard HTTP status codes and returns error responses in the following format:

{
  "id": "error_identifier",
  "message": "Human-readable error message explaining the issue"
}

Common error responses

StatusError TypeDescription
400GenericErrorRequest was malformed or contained invalid parameters
401AuthorizationErrorAuthentication failed or is missing
404GenericErrorRequested organization, project, or branch does not exist
5XXGenericErrorServer error occurred

Schema Reference

Core Data Models

BranchMetrics

Time-series metrics data for monitoring branch performance.

FieldTypeRequiredDescription
startstring (date-time)YesStart time of the metrics period
endstring (date-time)YesEnd time of the metrics period
metricstringYesThe metric type that was queried
unitstringYesThe unit of measurement (percentage, bytes, ms, etc.)
seriesarrayYesArray of metric series, one per instance and aggregation

BranchMetricsRequest

Parameters for querying branch metrics over a time period.

FieldTypeRequiredDescription
startstring (date-time)YesStart time for the metrics query
endstring (date-time)YesEnd time for the metrics query
metricstringYesMetric name to query. Options: cpu, memory, disk
instancesarrayYesList of instance IDs to query
aggregationsarrayYesList of aggregations to apply. Options: avg, max, min

MetricSeries

Individual metric series data for a specific instance and aggregation.

FieldTypeRequiredDescription
instancestringYesInstance ID for this metric series
aggregationstringYesAggregation type applied (avg, max, min)
dataarrayYesArray of timestamp-value pairs

MetricDataPoint

Individual data point in a metric series.

FieldTypeRequiredDescription
timestampstring (date-time)YesTimestamp for this data point
valuenumberYesMetric value at this timestamp

Usage Examples

Monitor CPU usage over time

curl -X POST "https://api.xata.tech/organizations/org_123/projects/proj_456/branches/br_789/metrics" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "start": "2024-01-01T00:00:00Z",
    "end": "2024-01-01T23:59:59Z",
    "metric": "cpu",
    "instances": ["inst_123"],
    "aggregations": ["avg", "max"]
  }'

Check memory usage for multiple instances

curl -X POST "https://api.xata.tech/organizations/org_123/projects/proj_456/branches/br_789/metrics" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "start": "2024-01-01T00:00:00Z",
    "end": "2024-01-01T23:59:59Z",
    "metric": "memory",
    "instances": ["inst_123", "inst_456"],
    "aggregations": ["avg"]
  }'