# Datasource API Keys (Legacy)

groundcover provides a robust user interface that allows you to view and analyze all your observability data from inside the platform. However, there may be cases in which you need to query the data from outside our platform using API communication.

Our proprietary eBPF sensor automatically captures granular observability data, which is stored via our integrations with two best-of-breed technologies. VictoriaMetrics for metrics storage, and ClickHouse for storage of logs, traces, and Kubernetes events.

Read more about our architecture [here](https://github.com/groundcover-com/docs/blob/main/use-groundcover/remote-access-and-apis/broken-reference/README.md).

{% hint style="warning" %}
Using the datasource API is not recommended (Legacy) as there are newer ways to use the API. You can refer to [Metrics and Logs API](/use-groundcover/remote-access-and-apis/raw-prometheus-and-clickhouse.md)
{% endhint %}

### Generate the API key

Run the following command in your CLI, and select tenant:

`groundcover auth get-datasources-api-key`

### **Querying ClickHouse**

Example for querying ClickHouse database using POST HTTP Request:

```bash
curl 'https://ds.groundcover.com/' \
        --header "X-ClickHouse-Key: ${API_KEY}" \
        --data "SELECT count() from traces where start_timestamp > now() - interval '15 minutes' "
```

#### Command parameters

* `X-ClickHouse-Key` (header): API Key you retrieved from the groundcover CLI. Replace `${API_KEY}` with your actual API key, or set `API_KEY` as env parameter.
* `SELECT count() FROM traces WHERE start_timestamp > now() - interval '15 minutes'` (data): The SQL query to execute. This query counts the number of traces where the `start_timestamp` is within the last 15 minutes.

Learn more about the ClickHouse query language [here](https://clickhouse.com/docs/en/sql-reference/statements/select).

### **Querying VictoriaMetrics**

Example for querying the VictoriaMetrics database using the [`query_range`](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries) API:

```bash
curl 'https://ds.groundcover.com/datasources/prometheus/api/v1/query_range' \
    --get \
    --header "apikey: ${API_KEY}" \
    --data 'query=sum(rate(groundcover_resource_total_counter{type="http"}))' \
    --data 'start=1715760000' \
    --data 'end=1715763600'
```

#### Command parameters

* `apikey` (header): API Key you retrieved from the groundcover CLI. Replace `${API_KEY}` with your actual API key, or set `API_KEY` as env parameter.
* `query` (data): The promql query to execute. In this case, it calculates the sum of the rate of `groundcover_resource_total_counter` with the `type` set to `http`.
* `start` (data): The start timestamp for the query range in Unix time (seconds since epoch). Example: `1715760000`.
* `end` (data): The end timestamp for the query range in Unix time (seconds since epoch). Example: `1715763600`.

Learn more about the promql syntax [here](https://prometheus.io/docs/prometheus/latest/querying/basics/).

Learn more about VictoriaMetrics HTTP API [here](https://prometheus.io/docs/prometheus/latest/querying/api/).


---

# 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/querying-you-data-using-an-api.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.
