> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/metrics-aggregation-api.md).

# Metrics Aggregation API

Read, configure and clear streaming metric aggregation.

### Authentication and permissions

Use an [API key](https://docs.groundcover.com/administer/api-keys.md) in `Authorization: Bearer <YOUR_API_KEY>` and select the backend with `X-Backend-Id: <YOUR_BACKEND_ID>`. Use your own API base URL for a self-hosted deployment.

**Admin required:** creating, replacing or clearing aggregation configuration. Reading the saved or default configuration requires backend access but does not require Admin permissions.

The configuration example uses `jq`; install it before running the example. It builds the JSON request body from a readable configuration file.

### Endpoints

| Method | Endpoint                                      | Purpose                                                    |
| ------ | --------------------------------------------- | ---------------------------------------------------------- |
| GET    | `/api/aggregations/v1/metrics/config`         | Read the saved configuration.                              |
| GET    | `/api/aggregations/v1/metrics/config/default` | Read the default configuration.                            |
| POST   | `/api/aggregations/v1/metrics/config`         | **Admin required.** Write configuration (HTTP 201).        |
| PUT    | `/api/aggregations/v1/metrics/config`         | **Admin required.** Replace configuration (HTTP 200).      |
| DELETE | `/api/aggregations/v1/metrics/config`         | **Admin required.** Clear custom configuration (HTTP 200). |

### Read configuration

```bash
curl --request GET 'https://api.groundcover.com/api/aggregations/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>'
```

```bash
curl --request GET 'https://api.groundcover.com/api/aggregations/v1/metrics/config/default' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>'
```

The saved-configuration response contains `uuid`, `created_by`, `created_timestamp`, and `value`; no saved configuration returns HTTP 204. The defaults endpoint returns `{"value": "..."}`.

Append `| jq -r '.value'` to either GET command to print the configuration text with its original line breaks.

### Configure aggregation

POST and PUT require an **outer JSON request body** with a `value` string. The server parses that string as YAML; JSON configuration text is also accepted by this parser. The configuration's `content` field is itself a string containing YAML or JSON stream aggregation rules. In the example below, YAML's `|` block keeps those rules readable. Other configuration fields include `keepInput`, `dropInput`, `dropInputLabels`, `dedupInterval`, `ignoreOldSamples`, `ignoreFirstIntervals`, `enableWindows`, `keepMetricNames`, `noAlignFlushToInterval`, and `flushOnShutdown`.

This example keeps the original input series and additionally aggregates an example counter by service. Replace the full configuration only after preserving any existing rules you need.

```bash
cat > metrics-aggregation.yaml <<'YAML'
keepInput: true
content: |
  - match: "example_requests_total"
    interval: 1m
    by: [__name__, service]
    outputs: [total]
YAML

jq -n --rawfile value metrics-aggregation.yaml '{value: $value}' |
curl --request PUT 'https://api.groundcover.com/api/aggregations/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --header 'Content-Type: application/json' \
  --data-binary @-
```

`keepInput` controls retaining samples that match aggregation rules; `dropInput` controls dropping unmatched samples. Review both when changing storage behavior. Invalid or uncompilable aggregation rules return HTTP 400.

### Clear custom configuration

```bash
curl --request DELETE 'https://api.groundcover.com/api/aggregations/v1/metrics/config' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>'
```

The response is HTTP 200 with no body. To understand aggregation configuration and its effect on ingested metrics, see [Metrics Aggregation](https://docs.groundcover.com/collect-data/data-pipelines/metrics-aggregation.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/metrics-aggregation-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
