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

> ClickHouseのPrometheus メトリクス エンドポイント: スクレイピング用に専用ポートでサーバーのメトリクスを公開します。

# Prometheus メトリクス エンドポイント

ClickHouseは、Prometheusサーバーがスクレイピングできるよう、Prometheusのテキストフォーマットで自身のメトリクスを専用ポートに公開します。

PrometheusのメトリクスをClickHouseに保存し、PromQLでクエリする場合は、代わりに[Prometheus HTTP APIとPromQL](/ja/interfaces/prometheus)を参照してください。

<Note>
  ClickHouse Cloudを使用している場合は、[Prometheusインテグレーション](/ja/products/cloud/features/monitoring/prometheus)を利用してPrometheusにメトリクスを公開できます。
</Note>

<h2 id="configure-the-metrics-port">
  メトリクスポートの設定
</h2>

Prometheus サーバーが ClickHouse 自身のメトリクスをスクレイプする必要がある場合は、専用のポートを設定します。

```xml theme={null}
<prometheus>
    <port>9363</port>
    <endpoint>/metrics</endpoint>
    <metrics>true</metrics>
    <asynchronous_metrics>true</asynchronous_metrics>
    <events>true</events>
    <errors>true</errors>
    <histograms>true</histograms>
    <dimensional_metrics>true</dimensional_metrics>
</prometheus>
```

<h2 id="configure-extended-handlers">
  拡張ハンドラーを設定する
</h2>

`<prometheus.handlers>` セクションを使用すると、同一ポート上により拡張されたハンドラーを構成できます。
このセクションは [`<http_handlers>`](/ja/concepts/features/interfaces/http) と似ていますが、Prometheus プロトコル向けに動作します。

```xml theme={null}
<prometheus>
    <port>9363</port>
    <handlers>
        <my_rule_1>
            <url>/metrics</url>
            <handler>
                <type>expose_metrics</type>
                <metrics>true</metrics>
                <asynchronous_metrics>true</asynchronous_metrics>
                <events>true</events>
                <errors>true</errors>
                <histograms>true</histograms>
                <dimensional_metrics>true</dimensional_metrics>
                <labels>
                    <environment>production</environment>
                    <shard from_env="SHARD_NAME"></shard>
                </labels>
            </handler>
        </my_rule_1>
    </handlers>
</prometheus>
```

<h2 id="settings">
  設定
</h2>

これらの設定の詳細な動作については、サーバー設定リファレンスの [Prometheus セクション](/ja/reference/settings/server-settings/settings/other#prometheus) を参照してください。

| 名前 | デフォルト | 説明 |
| - | - | - |
| `port` | なし | ClickHouse のメトリクスを提供するポート。 |
| `endpoint` | `/metrics` | メトリクスをスクレイピングするための HTTP エンドポイント。`/` で始まります。`<handlers>` セクションと併用しないでください。 |
| `url` / `headers` / `method` | なし | リクエストに一致するハンドラーを探すために使用されるフィルター。[`<http_handlers>`](/ja/concepts/features/interfaces/http) セクションの同名のフィールドと同様です。 |
| `info` | true | サーバーの識別ラベル (`name`、`version`、`version_describe`、`version_major`、`version_minor`、`version_patch`) を付与した `ClickHouse_Info` gauge を公開します。 |
| `metrics` | true | [`system.metrics`](/ja/reference/system-tables/metrics) のメトリクスを公開します。 |
| `asynchronous_metrics` | true | [`system.asynchronous_metrics`](/ja/reference/system-tables/asynchronous_metrics) のメトリクスを公開します。 |
| `events` | true | [`system.events`](/ja/reference/system-tables/events) のメトリクスを公開します。 |
| `errors` | true | [`system.errors`](/ja/reference/system-tables/errors) のエラー件数を公開します。 |
| `histograms` | true | [`system.histogram_metrics`](/ja/reference/system-tables/histogram_metrics) のメトリクスを公開します。 |
| `dimensional_metrics` | true | [`system.dimensional_metrics`](/ja/reference/system-tables/dimensional_metrics) のメトリクスを公開します。 |
| `labels` | なし | 公開されるすべてのメトリクスに追加される定数ラベル。各子要素が 1 つのラベルを定義し、要素名がラベル名 (`[a-zA-Z_][a-zA-Z0-9_]*` に一致する必要があります) 、要素の値がラベル値になります。ラベル値は `from_env` 属性などの標準的な設定の置換に対応しています。ラベル名が `__` (Prometheus の予約領域) で始まる場合、または有効化されているセクションのためにこのエンドポイントがすでに書き込んでいるラベルと衝突する場合、そのラベル名は拒否されます。したがって、予約されるラベル名の集合は、そのエンドポイントが実際にエクスポートする範囲に応じて変わります。`histograms` が有効な場合は `le`、`info` が有効な場合は `ClickHouse_Info` のラベル (`name`、`version`、`version_describe`、`version_major`、`version_minor`、`version_patch`) 、`histograms` または `dimensional_metrics` が有効な場合は、公開される histogram または次元付きメトリクスの family が使用するすべてのラベル (例: `group`、`direction`、`operation_type`) が該当します。エンドポイントが実際に公開する内容によって決まるため、あるエンドポイントでは有効な名前が、別のエンドポイントでは拒否されることがあります。 |

<h2 id="check-the-endpoint">
  エンドポイントを確認する
</h2>

```bash theme={null}
curl http://127.0.0.1:9363/metrics
```
