> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-flags/use-feature-flags/use-ff/relay-proxy/monitoring.md).

# Monitor the Proxy Using Prometheus

The proxy uses [Prometheus](https://prometheus.io/docs/introduction/overview/) for recording metrics that can be used to understand how the proxy is behaving and performing. You can view and scrape these metrics by hitting the proxy's `/metrics` endpoint. For example, if you're running the proxy locally on port 7000, you can view the metrics it exposes by making the following request:

`$ curl localhost:7000/metrics`

### Example Queries <a href="#example-queries" id="example-queries"></a>

To get started, here are some example promql queries that can be useful for monitoring how the proxy is performing.

| Usecase                     | Promql query                                                  |
| --------------------------- | ------------------------------------------------------------- |
| Request Rate by Status Code | `sum by (code) (rate(ff_proxy_http_requests_total[5m]))`      |
| Requests Rate by URL        | `sum by (url) ( rate ( ff_proxy_http_requests_total[5m]))`    |
| Cache Writes                | `sum by (error) (rate(ff_proxy_redis_cache_write_count[5m]))` |
| Cache Reads                 | `sum by (error) (rate(ff_proxy_redis_cache_read_count[5m]))`  |
| Cache Deletes               | `sum by (error) (rate(ff_proxy_redis_cache_read_count[5m]))`  |
| SSE Events Forwarded        | `sum by (error) (rate(ff_proxy_sse_publish[5m]))`             |
| SSE Streams Closed          | `sum by (error) (rate(ff ff_proxy_sse_stream_close[5m]))`     |

As well as counter metrics, the proxy also exposes a number of histogram metrics that can be used to monitor request duration, payload sizes, and how long interactions with the cache take. If you are unfamiliar with histogram metrics, we recommend reading [this article](https://grafana.com/blog/2020/06/23/how-to-visualize-prometheus-histograms-in-grafana/) for help with visualising histograms.

### Example Prometheus Configuration <a href="#example-prometheus-configuration" id="example-prometheus-configuration"></a>

Below is an example prometheus configuration that can be used to scrape metrics from the proxy.

```yaml
global:
  scrape_interval:     10s
  evaluation_interval: 10s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 30s
    static_configs:
      - targets: ['localhost:7000']
```

### Metrics exposed <a href="#metrics-exposed" id="metrics-exposed"></a>

Below is a list of all the prometheus metrics exposed by the proxy.

| Name                                           | Type      | Labels                                                                                                                                                                                                                                                                                                  | Description                                                                                       |
| ---------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| ff\_proxy\_http\_requests\_total               | counter   | <p><strong>code</strong>: The HTTP response code<br><br><br><br><strong>envID</strong>: The environmentID<br><br><br><br><strong>method</strong>: The HTTP method used for the request<br><br><br><br><strong>url</strong>: The requests URL</p>                                                        | Records the number of requests to an endpoint                                                     |
| ff\_proxy\_http\_requests\_duration            | histogram | <p><strong>envID</strong>: The environmentID<br><br><br><br><strong>url</strong>: The requests URL</p>                                                                                                                                                                                                  | Records the request duration for an endpoint                                                      |
| ff\_http\_requests\_content\_length\_histogram | histogram | <p><strong>envID</strong>: The environmentID<br><br><br><br><strong>url</strong>: The requests URL</p>                                                                                                                                                                                                  | Records the value of the Content-Length header for an HTTP request                                |
| ff\_proxy\_metrics\_forwarded                  | counter   | <p><strong>envID</strong>: The environmentID<br><br><br><br><strong>error</strong>: Indicates if an error occurred during forwarding</p>                                                                                                                                                                | Tracks the number of metrics forwarded from the proxy to SaaS Feature Flags                       |
| ff\_proxy\_sdk\_usage                          | counter   | <p><strong>envID</strong>: The environment ID<br><br><br><br><strong>sdk\_language</strong>: The programming language of the SDK<br><br><br><br><strong>sdk\_type</strong>: The type of the SDK (e.g., server, client, mobile)<br><br><br><br><strong>sdk\_version</strong>: The version of the SDK</p> | Tracks what SDKs are using the FF proxy                                                           |
| ff\_proxy\_sse\_publish                        | counter   | <p><strong>api\_key</strong>: The API key used for authentication<br><br><br><br><strong>environment</strong>: The environment ID<br><br><br><br><strong>error</strong>: Indicates whether an error occurred during event forwarding</p>                                                                | Records the number of Server-Sent Events (SSE) the proxy has received and forwarded on to clients |
| ff\_proxy\_sse\_stream\_close                  | counter   | <p><strong>api\_key</strong>: The API key used for authentication<br><br><br><br><strong>environment</strong>: The environment ID<br><br><br><br><strong>error</strong>: Indicates whether an error occurred during event forwarding</p>                                                                | Records the number of times the proxy closes an SSE stream                                        |
| ff\_proxy\_redis\_cache\_read\_count           | counter   | <p><strong>error</strong>: Indicates if an error occurred during the read operation<br><br><br><br><strong>key</strong>: The cache key used for the read operation<br><br><br><br></p>                                                                                                                  | Tracks how many reads are made to the cache                                                       |
| ff\_proxy\_redis\_cache\_write\_count          | counter   | <p><strong>error</strong>: Indicates whether an error occurred during the write operation<br><br><br><br><strong>key</strong>: The cache key<br><br><br><br></p>                                                                                                                                        | Tracks how many writes are made to the cache                                                      |
| ff\_proxy\_redis\_cache\_remove\_count         | counter   | <p><strong>key</strong>: The cache key<br><br><br><br></p>                                                                                                                                                                                                                                              | Tracks how many deletes are made to the cache                                                     |
| ff\_proxy\_redis\_cache\_delete\_duration      | histogram | N/A                                                                                                                                                                                                                                                                                                     | Tracks how long delete operations to the cache take                                               |
| ff\_proxy\_redis\_cache\_write\_duration       | histogram | N/A                                                                                                                                                                                                                                                                                                     | Tracks how long write operations to the cache take                                                |
| ff\_proxy\_redis\_cache\_read\_duration        | histogram | N/A                                                                                                                                                                                                                                                                                                     | Tracks how long write operations to the cache take                                                |
