# Query Monitors Summary

### Endpoint

**POST** `/api/monitors/summary/query`

### Authentication

This endpoint requires API Key authentication via the Authorization header.

### Headers

```bash
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json
Accept: text/event-stream
```

### Request Body

The request body supports filtering, pagination, sorting, and time range parameters:

```json
{
  "conditions": [],
  "limit": 200,
  "skip": 0,
  "maxInstances": 10,
  "order": "desc",
  "sortBy": "lastFiringStart",
  "start": "2025-10-12T08:19:18.582Z",
  "end": "2025-10-12T09:19:18.582Z"
}
```

#### Request Parameters

| Parameter      | Type    | Required | Description                                                       |
| -------------- | ------- | -------- | ----------------------------------------------------------------- |
| `conditions`   | array   | No       | Array of filter conditions for monitors (empty array returns all) |
| `limit`        | integer | No       | Maximum number of monitors to return (default: 200)               |
| `skip`         | integer | No       | Number of monitors to skip for pagination (default: 0)            |
| `maxInstances` | integer | No       | Maximum instances per monitor result (default: 10)                |
| `order`        | string  | No       | Sort order: `"asc"` or `"desc"` (default: `"desc"`)               |
| `sortBy`       | string  | No       | Field to sort by (see sorting options below)                      |
| `start`        | string  | No       | Start time for filtering (ISO 8601 format)                        |
| `end`          | string  | No       | End time for filtering (ISO 8601 format)                          |

#### Sorting Options

| Sort Field          | Description                             |
| ------------------- | --------------------------------------- |
| `"lastFiringStart"` | Last time monitor started firing alerts |
| `"title"`           | Monitor title alphabetically            |
| `"severity"`        | Monitor severity level                  |
| `"createdAt"`       | Monitor creation date                   |
| `"updatedAt"`       | Last modification date                  |
| `"state"`           | Current monitor state                   |

#### Filter Conditions

The `conditions` array accepts filter objects for targeted monitor queries:

```json
{
  "conditions": [
    {
      "field": "severity",
      "operator": "equals",
      "value": "S1"
    },
    {
      "field": "state",
      "operator": "in",
      "values": ["Alerting", "Normal"]
    }
  ]
}
```

### Response

The endpoint returns a JSON object containing an array of detailed monitor configurations:

```json
{
  "hasMonitors": true,
  "monitors": [
    {
      "uuid": "string",
      "title": "string",
      "description": "string",
      "severity": "string",
      "measurementType": "string",
      "state": "string",
      "alertingCount": 0,
      "model": {
        "queries": [],
        "thresholds": []
      },
      "interval": {
        "interval": "string",
        "for": "string"
      },
      "executionErrorState": "string",
      "noDataState": "string",
      "isPaused": false,
      "createdBy": 0,
      "createdByEmail": "string",
      "createdAt": "string",
      "updatedAt": "string",
      "lastStateStart": "string",
      "lastFiringStart": "string",
      "firstFiringStart": "string",
      "lastResolved": "string",
      "minEvaluationDurationSeconds": 0.0,
      "avgEvaluationDurationSeconds": 0.0,
      "maxEvaluationDurationSeconds": 0.0,
      "lastEvaluationError": "string",
      "lastEvaluationTimestamp": "string",
      "silenced": false,
      "fullySilenced": false,
      "silence_uuids": []
    }
  ]
}
```

#### Response Fields

**Top-Level Fields**

| Field         | Type    | Description                              |
| ------------- | ------- | ---------------------------------------- |
| `hasMonitors` | boolean | Whether any monitors exist in the system |
| `monitors`    | array   | Array of monitor configuration objects   |

**Monitor Object Fields**

| Field                          | Type    | Description                                                  |
| ------------------------------ | ------- | ------------------------------------------------------------ |
| `uuid`                         | string  | Unique monitor identifier                                    |
| `title`                        | string  | Monitor display name                                         |
| `description`                  | string  | Monitor description                                          |
| `severity`                     | string  | Alert severity level (`"S1"`, `"S2"`, `"S3"`, `"S4"`)        |
| `measurementType`              | string  | Monitor type (`"state"`, `"event"`)                          |
| `state`                        | string  | Current monitor state (`"Normal"`, `"Alerting"`, `"Paused"`) |
| `alertingCount`                | integer | Number of active alerts                                      |
| `model`                        | object  | Monitor configuration with queries and thresholds            |
| `interval`                     | object  | Evaluation timing configuration                              |
| `executionErrorState`          | string  | State when execution fails                                   |
| `noDataState`                  | string  | State when no data is available                              |
| `isPaused`                     | boolean | Whether monitor is currently paused                          |
| `createdBy`                    | integer | Creator user ID                                              |
| `createdByEmail`               | string  | Creator email address                                        |
| `createdAt`                    | string  | Creation timestamp (ISO 8601)                                |
| `updatedAt`                    | string  | Last update timestamp (ISO 8601)                             |
| `lastStateStart`               | string  | When current state began                                     |
| `lastFiringStart`              | string  | When monitor last started alerting                           |
| `firstFiringStart`             | string  | When monitor first started alerting                          |
| `lastResolved`                 | string  | When monitor was last resolved                               |
| `minEvaluationDurationSeconds` | float   | Fastest query execution time                                 |
| `avgEvaluationDurationSeconds` | float   | Average query execution time                                 |
| `maxEvaluationDurationSeconds` | float   | Slowest query execution time                                 |
| `lastEvaluationError`          | string  | Last execution error message                                 |
| `lastEvaluationTimestamp`      | string  | Last evaluation timestamp                                    |
| `silenced`                     | boolean | Whether monitor is silenced                                  |
| `fullySilenced`                | boolean | Whether monitor is completely silenced                       |
| `silence_uuids`                | array   | Array of silence rule identifiers                            |

### Examples

#### Basic Request

Get all monitors with default pagination:

```bash
curl -L \
  --request POST \
  --url 'https://api.groundcover.com/api/monitors/summary/query' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --header 'Accept: text/event-stream' \
  --data-raw '{
    "conditions": [],
    "limit": 200,
    "skip": 0,
    "maxInstances": 10,
    "order": "desc",
    "sortBy": "lastFiringStart"
  }'
```

#### Filter by Time Range

Get monitors within a specific time window:

```bash
curl -L \
  --request POST \
  --url 'https://api.groundcover.com/api/monitors/summary/query' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --header 'Accept: text/event-stream' \
  --data-raw '{
    "conditions": [],
    "limit": 100,
    "skip": 0,
    "maxInstances": 10,
    "order": "desc",
    "sortBy": "lastFiringStart",
    "start": "2025-10-12T08:00:00.000Z",
    "end": "2025-10-12T10:00:00.000Z"
  }'
```

#### Pagination Example

Get the second page of results:

```bash
curl -L \
  --request POST \
  --url 'https://api.groundcover.com/api/monitors/summary/query' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --header 'Accept: text/event-stream' \
  --data-raw '{
    "conditions": [],
    "limit": 50,
    "skip": 50,
    "maxInstances": 10,
    "order": "desc",
    "sortBy": "title"
  }'
```

#### Sort by Creation Date

Get monitors sorted by newest first:

```bash
curl -L \
  --request POST \
  --url 'https://api.groundcover.com/api/monitors/summary/query' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --header 'Accept: text/event-stream' \
  --data-raw '{
    "conditions": [],
    "limit": 100,
    "skip": 0,
    "maxInstances": 10,
    "order": "desc",
    "sortBy": "createdAt"
  }'
```

#### Response Example

```json
{
  "hasMonitors": true,
  "monitors": [
    {
      "uuid": "12345678-1234-1234-1234-123456789abc",
      "title": "Example_Latency_Monitor",
      "description": "",
      "template": "Example_Latency_Monitor",
      "severity": "S2",
      "measurementType": "event",
      "header": "Example_Latency_Monitor",
      "resourceLabels": ["workload"],
      "contextLabels": ["namespace", "cluster"],
      "category": "",
      "interval": {
        "interval": "5m0s",
        "for": "1m0s"
      },
      "model": {
        "queries": [
          {
            "dataType": "traces",
            "name": "threshold_input_query",
            "sqlPipeline": {
              "selectors": [
                {
                  "key": "workload",
                  "origin": "root",
                  "type": "string",
                  "alias": "workload"
                },
                {
                  "key": "namespace",
                  "origin": "root",
                  "type": "string",
                  "alias": "namespace"
                },
                {
                  "key": "cluster",
                  "origin": "root",
                  "type": "string",
                  "alias": "cluster"
                }
              ]
            },
            "instantRollup": "5 minutes"
          }
        ],
        "reducers": null,
        "thresholds": [
          {
            "name": "threshold_1",
            "inputName": "threshold_input_query",
            "operator": "gt",
            "values": [502]
          }
        ],
        "query": "SELECT workload, namespace, cluster, count(*) AS logs_total FROM traces WHERE (start_timestamp < toStartOfInterval(NOW(), INTERVAL '5 MINUTE') AND start_timestamp >= (toStartOfInterval(NOW(), INTERVAL '5 MINUTE') - INTERVAL '5 minutes')) GROUP BY workload, namespace, cluster",
        "type": "traces"
      },
      "reducer": "",
      "trigger": {
        "op": "gt",
        "value": 502
      },
      "labelsMapping": {
        "owner": "example-user"
      },
      "executionErrorState": "",
      "noDataState": "OK",
      "isPaused": false,
      "createdBy": 12345,
      "createdByEmail": "user@example.com",
      "createdAt": "2025-03-14T20:42:36.949847Z",
      "updatedAt": "2025-09-21T12:17:00.130801Z",
      "relativeTimerange": {},
      "silences": [],
      "monitorId": "12345678-1234-1234-1234-123456789abc",
      "state": "Alerting",
      "lastStateStart": "0001-01-01T00:00:00Z",
      "lastFiringStart": null,
      "firstFiringStart": null,
      "lastResolved": null,
      "alertingCount": 11,
      "silenced": false,
      "fullySilenced": false,
      "silence_uuids": [],
      "minEvaluationDurationSeconds": 7.107210216,
      "avgEvaluationDurationSeconds": 7.1096896183047775,
      "maxEvaluationDurationSeconds": 7.119120884,
      "lastEvaluationError": "",
      "lastEvaluationTimestamp": "2025-10-12T09:15:50Z"
    }
  ]
}
```
