> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Example PromQL Queries

> Provides example PromQL queries you can use to analyze Apinizer Gateway metrics. Includes ready query examples for API traffic analyses, external connection analyses, cache analyses, and JVM analyses. You can monitor and analyze Gateway performance using these queries in Prometheus or Grafana.

## API Traffic Analyses

### Total API Request Count

<Card title="Total Request Count for 1 Hour" icon="chart-line">
  Calculates the total number of API requests in the specified time range.
</Card>

```promql theme={null}
sum(increase(apinizer_api_traffic_total_count_total[1h]))
```

### Request Count per API

<Card title="Request Count per API for 5 Minutes" icon="layer-group">
  Calculates the request count separately for each API.
</Card>

```promql theme={null}
sum by (api_name) (increase(apinizer_api_traffic_total_count_tagged_total[5m]))
```

### API Success Rate

<Card title="Success Rate (%) for 10 Minutes" icon="check-circle">
  Calculates the ratio of successful requests to total requests as a percentage.
</Card>

```promql theme={null}
(sum(increase(apinizer_api_traffic_success_count_total[10m])) / sum(increase(apinizer_api_traffic_total_count_total[10m]))) * 100
```

### APIs with Highest Error Rate

<Card title="Highest Error Rate for 15 Minutes" icon="exclamation-triangle">
  Lists the top 5 APIs with the highest error rate.
</Card>

```promql theme={null}
topk(5, sum by (api_name) (increase(apinizer_api_traffic_error_count_tagged_total[15m])) / sum by (api_name) (increase(apinizer_api_traffic_total_count_tagged_total[15m])))
```

### Average Response Time per API

<Card title="Average Response Time for 5 Minutes" icon="clock">
  Calculates the average response time for each API.
</Card>

```promql theme={null}
sum by (api_name) (rate(apinizer_api_traffic_total_time_tagged_seconds_sum[5m])) / sum by (api_name) (rate(apinizer_api_traffic_total_time_tagged_seconds_count[5m]))
```

## External Connection Analyses

### Error Rate per Target URL

<Card title="Error Rate per URL for 5 Minutes" icon="network-wired">
  Calculates the error rate for each external URL.
</Card>

```promql theme={null}
sum by (url) (increase(apinizer_external_requests_total_count_tagged_total[5m])) / sum by (url) (increase(apinizer_external_requests_total_count_tagged_total[5m]))
```

### Slowest Services

<Card title="Slowest Services for 5 Minutes" icon="tachometer-alt">
  Lists the top 5 services with the highest average response time.
</Card>

```promql theme={null}
topk(5, sum by (url) (rate(apinizer_external_response_time_seconds_sum[5m])) / sum by (url) (rate(apinizer_external_response_time_seconds_count[5m])))
```

## Cache Analyses

### Cache Hit Rate

<Card title="General Cache Hit Rate (%) for 5 Minutes" icon="database">
  Calculates the general cache hit rate for all APIs as a percentage.
</Card>

```promql theme={null}
(sum(increase(apinizer_api_traffic_cache_hits_count_total[5m])) / sum(increase(apinizer_api_traffic_total_count_total[5m]))) * 100
```

### Cache Hit Rate per API

<Card title="Cache Hit Rate per API (%) for 5 Minutes" icon="tags">
  Calculates the cache hit rate separately for each API.
</Card>

```promql theme={null}
sum by (api_name) (increase(apinizer_api_traffic_cache_hits_count_tagged_total[5m])) / sum by (api_name) (increase(apinizer_api_traffic_total_count_tagged_total[5m])) * 100
```

## JVM Analyses

### Memory Usage Percentage

<Card title="Instant Memory Usage Percentage" icon="memory">
  Calculates the ratio of memory used by JVM to maximum memory amount as a percentage.
</Card>

```promql theme={null}
sum(jvm_memory_used_bytes) / sum(jvm_memory_max_bytes) * 100
```

### Garbage Collection Duration

<Card title="GC Duration for 5 Minutes" icon="recycle">
  Calculates the total duration of Garbage Collection operations.
</Card>

```promql theme={null}
sum(rate(jvm_gc_pause_seconds_sum[5m]))
```

### Thread Count

<Card title="Instant Thread Count" icon="microchip">
  Shows the number of active threads running in JVM.
</Card>

```promql theme={null}
sum(jvm_threads_live_threads)
```
