> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/monitoring/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/monitoring/latest/guides/create-exporter.md).

# Create an Exporter

`Exporter` is a Custom Resource (CR) that represents a Monitoring Exporter pipeline on the Management Cluster. This guide walks through creating one end to end.

## Prerequisites

Before creating an `Exporter` CR, ensure the following:

- The Monitoring Extension is installed. See [Installation](https://docs.cennso.com/cennso/monitoring/latest/installation.md).
- Crossplane, the required functions (`function-extra-resources`, `function-go-templating`, `function-sequencer`, `function-auto-ready`), and the Helm and Kubernetes providers are all running and healthy.
- A PromQL-compatible metrics source is reachable from the Management Cluster. The composition defaults to `http://mimir-gateway.cennso-monitoring/prometheus` when `spec.source.metricsURL` is omitted; explicitly setting the URL is recommended.
- If the sink requires OAuth 2.0 authentication, the credentials Secret exists in the target namespace before the `Exporter` is applied.

For more details about the `Exporter` API, see the [Exporter concept page](https://docs.cennso.com/cennso/monitoring/latest/concepts/exporter.md).

## Steps

1. Create the OAuth2 credentials Secret in the namespace where you will create the `Exporter`. The Secret must contain the four keys that the Telegraf configuration expects:

   ```bash
   kubectl create secret generic {SECRET_NAME} \
     --namespace {NAMESPACE} \
     --from-literal=client_id={CLIENT_ID} \
     --from-literal=client_secret={CLIENT_SECRET} \
     --from-literal=token_endpoint={TOKEN_ENDPOINT} \
     --from-literal=api_endpoint={ELASTICSEARCH_URL}
   ```

   The `api_endpoint` key must hold the exact URL of the ingest gateway that accepts the NDJSON document stream. The Telegraf `outputs.http` plugin POSTs to this URL verbatim.

2. Create a YAML file for your `Exporter` CR (for example: `exporter.yaml`) and configure it according to your needs:

   ```yaml
   apiVersion: monitoring.cennso.com/v1alpha1
   kind: Exporter
   metadata:
     name: platform-metrics
     namespace: my-namespace
   spec:
     compositionRevisionSelector:
       matchLabels:
         cennso.com/version: 0.1.0
   
     deployment:
       resources:
         requests:
           memory: "256Mi"
           cpu: "200m"
         limits:
           memory: "512Mi"
           cpu: "1000m"
   
     source:
       metricsURL: http://mimir-gateway.cennso-monitoring/prometheus
       pollInterval: "30s"
       initialLookback: "1m"
       requestTimeout: "25s"
       metrics:
         - name: up
           query: 'up{job=~"cennso-.*"}'
           step: "30s"
           limit: 500
         - name: smc_session_active_total
           query: 'smc_session_active_total{namespace="cennso-system"}'
           step: "60s"
           limit: 200
   
     sink:
       elastic:
         timeout: "30s"
         batchSize: 5000
         flushInterval: "30s"
         enableGzip: true
         tls:
           insecureSkipVerify: false
         auth:
           oauth2:
             secretRef:
               name: elastic-oauth-credentials
             scopes: ["metrics:write"]
             audience: elastic
   ```

   For more details about the `Exporter` CRD, refer to the [Exporter API reference](https://docs.cennso.com/cennso/monitoring/latest/technical-reference/crds/exporter.md).

3. Apply the `Exporter` CR to your Management Cluster:

   ```bash
   kubectl apply -f ./exporter.yaml
   ```

## Verification

To verify that the `Exporter` pipeline is running, follow these steps:

1. Check whether the CR is synced and ready:

   ```bash
   kubectl get exporter {EXPORTER_NAME} -n {NAMESPACE}
   ```

   Sample output:

   ```bash
   NAME               SYNCED   READY   COMPOSITION   AGE
   {EXPORTER_NAME}   True     True    exporter      2m
   ```

2. Confirm the ConfigMap with the rendered Telegraf configuration was created:

   ```bash
   kubectl get configmap {EXPORTER_NAME}-telegraf-conf -n {NAMESPACE}
   ```

3. Check that the Helm Release was created and is deployed:

   ```bash
   kubectl get release {EXPORTER_NAME} -n {NAMESPACE}
   ```

4. Verify the Telegraf pod is running and has loaded the expected plugins:

   ```bash
   kubectl get pods -n {NAMESPACE} -l app.kubernetes.io/name=telegraf
   kubectl logs -n {NAMESPACE} -l app.kubernetes.io/name=telegraf --tail=30
   ```

   A healthy pod logs lines such as `Loaded inputs: internal promql`, `processors: rename`, `secretstores: cennso_oauth`, and `outputs: http prometheus_client` with no `Unauthorized (401)` errors.

5. Confirm that ECS-compliant documents are being indexed. Query the Elasticsearch index directly:

   ```bash
   curl -s "${api_endpoint}/metrics-$(date +%Y.%m.%d)/_search?size=1&pretty"
   ```

   The response should contain documents with `orchestrator.*`, `container.name`, `host.name`, and `service.name` as nested objects at the document root, alongside `@timestamp` and the metric value nested under the measurement name.
