# Prometheus Agent Remote Write Config

Configure a Prometheus server or Grafana Agent to forward metrics to Kloudfuse using remote write, with options for standalone Helm charts, Prometheus Operator, or CRD-based configuration.

## Using an Existing Prometheus Server

1. Determine the ingress IP for the Kloudfuse stack.

```console
   kubectl get svc | grep kfuse-ingress-nginx-controller
   ```

You can use either the EXTERNAL-IP address, or DNS name.
   
   |     |     |
   | --- | --- |
   |  | DNS name does not work if the Kloudfuse stack is on a different VPC or cluster than the target cluster.<br>You can use the IP address in all circumstances. |

2. Add a `remote_write` endpoint to use the Prometheus server. Choose the correct option, depending on your network protocol (`http` or `https`):
   
   
   ```console
   http://<REPLACE KFUSE ADDRESS>/write as the remote_write
   
   https://<REPLACE KFUSE ADDRESS>/write as the remote_write
   ```

|     |     |
   | --- | --- |
   |  | Starting with Kloudfuse 3.4.3 and Prometheus 2.40+, native histograms are supported. To enable sending native histograms, add `send_native_histograms: true` to your remote write configuration. See [Native and Exponential Histograms](https://docs.kloudfuse.com/platform/4.1.0/signals/metrics/histogram-native-exponential/) for more details. |

3. If the Prometheus server is installed using the standalone [Prometheus helm chart](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus), add the following `helm` values and run `helm upgrade`:
   
   
   ```yaml
   server:
        # For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms feature:
        extraArgs:
          enable-feature: native-histograms

serverFiles:
        prometheus.yml:
          remote_write:
         - url: http://<REPLACE KFUSE ADDRESS>/write
           queue_config:
             max_samples_per_send: 4000
           # For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms:
           send_native_histograms: true
   ```

## Prometheus Operator

### Helm Chart Values

Use these steps if the Prometheus server is installed using Prometheus Operator or [kube-prometheus-stack helm chart](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack):

1. Add the following helm values:
   
   
   ```yaml
   prometheus:
        prometheusSpec:
          # For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms feature:
          enableFeatures:
         - native-histograms
   remoteWrite:
       - queueConfig:
           maxSamplesPerSend: 4000
         url: http://<REPLACE KFUSE ADDRESS>/write
         # For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms:
         sendNativeHistograms: true
   ```

2. Run `helm upgrade`.

### Prometheus CRD

Alternatively, configure the remote write through Prometheus CRD.

Update the Prometheus CRD (kind: Prometheus) using the following configuration:

```yaml
# For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms feature:
enableFeatures:
  - native-histograms

remoteWrite:
  - queueConfig:
      maxSamplesPerSend: 4000
    url: http://<REPLACE KFUSE ADDRESS>/write
    # For Prometheus 2.40+ and Kloudfuse 3.4.3+, enable native histograms:
    sendNativeHistograms: true
```

## Replacing the Prometheus Server

You can also replace the Prometheus server with Grafana Agent, which is lighter-weight and can be configured to scrape and emit write metrics.

Use the following helm chart to install the agent. Use the following helm values:

```yaml
config:
  prometheus:
    remoteWrite:
      url: http://<REPLACE KfUSE ADDRESS>/write
    configs:
      <copy existing scrape configs here>
```
