# Retrieve Prometheus metrics

Returns one complete UTC minute of transaction and receiver gauges in Prometheus text format. Data is 3 minutes behind. Requires the usage:read scope.

Source: https://zerocopy.sh/docs/reference/management-api/retrieve-prometheus-metrics

`GET https://console.zerocopy.sh/api/v1/metrics`

Authentication: API key, one of: `Authorization: Bearer` header.

## Responses

### 200

Minute gauges with explicit millisecond timestamps. Cache hits do not count toward the team's concurrent query limit.

| Header | Type | Description |
| --- | --- | --- |
| `X-Metrics-Cache` | `"hit"` or `"miss"` | hit or miss for the team and minute cache |

Content type: `text/plain; version=0.0.4; charset=utf-8`

Prometheus text exposition 0.0.4; every metric is a gauge with an explicit minute-end millisecond timestamp

```text title="One complete UTC minute"
# HELP zerocopy_key_info Key name, customer and state; value 1.
# TYPE zerocopy_key_info gauge
zerocopy_key_info{key_id="key_012345abcdef",name="Primary sender",customer="example-client",state="active"} 1 1794536040000
zerocopy_key_info{key_id="key_89abcdef0123",name="Research sender",customer="example-research",state="active"} 1 1794536040000
# HELP zerocopy_swqos_transactions Transactions by outcome in the minute. Data is 3 minutes behind.
# TYPE zerocopy_swqos_transactions gauge
zerocopy_swqos_transactions{key_id="key_012345abcdef",metro="fra",outcome="landed"} 3 1794536040000
zerocopy_swqos_transactions{key_id="key_89abcdef0123",metro="fra",outcome="expired"} 1 1794536040000
zerocopy_swqos_transactions{key_id="key_89abcdef0123",metro="lon",outcome="failed"} 1 1794536040000
# HELP zerocopy_swqos_slots_to_land Slots from send to successful landing, landed transactions only. Data is 3 minutes behind.
# TYPE zerocopy_swqos_slots_to_land gauge
zerocopy_swqos_slots_to_land{key_id="key_012345abcdef",metro="fra",quantile="0.5"} 2 1794536040000
zerocopy_swqos_slots_to_land{key_id="key_012345abcdef",metro="fra",quantile="0.9"} 2 1794536040000
zerocopy_swqos_slots_to_land{key_id="key_012345abcdef",metro="fra",quantile="0.99"} 2 1794536040000

```

### 400

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Invalid request"
{
  "title": "Bad request",
  "status": 400,
  "code": "invalid_request",
  "detail": "The request does not match the schema.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 401

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown, revoked or expired management key"
{
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The management key is unknown, revoked or expired.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 403

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="IP restriction"
{
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden_ip",
  "detail": "This key does not allow requests from this address.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 404

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown route"
{
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No such route.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 429

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Management read limit"
{
  "title": "Too many requests",
  "status": 429,
  "code": "rate_limited",
  "detail": "This key may make 600 such requests a minute.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

```json title="Concurrent analytics limit"
{
  "title": "Too many requests",
  "status": 429,
  "code": "analytics_busy",
  "detail": "This team already has two analytics reads running.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

## Code samples

```rust title="Rust"
// src/bin/management_metrics.rs
use swqos_examples::swqos::{Result, required};

#[tokio::main]
async fn main() -> Result<()> {
    let response = reqwest::Client::new()
        .get("https://console.zerocopy.sh/api/v1/metrics")
        .bearer_auth(required("MANAGEMENT_API_KEY")?)
        .send()
        .await?;
    let status = response.status();
    let body = response.text().await?;
    if !status.is_success() {
        return Err(format!("HTTP {status}: {body}").into());
    }
    print!("{body}");
    Ok(())
}
```

```go title="Go"
// management-metrics/main.go
package main

import (
    "fmt"
    "io"
    "log"
    "net/http"

    swqos "swqos-examples"
)

func main() {
    if err := run(); err != nil {
        log.Fatal(err)
    }
}

func run() error {
    apiKey, err := swqos.Required("MANAGEMENT_API_KEY")
    if err != nil {
        return err
    }
    request, err := http.NewRequest(http.MethodGet, "https://console.zerocopy.sh/api/v1/metrics", nil)
    if err != nil {
        return err
    }
    request.Header.Set("Authorization", "Bearer "+apiKey)
    response, err := http.DefaultClient.Do(request)
    if err != nil {
        return err
    }
    defer response.Body.Close()
    body, err := io.ReadAll(response.Body)
    if err != nil {
        return err
    }
    if response.StatusCode < 200 || response.StatusCode >= 300 {
        return fmt.Errorf("HTTP %d: %s", response.StatusCode, body)
    }
    fmt.Print(string(body))
    return nil
}
```

```ts title="TypeScript"
// management-metrics.ts
const apiKey = process.env.MANAGEMENT_API_KEY
if (!apiKey) throw new Error('set MANAGEMENT_API_KEY')

const response = await fetch('https://console.zerocopy.sh/api/v1/metrics', {
  headers: { authorization: `Bearer ${apiKey}` },
})
const body = await response.text()
if (!response.ok) throw new Error(`HTTP ${response.status}: ${body}`)
console.log(body)

export {}
```
