---
source_url: https://www.pubnub.com/docs/general/operational-dashboards/visualization-queries
title: Queries for metrics visualizations
updated_at: 2026-05-25T05:44:44.850Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Queries for metrics visualizations

Once you receive your app’s [raw metrics export](https://www.pubnub.com/docs/general/operational-dashboards/basics#request-metrics-export) and review the [raw metrics glossary](https://www.pubnub.com/docs/general/operational-dashboards/raw-metrics), you can build queries in Datadog or New Relic. These examples complement your [Operational Dashboards](https://www.pubnub.com/docs/general/operational-dashboards/basics). Use them to turn raw data into actionable insights quickly.

Replace `CUSTOMER` with your actual customer tag, for example `customer:acme-prod`. New Relic queries use `WHERE` filters instead of tags.

:::note Performance and troubleshooting
Aggregation on large ranges may take up to 30–60 seconds. If a query returns no results, confirm the time window and filters (for example, `customer`) match your app configuration.
:::

## Datadog

Use these queries to power Datadog dashboards and alerts. Adapt filters (such as `customer`) to your environment.

### Request data

Start here to understand overall traffic.

#### Total requests by region

```sql
sum:pubnub.http_status{customer:CUSTOMER} by {region}.as_count()
```

#### Total requests by API

```sql
sum:pubnub.http_status{customer:CUSTOMER} by {api}.as_count()
```

#### Requests per second

```sql
sum:pubnub.http_status{customer:CUSTOMER} by {region}.as_rate()
```

#### Max requests per second per API

```sql
top(sum:pubnub.http_status{customer:CUSTOMER} by {api}.as_rate(), 5, 'max', 'desc')
```

#### Connection optimization tracking (499 status monitoring)

Status 499 means the client closed the connection. Track this to spot timeout handling or network optimization effects.

```sql
sum:pubnub.http_status{customer:CUSTOMER,status:499} by {api}.as_count()
```

### Client error data

Use these to track client‑side failures and their impact.

#### Count

```sql
sum:pubnub.http_status{customer:CUSTOMER,status_class:4xx,!status:499}.as_count()
```

#### Percentage

```sql
sum:pubnub.http_status{customer:CUSTOMER,status_class:4xx,!status:499}.as_count()/sum:pubnub.http_status{customer:CUSTOMER,!status_class:5xx}.as_count()*100
```

#### Client errors (4xx) non 403/499

```sql
sum:pubnub.http_status{customer:CUSTOMER,status_class:4xx,!status:499,!status:403} by {api,status}.as_count()
```

#### Client unauthorized errors (403)

```sql
sum:pubnub.http_status{customer:CUSTOMER,status:403} by {api}.as_count()
```

### Messaging: publish | subscribe | history | signals | Message Actions | file sharing

Use these to confirm healthy traffic for key messaging features.

#### Healthy publishes

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:publish,status_class:2xx}.as_count()
```

#### Healthy subscribes

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:subscribe,status_class:2xx}.as_count()
```

#### Healthy history

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:history,status_class:2xx}.as_count()
```

#### Healthy signal publishes

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:signal,status_class:2xx}.as_count()
```

#### Healthy Message Reactions

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:message-actions,status_class:2xx}.as_count()
```

#### Healthy file sharing publish

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:files.publish-file,status_class:2xx}.as_count()
```

### Presence | Access Manager | channel registrations

Use these to track Presence calls, Access Manager grants, and channel group activity.

#### Healthy presence total

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:presence,status_class:2xx}.as_count()
```

#### Healthy Access Manager grants

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:auth-grant,status_class:2xx}.as_count()
```

#### Healthy channel registrations

```sql
sum:pubnub.http_status{customer:CUSTOMER,api:channel-registration,status_class:2xx} by {status}.as_count()
```

### Server errors

Use this to monitor server‑side failures.

#### Server errors (5xx)

```sql
sum:pubnub.http_status{customer:CUSTOMER,status_class:5xx} by {api,status}.as_count()
```

## New Relic

Use these queries to build New Relic charts and alerts. Replace facets and filters to match your accounts and entities. Each query mirrors the Datadog examples above.

### Request data

Start here to understand overall traffic.

#### Total requests by region

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric FACET region
```

#### Total requests by API

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric FACET api
```

#### Client closed connections (499)

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where status = 499 FACET api TIMESERIES
```

### Client error data

Use these to track client‑side failures and their impact.

#### Count

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where status_class = '4xx' and status NOT IN ('403', '499')
```

#### Percentage

```sql
SELECT filter(count(*), WHERE status_class = '4xx' and status NOT IN ('403', '499')) / count(*) FROM Metric TIMESERIES
```

#### Client errors (4xx) non 403/499

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where status_class = '4xx' and status NOT IN ('403', '499') FACET api, status TIMESERIES
```

#### Client unauthorized errors (403)

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where status = '403' FACET api TIMESERIES
```

### Messaging: publish | subscribe | history | signals | Message Actions | file sharing

Use these to confirm healthy traffic for key messaging features.

#### Healthy publishes

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'publish' and status_class = '2xx' TIMESERIES
```

#### Healthy subscribes

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'subscribe' and status_class = '2xx' TIMESERIES
```

#### Healthy history

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'history' and status_class = '2xx' TIMESERIES
```

#### Healthy signal publishes

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'signal' and status_class = '2xx' TIMESERIES
```

#### Healthy Message Reactions

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'message-actions' and status_class = '2xx' TIMESERIES
```

#### Healthy file sharing publish

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'files.publish-file' and status_class = '2xx' TIMESERIES
```

### Presence | Access Manager | channel registrations

Use these to track Presence calls, Access Manager grants, and channel group activity.

#### Healthy presence total

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'presence' and status_class = '2xx' TIMESERIES
```

#### Healthy Access Manager grants

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'auth-grant' and status_class = '2xx' TIMESERIES
```

#### Healthy channel registrations

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where api = 'channel-registration' and status_class = '2xx' TIMESERIES
```

### Server errors

Use this to monitor server‑side failures.

#### Server errors (5xx)

```sql
SELECT sum(`pubnub.http_status.value`) FROM Metric where status_class = '5xx' FACET api, status TIMESERIES
```