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

# Configure Partner Zone traffic analytics

> Enable traffic analytics for Conduktor Partner Zones. Track bytes produced and consumed per partner to monitor usage and enforce governance on shared.

## Overview

Partner Zone analytics allow you to track traffic for each Partner Zone, providing insights into data consumption, like ingress and egress.

## Prerequisites

1. Console v1.39.0 (and above) and Gateway v3.12.0 (and above).
2. Existing observability Interceptors must be deleted and re-created with global scope.

## Enable Partner Zone traffic analytics

To enable Partner Zone traffic to be captured, the [observability Interceptor](#configure-observability-interceptor) with **global scope** has to be deployed on the same Gateway cluster where the Partner Zone is defined.

Partner Zones on clusters *without* this Interceptor enabled **will not capture** traffic data.

<Warning>
  If you already have an observability Interceptor deployed on the relevant Gateway cluster with a non-global scope (e.g., where the vcluster scope is set to `passthrough`), you'll need to delete and re-create it with the global scope.

  Any previously collected data will remain intact - the observability Kafka topic will not be deleted during this process.
</Warning>

To enable traffic analytics in Console:

1. Deploy the [observability Interceptor](#configure-observability-interceptor) on Gateway with a **global scope** in the `metadata`. Use the API or CLI:

<Note>
  Interceptors in the Console UI can only be created with a `passthrough` vcluster scope.

  When created, the Interceptors will **not** appear in the Console UI but will still function as expected.

  To verify the that the Interceptor has been created, make a Gateway API call `GET /gateway/v2/interceptor`.
</Note>

<Tabs>
  <Tab title="Gateway API">
    The host in this example is `localhost:8888`. Replace that with your Gateway's host and port.

    ```bash title="cURL command to the Gateway API" theme={null}
    curl http://localhost:8888/gateway/v2/interceptor \
      -X PUT \
      -u admin:conduktor \
      -H 'content-type: application/json' \
      -d '{
        "kind" : "Interceptor",
        "apiVersion" : "gateway/v2",
        "metadata" : {
          "name" : "observability-interceptor",
          "scope":
            "vCluster": null,
            "group": null,
            "username": null
        },
        "spec" : {
          "pluginClass" : "io.conduktor.gateway.interceptor.observability.ObservabilityPlugin",
          "priority" : 100,
          "config" : {
            "topicName" : "_conduktor_observability",
            "replicationFactor" : 3,
            "flushIntervalInSecond" : 300
          }
        }
      }'
    ```
  </Tab>

  <Tab title="Conduktor CLI">
    Apply your Interceptor via the Conduktor CLI, configured to connect to Console:

    ```yaml theme={null}
    apiVersion: gateway/v2
    kind: Interceptor
    metadata:
      name: observability-interceptor
      scope:
        vCluster: null
        group: null
        username: null
    spec:
      pluginClass: "io.conduktor.gateway.interceptor.observability.ObservabilityPlugin"
      priority: 100
      config:
        topicName: _conduktor_observability
        replicationFactor: 3
        flushIntervalInSecond: 300
    ```
  </Tab>
</Tabs>

2. Ensure that you create the Partner Zone on the the same Gateway cluster that this Interceptor was deployed to.

Once there's Partner Zone activity (either by producing or consuming data from the aliased topics), you'll see the metrics appear in the **Traffic** tab.

## View Partner Zone traffic analytics

Once the observability Interceptor is deployed and collecting data, you can view analytics using the Console UI: go to **Settings** > **Partner Zones**.

Click the **Traffic** tab in the Partner Zone list page to view the analytics:

* **Traffic views**: choose the required view of data:
  * **All**: combined view of both ingress and egress traffic
  * **Ingress**: incoming traffic (data being produced *to* Partner Zone topics)
  * **Egress**: outgoing traffic (data being consumed *from* Partner Zone topics)
* **Date range**: choose a date range to analyze a specific time period

## Configure observability Interceptor

This Interceptor monitors produce and consume operations in order to collect metrics about incoming and outgoing traffic (bytes) in a topic.

The collected metrics are then utilized by Console to display Partner Zone metrics.

<Warning>
  The observability Interceptor has to be configured for **global scope** to properly track metrics across Partner Zones.
</Warning>

| Name                  | Type   | Default | Description                                                                                                                                                                                                          |
| :-------------------- | :----- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| topicName             | String |         | Topics used to store observability metrics. If this topic already exists in your cluster, it has to have **only one partition**. If the topic doesn't exist, Gateway will create it when you deploy the Interceptor. |
| replicationFactor     | Int    |         | The replication factor to set if Gateway needs to create the topic.                                                                                                                                                  |
| flushIntervalInSecond | Int    | **300** | The periodic interval (in seconds) for Gateway to flush collected metrics to the specified topic.                                                                                                                    |

After Gateway writes metrics to the observability topic, Console has to read and process these into the PostgreSQL database.

This processing interval is defined by `CDK_CHARGEBACK_FLUSH_METRICS_EVERY_SECONDS` environment variable. The default is 300 (5 minutes).

It defines how frequently Console reads metrics from the observability topic and writes them to the `chargeback_metrics` PostgreSQL table.

You can configure it when deploying Console:

```bash theme={null}
docker run -e CDK_CHARGEBACK_FLUSH_METRICS_EVERY_SECONDS=300 conduktor/conduktor-console:latest
```

Or in your `docker-compose.yml`:

```yaml theme={null}
services:
  console:
    image: conduktor/conduktor-console:latest
    environment:
      CDK_CHARGEBACK_FLUSH_METRICS_EVERY_SECONDS: 300
```

<Info>
  **Data freshness:** the total delay before metrics appear in Partner Zone analytics depends on these intervals (both default to 5 minutes):

  * Gateway: flush interval for the observability Interceptor (`flushIntervalInSecond`).
  * Console: processing interval (`CDK_CHARGEBACK_FLUSH_METRICS_EVERY_SECONDS`).

  Reduce the values for more real-time data. Note that this will increase system overhead and storage.
</Info>

## Related resources

* [Share data externally with Partner Zones](/guide/use-cases/third-party-data)
* [Create Partner Zones using multi-cluster Gateway](/guide/tutorials/partner-zone-multi-cluster)
* [Give us feedback/request a feature](https://conduktor.io/roadmap)
