# List metrics

List a source's or an application's ingested and user-defined metrics.

[endpoint]
method = "GET"
base_url = "https://telemetry.betterstack.com"
path = "/api/v4/metrics"

[[query_param]]
name = "source_id"
type = "string"
description = "Source whose metrics are listed. Send this or `application_id`."

[[query_param]]
name = "application_id"
type = "string"
description = "Error tracking application whose metrics are listed. Send this or `source_id`."

[[query_param]]
name = "name_filter"
type = "string"
description = "Only metrics whose name matches, ignoring letter case. Use `prefix*`, `*contains*`, `*suffix` or an exact name."

[[query_param]]
name = "order"
default = "cardinality"
type = "string"
description = "The order the metrics are listed in.<br/>Valid values:<br/>`cardinality`: Lists the metrics with the highest `active_series` first.<br/>`catalog`: Keeps the catalog's own order, with ingested metrics by name, then user-defined ones in the order they were created."

[[query_param]]
name = "page"
type = "integer"
description = "Page to return, starting at 1."

[[query_param]]
name = "per_page"
default = "50"
type = "integer"
description = "Results per page. Maximum 250."

[[query_param]]
name = "team_id"
type = "string"
description = "Team to use, such as `t123`. Get the ID via [List teams](/docs/uptime/api/teams/list/). Required when you can access more than one team."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[info]
#### Results are paginated
Use `pagination.next` and `pagination.prev` to move through pages or jump to a specific one using `page` and `per_page`. See [Pagination](/docs/getting-started/integrations/api/#pagination).
[/info]

[responses]
[[response]]
status = 200
description = "Returns the list of metrics."
body = '''
{
  "data": [
    {
      "id": "http_requests_total",
      "type": "source_metric",
      "attributes": {
        "name": "http_requests_total",
        "type": "float64",
        "origin": "ingested",
        "layout": "row-based",
        "aggregations": [
          "avg",
          "max",
          "min"
        ],
        "data_points": 182400,
        "active_series": 37,
        "sql_expression": null,
        "json_dot_notation": null,
        "query_examples": [
          "avgMergeIf(value_avg, name = 'http_requests_total')",
          "avgMergeIf(rate_avg, name = 'http_requests_total')   -- per-second rate, for counters"
        ],
        "labels": [
          "host",
          "method",
          "status"
        ]
      }
    }
  ],
  "pagination": {
    "first": "https://telemetry.betterstack.com/api/v4/metrics?page=1",
    "last": "https://telemetry.betterstack.com/api/v4/metrics?page=1",
    "prev": null,
    "next": null,
    "total_count": 1
  },
  "usage_available": true
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "errors": "Invalid Team API token. How to find your Team API token: https://betterstack.com/docs/logs/api/getting-started/#obtaining-a-logtail-api-token"
}
'''

[[response]]
status = 403
description = "Your role doesn't allow viewing this, or the token can't be used for this API."

[[response]]
status = 404
description = "No source or application with that ID."

[[response]]
status = 422
description = "Both or neither of `source_id` and `application_id` were sent."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the metric, such as `http_requests_total`."

[[param]]
name = "type"
type = "string"
description = "Always `source_metric`."

[[param]]
name = "name"
type = "string"
description = "Metric name."

[[param]]
name = "attributes.type"
type = "string"
description = "The data type the metric is stored as. Ingested metrics are `float64`. A user-defined metric has the type its definition sets."

[[param]]
name = "origin"
type = "string"
description = "Where the metric comes from.<br/>Valid values:<br/>`ingested`: The metric was sent to Better Stack as a metric.<br/>`user-defined`: The metric is defined from the source's logs."

[[param]]
name = "layout"
type = "string"
description = "How the metric is stored, which decides how to query it.<br/>Valid values:<br/>`row-based`: The metric shares the `value_*` columns with other metrics and is selected by `name`.<br/>`column-based`: The metric has columns of its own."

[[param]]
name = "aggregations"
type = "array of strings"
description = "Aggregations stored for the metric, such as `avg`, `max` and `min`."

[[param]]
name = "data_points"
type = "integer"
description = "Data points received in the last 24 hours."

[[param]]
name = "active_series"
type = "integer"
description = "Distinct series seen in the last 24 hours."

[[param]]
name = "sql_expression"
type = "string or null"
description = "The SQL expression a user-defined metric is defined by. `null` for an ingested metric or one defined by `json_dot_notation`. Returned by get only."

[[param]]
name = "json_dot_notation"
type = "string or null"
description = "The JSON field a user-defined metric is read from, when it's defined that way. Returned by get only."

[[param]]
name = "query_examples"
type = "array of strings"
description = "Expressions to select the metric with in a metrics query. Returned by get only."

[[param]]
name = "labels"
type = "array of strings or null"
description = "Labels seen on an ingested metric in the last 24 hours. `null` for a user-defined metric. Returned by get only."

[[param]]
name = "usage_available"
type = "boolean"
description = "Whether the usage of user-defined metrics was measured. `false` when it couldn't be measured in time, so their `data_points` and `active_series` show 0."

[[param]]
name = "pagination.first"
type = "string"
description = "The URL of the first page of results."

[[param]]
name = "pagination.last"
type = "string"
description = "The URL of the last page of results."

[[param]]
name = "pagination.prev"
type = "string or null"
description = "The URL of the previous page, or `null` on the first page."

[[param]]
name = "pagination.next"
type = "string or null"
description = "The URL of the next page, or `null` on the last page."

[[param]]
name = "pagination.total_count"
type = "integer"
description = "How many results the whole list holds, across every page."
[/params]

#### Example cURL

[code-tabs]
```shell
[label Metrics of a source]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/metrics?source_id=123456" \
  --header "Authorization: Bearer $TOKEN"
```
```shell
[label Filter by name]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/metrics?source_id=123456&name_filter=http_*" \
  --header "Authorization: Bearer $TOKEN"
```
[/code-tabs]
