# Configuration reference

Source: https://docs.chmonitor.dev/reference/configuration

> How chmonitor, a ClickHouse monitoring dashboard, reads configuration: sources, precedence, and where each setting category is documented.

chmonitor reads its settings from environment variables, with one canonical `CHM_*` name per setting. Set that name once and the build derives the browser-side `VITE_*` value. This page explains the sources, their precedence, and which category lives where.

## How configuration works [#how-configuration-works]

chmonitor has three configuration sources. A later source always wins over an
earlier one:

 B[CHM_CONFIG_FILE]
  B --> C[Environment variables]
  C --> D[Runtime config]
  style D fill:#4ade80,color:#000`"
/>

| Source                        | What it controls         | Notes                                                                                                                                             |
| ----------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Built-in defaults             | Everything               | Every feature is public and enabled. Sensible query/pool timeouts.                                                                                |
| `CHM_CONFIG_FILE`             | Feature permissions only | Optional file; mount at any path, point `CHM_CONFIG_FILE` at it.                                                                                  |
| `CHM_HEALTH_CONFIG_DIRECTORY` | Alert definitions only   | Optional directory of `<concern>.yaml` files (default `/etc/chmonitor/health.d`). Merges below database rows and above env. Read once at startup. |
| Environment variables         | All settings             | Primary surface. Server vars take effect on restart; client vars require a rebuild.                                                               |
| Browser localStorage          | Per-user UI state        | Time range, alert settings, connection list. Not server config.                                                                                   |

## Which variable name is canonical? [#which-variable-name-is-canonical]

Settings the browser needs (auth provider, cloud mode, feature flags) are inlined
into the client bundle at build time as `VITE_*` vars. You set each one **once**:
use the canonical `CHM_*` name and `vite.config.ts` derives the matching `VITE_*`
for the client. For example, set `CHM_AUTH_PROVIDER` — not also
`VITE_AUTH_PROVIDER`.

Precedence per variable:

```text
explicit VITE_* → canonical CHM_* → deployment-mode default
```

See [Environment variables — one canonical name per setting](/reference/environment-variables#one-canonical-name-per-setting).

**Dual-surface settings need a rebuild**

  A dual-surface setting is needed at both build time (so vite inlines its
  `VITE_*`) and runtime (so the server reads it). Changing it requires a **rebuild
  and redeploy** — it is not a runtime-only change.

If you are migrating from a v0.2 Next.js deployment, the legacy `NEXT_PUBLIC_*`
prefix is no longer read — rename to the canonical `CHM_*` name. See [Migrate to v0.3](/reference/migrating/v0-3) for the full rename list.

## Configuration categories [#configuration-categories]

Each category has a full reference — expand for the essentials and the link.

  
#### ClickHouse connection

    The only required settings. Set `CLICKHOUSE_HOST` at minimum.

    ```bash
    CLICKHOUSE_HOST=http://localhost:8123
    CLICKHOUSE_USER=default
    CLICKHOUSE_PASSWORD=
    ```

    For multiple hosts, use comma-separated values. See
    [Multiple hosts](/operate/advanced/multiple-hosts).

    Full reference: [Environment variables — ClickHouse connection](/reference/environment-variables#clickhouse-connection).
  

  
#### Query execution and connection pool

    Controls timeouts, caching, and the connection pool. Defaults are sensible;
    override only if needed.

    Key variables: `CLICKHOUSE_MAX_EXECUTION_TIME` (60 s), `CLICKHOUSE_POOL_SIZE` (10).

    Full reference: [Environment variables — query execution](/reference/environment-variables#query-execution).
  

  
#### Authentication

    Server auth is off by default (`CHM_AUTH_PROVIDER=none`). Choose a provider:

    | Provider | Description                                                      |
    | -------- | ---------------------------------------------------------------- |
    | `none`   | Open — no login required.                                        |
    | `clerk`  | Clerk browser sessions.                                          |
    | `proxy`  | Trust a reverse proxy (Cloudflare Access JWT or trusted header). |

    An API key layer (`CHM_API_KEY_SECRET`) can run alongside any provider and issues
    signed `chm_` Bearer tokens for scripts and MCP clients.

    Full reference: [Authentication](/operate/authentication).
  

  
#### Feature permissions

    All features are public and enabled by default. Gate or disable features via env
    vars or a config file.

    ```bash
    CHM_FEATURE_AGENT_ACCESS=authenticated

    # Disable a feature entirely
    CHM_FEATURE_METRICS_ENABLED=false

    # Disable multiple features at once
    CHM_DISABLED_FEATURES=settings,insights
    ```

    Full reference: [Feature permissions](/operate/advanced/feature-permissions).
  

  
#### AI agent

    The agent uses an OpenAI-compatible API. Set `LLM_API_KEY` to enable it.

    ```bash
    LLM_API_KEY=sk-...
    LLM_API_BASE=https://openrouter.ai/api/v1      # default
    LLM_MODEL=openrouter:openrouter/free           # default; format is provider:modelId
    ```

    Keep LLM keys server-side. Never use `VITE_` or `NEXT_PUBLIC_` for them.

    Full reference: [AI agent — configuration](/guide/ai-agent/configuration).
  

  
#### Conversation store

    Agent conversations default to browser localStorage. Enable server persistence:

    ```bash
    # Set the canonical name (VITE_FEATURE_CONVERSATION_DB is derived at build time);
    # also requires Clerk auth (CHM_AUTH_PROVIDER=clerk):
    CHM_FEATURE_CONVERSATION_DB=true

    # Runtime — force a backend (optional; auto-selects when unset):
    CONVERSATION_STORE_BACKEND=agentstate   # or: d1, postgres, memory
    ```

    Full reference: [Conversation history — backends](/guide/ai-agent/conversation-history/backends).
  

  
#### Health alerting

    A cron sweep runs health checks over all hosts every 10 minutes (Cloudflare Cron
    Trigger) and can post webhook alerts.

    ```bash
    HEALTH_ALERT_WEBHOOK_URL=https://hooks.slack.com/services/...
    HEALTH_ALERT_MIN_SEVERITY=warning
    ```

    Without a metadata database, declare alert definitions from a mounted directory
    (`CHM_HEALTH_CONFIG_DIRECTORY`). Definitions merge D1/Postgres > file > env >
    default; alert state and ACKs stay in memory. See
    [Run alerts without a metadata database](/guide/features/health#run-alerts-without-a-metadata-database).

    Full reference: [Environment variables — health alerting](/reference/environment-variables#health-alerting).
  

  
#### PeerDB monitoring

    Optional. Set `PEERDB_API_URL` to enable the PeerDB section in the sidebar.

    Full reference: [Environment variables — PeerDB](/reference/environment-variables#peerdb-monitoring).
  

  
#### Analytics

    Product analytics uses the PostHog key `CHM_ANALYTICS_KEY` (client
    `VITE_ANALYTICS_KEY` is derived at build time). Optional build-time override:

    ```bash
    VITE_AUTOCOMPLETE_LIMIT=500
    ```

    Full reference: [Environment variables — analytics and branding](/reference/environment-variables#analytics--branding).
  

## Where do I set variables? [#where-do-i-set-variables]

  
    Use `-e VAR=value` flags on `docker run`, or `environment:` / an optional
    `env_file: .env` in `docker-compose.yml`.
  

  
    Set values in `values.yaml` → ConfigMap (non-secret) + `Secret` (secrets),
    mounted via `envFrom`.
  

  
    Non-secret vars via the Workers dashboard (the build does not carry `wrangler.toml [vars]` into the deployed Worker); secrets via `wrangler secret put`.
  

  
    Project → Settings → Environment Variables.
  

  
    A `.env` / `.env.local` file or shell export (template:
    `apps/dashboard/.env.example`).
  

**The hosted product uses .env.production**

  On the hosted `dash.chmonitor.dev`, `wrangler.toml` declares **no** `[vars]` — the
  non-secret config lives in committed `apps/dashboard/.env.production` (+
  `.env.preview`), which feeds both the client build and the Worker runtime vars
  (injected by `scripts/patch-wrangler-env.ts` at deploy). When working in this
  repo, edit `.env.production` rather than re-adding a `[vars]` block.

See the per-platform install guides for copy-paste examples.

## Config shape [#config-shape]

The connection config chmonitor resolves at startup looks like this:

```ts
interface ChmonitorConfig {
  host: string
  user: string
  password: string
  maxExecutionTime?: number
}

const config: ChmonitorConfig = {
  host: 'https://clickhouse.example.com:8443',
  user: 'monitoring',
  password: 'secret',
  maxExecutionTime: 60,
}
```

## Related [#related]

  - [Environment variables](/reference/environment-variables): Full list of every variable, grouped by category.

  - [Settings](/reference/settings): In-app settings and their server-side counterparts.

  - [Connection presets](/reference/connection-presets): Create a least-privilege read-only ClickHouse user.

  - [Feature permissions](/operate/advanced/feature-permissions): Config-file and env-override details.

  - [Authentication](/operate/authentication): Choose and configure an auth provider.

  - [AI agent — configuration](/guide/ai-agent/configuration): LLM provider setup.

  - [MCP server](/reference/mcp-server): Connect external AI tools.