> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Configuration options for the ClickHouse data source plugin in Grafana

# Configuring ClickHouse data source in Grafana

export const ClickHouseSupportedBadge = () => {
  return <div className="ClickHouseSupportedBadge">
            <div className="ClickHouseSupportedIcon">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M1.30762 1.39073C1.30762 1.3103 1.37465 1.22986 1.46849 1.22986H2.64824C2.72868 1.22986 2.80912 1.29689 2.80912 1.39073V14.4886C2.80912 14.5691 2.74209 14.6495 2.64824 14.6495H1.46849C1.38805 14.6495 1.30762 14.5825 1.30762 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M4.2832 1.39073C4.2832 1.3103 4.35023 1.22986 4.44408 1.22986H5.62383C5.70427 1.22986 5.7847 1.29689 5.7847 1.39073V14.4886C5.7847 14.5691 5.71767 14.6495 5.62383 14.6495H4.44408C4.36364 14.6495 4.2832 14.5825 4.2832 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M7.25977 1.39073C7.25977 1.3103 7.3268 1.22986 7.42064 1.22986H8.60039C8.68083 1.22986 8.76127 1.29689 8.76127 1.39073V14.4886C8.76127 14.5691 8.69423 14.6495 8.60039 14.6495H7.42064C7.3402 14.6495 7.25977 14.5825 7.25977 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M10.2354 1.39073C10.2354 1.3103 10.3024 1.22986 10.3962 1.22986H11.576C11.6564 1.22986 11.7369 1.29689 11.7369 1.39073V14.4886C11.7369 14.5691 11.6698 14.6495 11.576 14.6495H10.3962C10.3158 14.6495 10.2354 14.5825 10.2354 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M13.2256 6.6057C13.2256 6.52526 13.2926 6.44482 13.3865 6.44482H14.5662C14.6466 6.44482 14.7271 6.51186 14.7271 6.6057V9.27354C14.7271 9.35398 14.6601 9.43442 14.5662 9.43442H13.3865C13.306 9.43442 13.2256 9.36739 13.2256 9.27354V6.6057Z" fill="currentColor" />
                </svg>
            </div>
            ClickHouse Supported
        </div>;
};

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

The easiest way to modify a configuration is in the Grafana UI on the plugin configuration page, but data sources can also be [provisioned with a YAML file](https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources).

This page shows a list of options available for configuration in the ClickHouse plugin, as well as config snippets for those provisioning a data source with YAML.

For a quick overview of all the options, a full list of config options can be found [here](#all-yaml-options).

<h2 id="common-settings">
  Common settings
</h2>

Example configuration screen:

<Image size="sm" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/config_common.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=34394a10e60b8e57c963ea4b6659c4d6" alt="Example secure native config" border width="601" height="813" data-path="images/integrations/data-visualization/grafana/config_common.png" />

Example configuration YAML for common settings:

```yaml theme={null}
jsonData:
  host: 127.0.0.1 # (required) server address.
  port: 9000      # (required) server port. For native, defaults to 9440 secure and 9000 insecure. For HTTP, defaults to 8443 secure and 8123 insecure.

  protocol: native # (required) the protocol used for the connection. Can be set to "native" or "http".
  secure: false    # set to true if the connection is secure.

  username: default # the username used for authentication.

  tlsSkipVerify:     <boolean> # skips TLS verification when set to true.
  tlsAuth:           <boolean> # set to true to enable TLS client authentication.
  tlsAuthWithCACert: <boolean> # set to true if CA certificate is provided. Required for verifying self-signed TLS certificates.

secureJsonData:
  password: secureExamplePassword # the password used for authentication.

  tlsCACert:     <string> # TLS CA certificate
  tlsClientCert: <string> # TLS client certificate
  tlsClientKey:  <string> # TLS client key
```

Note that a `version` property is added when the configuration is saved from the UI. This shows the version of the plugin that the config was saved with.

<h3 id="http-protocol">
  HTTP protocol
</h3>

More settings will be displayed if you choose to connect via the HTTP protocol.

<Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/config_http.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=444cfb0ca8c45758c96010e2af6ac63b" alt="Extra HTTP config options" border width="975" height="442" data-path="images/integrations/data-visualization/grafana/config_http.png" />

<h4 id="http-path">
  HTTP path
</h4>

If your HTTP server is exposed under a different URL path, you can add that here.

```yaml theme={null}
jsonData:
  # excludes first slash
  path: additional/path/example
```

<h4 id="custom-http-headers">
  Custom HTTP headers
</h4>

You can add custom headers to the requests sent to your server.

Headers can be either plain text or secure.
All header keys are stored in plain text, while secure header values are saved in the secure config (similar to the `password` field).

<Warning>
  **Secure Values over HTTP**

  While secure header values are stored securely in the config, the value will still be sent over HTTP if secure connection is disabled.
</Warning>

Example YAML for plain/secure headers:

```yaml theme={null}
jsonData:
  httpHeaders:
  - name: X-Example-Plain-Header
    value: plain text value
    secure: false
  - name: X-Example-Secure-Header
    # "value" is excluded
    secure: true
secureJsonData:
  secureHttpHeaders.X-Example-Secure-Header: secure header value
```

<h2 id="additional-settings">
  Additional settings
</h2>

These additional settings are optional.

<Image size="sm" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/config_additional.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=6079d85292bcd0ca85a64575159553a2" alt="Example additional settings" border width="406" height="452" data-path="images/integrations/data-visualization/grafana/config_additional.png" />

Example YAML:

```yaml theme={null}
jsonData:
  defaultDatabase: default # default database loaded by the query builder. Defaults to "default".
  defaultTable: <string>   # default table loaded by the query builder.

  dialTimeout: 10    # dial timeout when connecting to the server, in seconds. Defaults to "10".
  queryTimeout: 60   # query timeout when running a query, in seconds. Defaults to 60. This requires permissions on the user, if you get a permission error try setting it to "0" to disable it.
  validateSql: false # when set to true, will validate the SQL in the SQL editor.
```

<h3 id="opentelemetry">
  OpenTelemetry
</h3>

OpenTelemetry (OTel) is deeply integrated within the plugin.
OpenTelemetry data can be exported to ClickHouse with our [exporter plugin](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/clickhouseexporter).
For the best usage, it is recommended to configure OTel for both [logs](#logs) and [traces](#traces).

It is also required to configure these defaults for enabling [data links](/integrations/connectors/data-visualization/grafana/query-builder#data-links), a feature that enables powerful observability workflows.

<h3 id="logs">
  Logs
</h3>

To speed up [query building for logs](/integrations/connectors/data-visualization/grafana/query-builder#logs), you can set a default database/table as well as columns for the logs query. This will pre-load the query builder with a runnable logs query, which makes browsing on the explore page faster for observability.

If you're using OpenTelemetry, you should enable the "**Use OTel**" switch, and set the **default log table** to `otel_logs`.
This will automatically override the default columns to use the selected OTel schema version.

While OpenTelemetry isn't required for logs, using a single logs/trace dataset helps to enable a smoother observability workflow with [data linking](/integrations/connectors/data-visualization/grafana/query-builder#data-links).

Example logs configuration screen:

<Image size="sm" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/config_logs.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=04d87cd55ccfc1cd554300805e31e0eb" alt="Logs config" border width="460" height="402" data-path="images/integrations/data-visualization/grafana/config_logs.png" />

Example logs config YAML:

```yaml theme={null}
jsonData:
  logs:
    defaultDatabase: default # default log database.
    defaultTable: otel_logs  # default log table. If you're using OTel, this should be set to "otel_logs".

    otelEnabled: false  # set to true if OTel is enabled.
    otelVersion: latest # the otel collector schema version to be used. Versions are displayed in the UI, but "latest" will use latest available version in the plugin.

    # Default columns to be selected when opening a new log query. Will be ignored if OTel is enabled.
    timeColumn:       <string> # the primary time column for the log.
    levelColumn:   <string> # the log level/severity of the log. Values typically look like "INFO", "error", or "Debug".
    messageColumn: <string> # the log's message/content.
```

<h3 id="traces">
  Traces
</h3>

To speed up [query building for traces](/integrations/connectors/data-visualization/grafana/query-builder#traces), you can set a default database/table as well as columns for the trace query. This will pre-load the query builder with a runnable trace search query, which makes browsing on the explore page faster for observability.

If you're using OpenTelemetry, you should enable the "**Use OTel**" switch, and set the **default trace table** to `otel_traces`.
This will automatically override the default columns to use the selected OTel schema version.
While OpenTelemetry isn't required, this feature works best when using its schema for traces.

Example trace configuration screen:

<Image size="sm" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/config_traces.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=d25a65b35a6f9665a50b8c328836f9c5" alt="Traces config" border width="476" height="625" data-path="images/integrations/data-visualization/grafana/config_traces.png" />

Example trace config YAML:

```yaml theme={null}
jsonData:
  traces:
    defaultDatabase: default  # default trace database.
    defaultTable: otel_traces # default trace table. If you're using OTel, this should be set to "otel_traces".

    otelEnabled: false  # set to true if OTel is enabled.
    otelVersion: latest # the otel collector schema version to be used. Versions are displayed in the UI, but "latest" will use latest available version in the plugin.

    # Default columns to be selected when opening a new trace query. Will be ignored if OTel is enabled.
    traceIdColumn:       <string>    # trace ID column.
    spanIdColumn:        <string>    # span ID column.
    operationNameColumn: <string>    # operation name column.
    parentSpanIdColumn:  <string>    # parent span ID column.
    serviceNameColumn:   <string>    # service name column.
    durationTimeColumn:  <string>    # duration time column.
    durationUnitColumn:  <time unit> # duration time unit. Can be set to "seconds", "milliseconds", "microseconds", or "nanoseconds". For OTel the default is "nanoseconds".
    startTimeColumn:     <string>    # start time column. This is the primary time column for the trace span.
    tagsColumn:          <string>    # tags column. This is expected to be a map type.
    serviceTagsColumn:   <string>    # service tags column. This is expected to be a map type.
```

<h3 id="column-aliases">
  Column aliases
</h3>

Column aliasing is a convenient way to query your data under different names and types.
With aliasing, you can take a nested schema and flatten it so it can be easily selected in Grafana.

Aliasing may be relevant to you if:

* You know your schema and most of its nested properties/types
* You store your data in Map types
* You store JSON as strings
* You often apply functions to transform the columns you select

<h4 id="table-defined-alias-columns">
  Table-defined ALIAS columns
</h4>

ClickHouse has column aliasing built-in and works with Grafana out of the box.
Alias columns can be defined directly on the table.

```sql theme={null}
CREATE TABLE alias_example (
  TimestampNanos DateTime(9),
  TimestampDate ALIAS toDate(TimestampNanos)
)
```

In the above example, we create an alias called `TimestampDate` that converts the nanoseconds timestamp to a `Date` type.
This data isn't stored on disk like the first column, it's calculated at query time.
Table-defined aliases won't be returned with `SELECT *`, but this can be configured in the server settings.

For more info, read the documentation for the [ALIAS](/reference/statements/create/table#alias) column type.

<h4 id="column-alias-tables">
  Column alias tables
</h4>

By default, Grafana will provide column suggestions based on the response from `DESC table`.
In some cases, you may want to completely override the columns that Grafana sees.
This helps obscure your schema in Grafana when selecting columns, which can improve the user experience depending on your table's complexity.

The benefit of this over the table-defined aliases is that you can easily update them without having to alter your table. In some schemas, this can be thousands of entries long, which may clutter the underlying table definition. It also allows hiding columns that you want the user to ignore.

Grafana requires the alias table to have the following column structure:

```sql theme={null}
CREATE TABLE aliases (
  `alias` String,  -- The name of the alias, as seen in the Grafana column selector
  `select` String, -- The SELECT syntax to use in the SQL generator
  `type` String    -- The type of the resulting column, so the plugin can modify the UI options to match the data type.
)
```

Here's how we could replicate the behavior of the `ALIAS` column using the alias table:

```sql theme={null}
CREATE TABLE example_table (
  TimestampNanos DateTime(9)
);

CREATE TABLE example_table_aliases (`alias` String, `select` String, `type` String);

INSERT INTO example_table_aliases (`alias`, `select`, `type`) VALUES
('TimestampNanos', 'TimestampNanos', 'DateTime(9)'), -- Preserve original column from table (optional)
('TimestampDate', 'toDate(TimestampNanos)', 'Date'); -- Add new column that converts TimestampNanos to a Date
```

We can then configure this table to be used in Grafana. Note that the name can be anything, or even defined in a separate database:

<Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/alias_table_config_example.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=070045b4495566cfba890cc7017d62a8" alt="Example alias table config" border width="974" height="199" data-path="images/integrations/data-visualization/grafana/alias_table_config_example.png" />

Now Grafana will see the results of the alias table instead of the results from `DESC example_table`:

<Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/alias_table_select_example.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=295fc1034da3b2e15dcf14f760d9a1e1" alt="Example alias table select" border width="508" height="188" data-path="images/integrations/data-visualization/grafana/alias_table_select_example.png" />

Both types of aliasing can be used to perform complex type conversions or JSON field extraction.

<h2 id="all-yaml-options">
  All YAML options
</h2>

These are all of the YAML configuration options made available by the plugin.
Some fields have example values while others simply show the field's type.

See [Grafana documentation](https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources) for more information on provisioning data sources with YAML.

```yaml theme={null}
datasources:
  - name: Example ClickHouse
    uid: clickhouse-example
    type: grafana-clickhouse-datasource
    jsonData:
      host: 127.0.0.1
      port: 9000
      protocol: native
      secure: false
      username: default
      tlsSkipVerify: <boolean>
      tlsAuth: <boolean>
      tlsAuthWithCACert: <boolean>
      defaultDatabase: default
      defaultTable: <string>
      dialTimeout: 10
      queryTimeout: 60
      validateSql: false
      httpHeaders:
      - name: X-Example-Plain-Header
        value: plain text value
        secure: false
      - name: X-Example-Secure-Header
        secure: true
      logs:
        defaultDatabase: default
        defaultTable: otel_logs
        otelEnabled: false
        otelVersion: latest
        timeColumn: <string>
        levelColumn: <string>
        messageColumn: <string>
      traces:
        defaultDatabase: default
        defaultTable: otel_traces
        otelEnabled: false
        otelVersion: latest
        traceIdColumn: <string>
        spanIdColumn: <string>
        operationNameColumn: <string>
        parentSpanIdColumn: <string>
        serviceNameColumn: <string>
        durationTimeColumn: <string>
        durationUnitColumn: <time unit>
        startTimeColumn: <string>
        tagsColumn: <string>
        serviceTagsColumn: <string>
    secureJsonData:
      tlsCACert:     <string>
      tlsClientCert: <string>
      tlsClientKey:  <string>
      secureHttpHeaders.X-Example-Secure-Header: secure header value
```
