> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/insights.md).

# Insights

{% hint style="info" %}
**File-based configuration**

You can add `_FILE` to individual variables to provide their configuration in a separate file. Refer to [Keeping sensitive data in separate files](/deploy/host-n8n/configure-n8n/basic-configuration.md#keeping-sensitive-data-in-separate-files) for more details.
{% endhint %}

Insights gives instance owners and admins visibility into how workflows perform over time. Refer to [Insights](/administer/observe-and-log/track-usage-with-insights.md) for details.

{% hint style="warning" %}
**Storage and compaction thresholds**

`N8N_INSIGHTS_COMPACTION_HOURLY_TO_DAILY_THRESHOLD_DAYS` and `N8N_INSIGHTS_COMPACTION_DAILY_TO_WEEKLY_THRESHOLD_DAYS` set how many days n8n keeps high-resolution insights (metrics stored in one-hour buckets) before each compaction step (from the hour bucket to the day bucket, then from the day bucket to the week bucket). You configure those day counts on your instance.

Raising the values delays compaction. That adds more rows to `insights_by_period` and increases database usage. For how this relates to retention, see [Insights](/administer/observe-and-log/track-usage-with-insights.md#disable-or-configure-insights-metrics-collection).
{% endhint %}

If you encounter database load issues during compaction, tune how often compaction runs and how much work n8n does in each run:

* Decrease `N8N_INSIGHTS_COMPACTION_INTERVAL_MINUTES` to run compaction more often. This can reduce the amount of data that builds up between runs.
* Increase `N8N_INSIGHTS_COMPACTION_BATCH_DELAY_MILLISECONDS` to wait longer between batches.
* Decrease `N8N_INSIGHTS_COMPACTION_MAX_BATCHES_PER_RUN` to process fewer batches in each run.
* Decrease `N8N_INSIGHTS_COMPACTION_MAX_RUNTIME_SECONDS` to stop each run sooner.

These settings only control compaction workload and scheduling. They don't change retention or the age thresholds for each compaction step.

| Variable                                                 | Type   | Default | Description                                                                                                                                       |
| -------------------------------------------------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_DISABLED_MODULES`                                   | String | -       | Set to `insights` to disable the feature and metrics collection for an instance.                                                                  |
| `N8N_INSIGHTS_COMPACTION_BATCH_SIZE`                     | Number | 500     | The number of raw insights data to compact in a single batch.                                                                                     |
| `N8N_INSIGHTS_COMPACTION_BATCH_DELAY_MILLISECONDS`       | Number | 100     | Delay in milliseconds between full compaction batches. Increase this to wait longer between batches. Set to `0` to skip the delay.                |
| `N8N_INSIGHTS_COMPACTION_DAILY_TO_WEEKLY_THRESHOLD_DAYS` | Number | 180     | Age in days after which n8n compacts daily insights rows to weekly.                                                                               |
| `N8N_INSIGHTS_COMPACTION_HOURLY_TO_DAILY_THRESHOLD_DAYS` | Number | 90      | Age in days after which n8n compacts hourly insights rows to daily.                                                                               |
| `N8N_INSIGHTS_COMPACTION_INTERVAL_MINUTES`               | Number | 60      | Interval (in minutes) at which compaction should run. Decrease this to run compaction more often and reduce how much data builds up between runs. |
| `N8N_INSIGHTS_COMPACTION_MAX_BATCHES_PER_RUN`            | Number | 1000    | Maximum number of compaction batches to process in one run. Decrease this to process fewer batches per run. Set to `0` to disable this limit.     |
| `N8N_INSIGHTS_COMPACTION_MAX_RUNTIME_SECONDS`            | Number | 300     | Maximum runtime in seconds for one compaction run. Decrease this to stop each run sooner. Set to `0` to disable this limit.                       |
| `N8N_INSIGHTS_FLUSH_BATCH_SIZE`                          | Number | 1000    | The maximum number of insights data to keep in the buffer before flushing.                                                                        |
| `N8N_INSIGHTS_FLUSH_INTERVAL_SECONDS`                    | Number | 30      | The interval (in seconds) at which n8n flushes insights data to the database.                                                                     |
| `N8N_INSIGHTS_MAX_AGE_DAYS`                              | Number | 365     | Number of days n8n keeps compacted insights data before pruning. The maximum value is 730 (two years).                                            |
| `N8N_INSIGHTS_PRUNE_CHECK_INTERVAL_HOURS`                | Number | 24      | How often (in hours) the instance checks for insights data older than the effective max age and deletes it.                                       |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/insights.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
