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

# Output Formats

> Available output formats for exporting k6 test results

k6 supports multiple output formats for exporting test results to different backends and file formats. You can use one or more outputs simultaneously to send metrics to various destinations.

## Available Outputs

### Summary Output

The default output that displays test results in the terminal at the end of the test.

```bash theme={null}
k6 run script.js
```

See [End of Test Summary](/results/end-of-test-summary) for detailed information.

### CSV Output

Export metrics to CSV files for analysis in spreadsheet applications.

```bash theme={null}
k6 run --out csv=results.csv script.js
```

The CSV output (`internal/output/csv/output.go:21`) writes metrics with the following structure:

* Metric name
* Timestamp
* Metric value
* All tags as separate columns

<Note>
  CSV output supports gzip compression automatically when the filename ends with `.gz`:

  ```bash theme={null}
  k6 run --out csv=results.csv.gz script.js
  ```
</Note>

**Configuration options:**

```javascript theme={null}
export const options = {
  ext: {
    csv: {
      fileName: 'results.csv',
      saveInterval: '5s',
      timeFormat: 'unix',
    },
  },
};
```

### Cloud Output

Stream results to Grafana Cloud k6 for real-time analysis and collaboration.

```bash theme={null}
k6 run --out cloud script.js
```

See [Cloud Integration](/results/cloud-integration) for details.

### InfluxDB Output

Send metrics directly to InfluxDB v1 for time-series storage and visualization.

```bash theme={null}
k6 run --out influxdb=http://localhost:8086/mydb script.js
```

The InfluxDB output (`internal/output/influxdb/output.go:37`) supports:

* Configurable batch sizes
* Concurrent writes for better performance
* Tag-to-field conversions
* Custom precision settings

<Warning>
  For InfluxDB v2, use the [xk6-output-influxdb](https://github.com/grafana/xk6-output-influxdb) extension instead.
</Warning>

**Configuration example:**

```javascript theme={null}
export const options = {
  ext: {
    influxdb: {
      addr: 'http://localhost:8086',
      db: 'k6',
      username: 'admin',
      password: 'admin',
      insecureSkipTLSVerify: true,
      pushInterval: '1s',
      concurrentWrites: 4,
      tagsAsFields: ['status', 'method'],
    },
  },
};
```

### OpenTelemetry Output

Export metrics using the OpenTelemetry protocol (OTLP) for integration with observability platforms.

```bash theme={null}
k6 run --out opentelemetry script.js
```

Supports both gRPC and HTTP transports.

### Prometheus Remote Write

Send metrics to Prometheus-compatible systems using the remote write protocol.

```bash theme={null}
k6 run --out prometheusrw script.js
```

**Configuration:**

```javascript theme={null}
export const options = {
  ext: {
    prometheusrw: {
      url: 'http://localhost:9090/api/v1/write',
      insecureSkipTLSVerify: true,
    },
  },
};
```

## Using Multiple Outputs

You can specify multiple outputs to send results to different destinations:

```bash theme={null}
k6 run --out csv=results.csv --out cloud --out influxdb=http://localhost:8086/k6 script.js
```

<Tip>
  Using multiple outputs allows you to maintain local copies of results while also streaming to remote services.
</Tip>

## Output Configuration

All outputs can be configured via:

1. **Command-line flags**: `--out format=config`
2. **Environment variables**: `K6_OUT=format=config`
3. **Test script options**: Using the `ext` configuration object
4. **JSON configuration**: Via the `--config` flag

### Priority Order

Configuration sources are applied in this order (later overrides earlier):

1. Default values
2. JSON configuration file
3. Script options
4. Environment variables
5. Command-line arguments

## Output Interface

All outputs implement the `Output` interface (`output/types.go:44`) with these methods:

* `Description()`: Human-readable output description
* `Start()`: Initialize the output and start background processing
* `AddMetricSamples()`: Receive metric samples (non-blocking)
* `Stop()`: Flush remaining metrics and clean up resources

<Note>
  Outputs should use non-blocking `AddMetricSamples()` methods and buffer metrics for asynchronous flushing to avoid impacting test performance.
</Note>

## Output Extensions

k6 supports custom output formats through extensions. See [Creating Custom Outputs](/results/custom-outputs) for building your own output plugin.

Popular community extensions:

* **xk6-output-influxdb**: InfluxDB v2 support
* **xk6-output-prometheus-remote**: Enhanced Prometheus integration
* **xk6-output-kafka**: Stream to Apache Kafka
* **xk6-output-timescaledb**: Direct TimescaleDB output

## Performance Considerations

<Steps>
  ### Buffer Metrics

  Use `SampleBuffer` to collect samples before processing:

  ```go theme={null}
  type Output struct {
      output.SampleBuffer
      // ...
  }
  ```

  ### Periodic Flushing

  Flush metrics at regular intervals instead of per-sample:

  ```go theme={null}
  pf, err := output.NewPeriodicFlusher(flushPeriod, o.flushMetrics)
  ```

  ### Concurrent Writes

  For network outputs, use concurrent connections:

  ```javascript theme={null}
  metricPushConcurrency: 4
  ```
</Steps>
