# Metrics and Logs API

## Authentication

Authentication is performed using an API key generated in the [API Keys section](https://docs.groundcover.com/use-groundcover/remote-access-and-apis/api-keys) of the Groundcover console.

All API requests must include the API key in the Authorization header using the following format:

```
Authorization: Bearer <YOUR_API_KEY>
```

## Raw Prometheus API for Metrics

Use the following endpoint to query the groundcover Prometheus API:

```bash
https://app.groundcover.com/api/prometheus/api/v1/query
```

To see usage example on how to query metrics in groundcover see: [Query metrics examples](https://docs.groundcover.com/use-groundcover/remote-access-and-apis/api-examples/query-metrics)

For a complete Prometheus REST API documentation, and available operations, see: [Prometheus HTTP API](https://prometheus.io/docs/prometheus/latest/querying/api/)

## Logs API

Use the following endpoint to query the groundcover logs API:

```bash
https://app.groundcover.com/api/logs/v2/query
```

To see usage examples on how to query logs in groundcover see: [Query logs examples](https://docs.groundcover.com/use-groundcover/remote-access-and-apis/api-examples/query-logs)

## Legacy API (Clickhouse)

The following configurations are deprecated but may still be in use in older setups.

{% hint style="warning" %}
The legacy datasources us using a different API key than described above. The API key can be obtained by running: `groundcover auth get-datasources-api-key`
{% endhint %}

You can query the legacy API to execute SQL statements directly on the Clickhouse database.

Try the following structure:

```bash
curl https://ds.groundcover.com/ \
    -H "X-ClickHouse-Key: <DS-API-KEY-VALUE>" \
    --data "SELECT count() FROM logs LIMIT 1 FORMAT JSON" 
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.groundcover.com/use-groundcover/remote-access-and-apis/raw-prometheus-and-clickhouse.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
