# Read a service's metrics

Source: https://openpanel.sh/docs/api/services/read-a-service-s-metrics

CPU, memory, network and restarts of each of its replicas over the range, from the samples its servers' agents report every few seconds. Anyone who can see the service may read them.

`GET https://openpanel.sh/api/v1/services/{serviceId}/metrics`

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `serviceId` | path | yes | The service's id. |
| `range` | query | no | How far back: 1h, 6h, 24h, 7d or 30d. Default 1h. |

## Responses

| Status | Meaning | Body |
|---|---|---|
| 200 | Read a service's metrics | `application/json`, `ServiceMetrics` |
| 401 | No valid credential was sent. | `application/problem+json`, `Problem` |
| 403 | The credential may not do this. | `application/problem+json`, `Problem` |
| 404 | Not found, or not visible to this credential. | `application/problem+json`, `Problem` |
| 422 | The input was refused; detail says why. | `application/problem+json`, `Problem` |
| 429 | Too many requests; wait for Retry-After seconds. | `application/problem+json`, `Problem` |

## Schemas

### Problem

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "description": "A link to the error's explanation in the docs."
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "integer"
    },
    "code": {
      "type": "string",
      "description": "Stable machine-readable code: not_found, forbidden, invalid, conflict, rate_limited, not_implemented, …"
    },
    "detail": {
      "type": "string",
      "description": "What went wrong, in a sentence written for a person."
    }
  },
  "required": [
    "type",
    "title",
    "status",
    "code",
    "detail"
  ]
}
```

### ServiceMetrics

```json
{
  "type": "object",
  "properties": {
    "serviceId": {
      "type": "string",
      "format": "uuid"
    },
    "range": {
      "type": "string",
      "enum": [
        "1h",
        "6h",
        "24h",
        "7d",
        "30d"
      ]
    },
    "step": {
      "type": "integer",
      "description": "Seconds between points."
    },
    "start": {
      "type": "string",
      "format": "date-time"
    },
    "end": {
      "type": "string",
      "format": "date-time"
    },
    "cpu": {
      "type": "object",
      "properties": {
        "unit": {
          "type": "string"
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "replica": {
                "type": "integer"
              },
              "container": {
                "type": "string"
              },
              "serverId": {
                "type": "string"
              },
              "deploymentId": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                },
                "description": "[unix seconds, value], oldest first."
              }
            },
            "required": [
              "replica",
              "container",
              "serverId",
              "deploymentId",
              "points"
            ]
          },
          "description": "One line per replica."
        }
      },
      "required": [
        "unit",
        "series"
      ],
      "description": "Percent of one CPU core."
    },
    "memory": {
      "type": "object",
      "properties": {
        "unit": {
          "type": "string"
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "replica": {
                "type": "integer"
              },
              "container": {
                "type": "string"
              },
              "serverId": {
                "type": "string"
              },
              "deploymentId": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                },
                "description": "[unix seconds, value], oldest first."
              }
            },
            "required": [
              "replica",
              "container",
              "serverId",
              "deploymentId",
              "points"
            ]
          },
          "description": "One line per replica."
        }
      },
      "required": [
        "unit",
        "series"
      ],
      "description": "Bytes in use."
    },
    "networkRx": {
      "type": "object",
      "properties": {
        "unit": {
          "type": "string"
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "replica": {
                "type": "integer"
              },
              "container": {
                "type": "string"
              },
              "serverId": {
                "type": "string"
              },
              "deploymentId": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                },
                "description": "[unix seconds, value], oldest first."
              }
            },
            "required": [
              "replica",
              "container",
              "serverId",
              "deploymentId",
              "points"
            ]
          },
          "description": "One line per replica."
        }
      },
      "required": [
        "unit",
        "series"
      ],
      "description": "Bytes received per second."
    },
    "networkTx": {
      "type": "object",
      "properties": {
        "unit": {
          "type": "string"
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "replica": {
                "type": "integer"
              },
              "container": {
                "type": "string"
              },
              "serverId": {
                "type": "string"
              },
              "deploymentId": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                },
                "description": "[unix seconds, value], oldest first."
              }
            },
            "required": [
              "replica",
              "container",
              "serverId",
              "deploymentId",
              "points"
            ]
          },
          "description": "One line per replica."
        }
      },
      "required": [
        "unit",
        "series"
      ],
      "description": "Bytes sent per second."
    },
    "restarts": {
      "type": "object",
      "properties": {
        "unit": {
          "type": "string"
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "replica": {
                "type": "integer"
              },
              "container": {
                "type": "string"
              },
              "serverId": {
                "type": "string"
              },
              "deploymentId": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "type": "array",
                  "prefixItems": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "number"
                    }
                  ],
                  "items": false,
                  "minItems": 2,
                  "maxItems": 2
                },
                "description": "[unix seconds, value], oldest first."
              }
            },
            "required": [
              "replica",
              "container",
              "serverId",
              "deploymentId",
              "points"
            ]
          },
          "description": "One line per replica."
        },
        "total": {
          "type": "integer",
          "description": "Restarts within the range, all replicas together."
        }
      },
      "required": [
        "unit",
        "series",
        "total"
      ],
      "description": "Each container's restart counter."
    }
  },
  "required": [
    "serviceId",
    "range",
    "step",
    "start",
    "end",
    "cpu",
    "memory",
    "networkRx",
    "networkTx",
    "restarts"
  ]
}
```