# Observability > Influxdb

# InfluxDB

Artillery can send metrics to InfluxDB through Telegraf using Telegraf's [statsd Service Plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/statsd).

## Quick Start

```yaml
config:
  plugins:
    publish-metrics:
      - type: influxdb-statsd
        host: localhost
        port: 8125
```

## Configuration

The InfluxDB integration uses the same configuration options as the StatsD integration:

| Name     | Description                                                                    |
| -------- | ------------------------------------------------------------------------------ |
| `type`   | Set to `influxdb-statsd`                                                      |
| `host`   | Hostname/IP of Telegraf agent (defaults to `127.0.0.1`)                       |
| `port`   | Port of Telegraf StatsD input (defaults to `8125`)                            |
| `prefix` | Prefix for metric names created by Artillery (defaults to `artillery.`)        |
| `tags`   | List of `name:value` strings to use as tags for all metrics sent during a test |

## Telegraf Configuration

Configure Telegraf's StatsD input plugin in your `telegraf.conf`:

```toml
[[inputs.statsd]]
  protocol = "udp"
  service_address = ":8125"
  delete_gauges = true
  delete_counters = true
  delete_sets = true
  delete_timings = true
  percentiles = [50.0, 90.0, 95.0, 99.0]
  metric_separator = "_"
  datadog_extensions = true
  allowed_pending_messages = 10000
  percentile_limit = 1000

[[outputs.influxdb_v2]]
  urls = ["http://localhost:8086"]
  token = "$INFLUX_TOKEN"
  organization = "your-org"
  bucket = "your-bucket"
```

## Examples

### Basic Configuration

```yaml
config:
  plugins:
    publish-metrics:
      - type: influxdb-statsd
        prefix: 'artillery.publish_metrics_plugin.'
        tags:
          - 'testId:{{ $testId }}'
          - 'environment:production'
```

### With Custom Host and Port

```yaml
config:
  plugins:
    publish-metrics:
      - type: influxdb-statsd
        host: telegraf.example.com
        port: 8126
        prefix: 'loadtest.'
        tags:
          - 'service:checkout'
          - 'testType:peak-load'
          - 'version:{{ $env.APP_VERSION }}'
```

## Querying Metrics in InfluxDB

Example Flux queries:

```flux
// Get response time percentiles
from(bucket: "your-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "artillery_http_response_time")
  |> filter(fn: (r) => r._field == "p95")

// Get request rate
from(bucket: "your-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "artillery_http_requests")
  |> aggregateWindow(every: 10s, fn: mean)
```

## Best Practices

1. **Configure retention policies**: Set appropriate retention policies in InfluxDB for your load test data
2. **Use consistent tags**: Include tags that help you filter and group metrics across test runs
3. **Monitor Telegraf**: Ensure Telegraf has sufficient resources to handle the metric volume from Artillery

## Debugging

Monitor Telegraf logs to verify metrics are being received:

```bash
journalctl -u telegraf -f
```

You can also enable debug logging in Telegraf configuration:

```toml
[agent]
  debug = true
```
