# 可觀測性

> 使用 Langfuse 追蹤每個 LLM 呼叫，並透過 Grafana 和 OpenTelemetry 監控整個系統——這是內建儀表板之外的兩個可選堆疊。

兩個選用堆疊可顯示 PentAGI 的運作狀態：Langfuse 用於模型呼叫，Grafana 搭配 OpenTelemetry 則涵蓋系統其餘部分。

PentAGI 內建的 **Dashboard** 已提供 [flows](https://pentagi.com/zh-tw/docs/glossary/#flow)、[tool calls](https://pentagi.com/zh-tw/docs/glossary/#tool-call)、token 與成本隨時間變化的圖表；下方的堆疊則補充了完整的追蹤紀錄與系統指標。

![內建儀表板](https://pentagi.com/images/product/dashboard.webp)

## [Langfuse](https://pentagi.com/zh-tw/docs/configuration/observability/#langfuse)

Langfuse 會記錄每個 [agent](https://pentagi.com/zh-tw/docs/glossary/#agent) 的提示、完成內容、token 與成本。

```bash
LANGFUSE_BASE_URL=http://langfuse-web:3000
LANGFUSE_PROJECT_ID=same_as_LANGFUSE_INIT_PROJECT_ID
LANGFUSE_PUBLIC_KEY=same_as_LANGFUSE_INIT_PROJECT_PUBLIC_KEY
LANGFUSE_SECRET_KEY=same_as_LANGFUSE_INIT_PROJECT_SECRET_KEY
```

請在 `.env` 中設定 Langfuse 憑證（`LANGFUSE_POSTGRES_*`、`LANGFUSE_CLICKHOUSE_*`、`LANGFUSE_REDIS_AUTH`、`LANGFUSE_SALT`、`LANGFUSE_ENCRYPTION_KEY`、`LANGFUSE_NEXTAUTH_SECRET`、`LANGFUSE_INIT_USER_*` 及專案金鑰），然後啟動堆疊：

```bash
curl -O https://raw.githubusercontent.com/vxcontrol/pentagi/main/docker-compose-langfuse.yml
docker compose -f docker-compose.yml -f docker-compose-langfuse.yml up -d
```

Langfuse UI 可於 `http://localhost:4000` 存取。

## [Grafana 與 OpenTelemetry](https://pentagi.com/zh-tw/docs/configuration/observability/#grafana-and-opentelemetry)

```bash
OTEL_HOST=otelcol:8148
```

```bash
git clone --depth 1 https://github.com/vxcontrol/pentagi.git pentagi-src
cp -r pentagi-src/observability ./observability
rm -rf pentagi-src
curl -O https://raw.githubusercontent.com/vxcontrol/pentagi/main/docker-compose-observability.yml
docker compose -f docker-compose.yml -f docker-compose-observability.yml up -d
```

Grafana 可於 `http://localhost:3000` 存取，其中指標儲存於 VictoriaMetrics，追蹤紀錄儲存於 Jaeger，日誌則儲存於 Loki。

> [!NOTE]
> 若要將 Langfuse 遙測資料傳送至同一個堆疊，請設定 `LANGFUSE_OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol:4318`。

## [整合所有服務](https://pentagi.com/zh-tw/docs/configuration/observability/#everything-together)

```bash
git clone --depth 1 https://github.com/vxcontrol/pentagi.git pentagi-src
cp -r pentagi-src/examples/graphiti ./graphiti
cp -r pentagi-src/examples/neo4j ./neo4j
rm -rf pentagi-src
curl -O https://raw.githubusercontent.com/vxcontrol/pentagi/main/docker-compose-graphiti.yml
docker compose \
  -f docker-compose.yml \
  -f docker-compose-langfuse.yml \
  -f docker-compose-graphiti.yml \
  -f docker-compose-observability.yml \
  up -d
```