From 5ef7247eaccb4db69397cf176448db90312f3d21 Mon Sep 17 00:00:00 2001 From: Seefs Date: Fri, 19 Dec 2025 23:03:04 +0800 Subject: [PATCH] docs: document pyroscope env var --- .env.example | 6 ++++++ README.en.md | 5 +++++ README.fr.md | 5 +++++ README.ja.md | 5 +++++ README.md | 5 +++++ common/pyro.go | 9 +++++++-- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index f43f7b211..c059777d3 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,12 @@ # ENABLE_PPROF=true # 启用调试模式 # DEBUG=true +# Pyroscope 配置 +# PYROSCOPE_URL=http://localhost:4040 +# PYROSCOPE_APP_NAME=new-api +# PYROSCOPE_BASIC_AUTH_USER=your-user +# PYROSCOPE_BASIC_AUTH_PASSWORD=your-password +# HOSTNAME=your-hostname # 数据库相关配置 # 数据库连接字符串 diff --git a/README.en.md b/README.en.md index e71f5e623..f53c9742a 100644 --- a/README.en.md +++ b/README.en.md @@ -307,6 +307,11 @@ docker run --name new-api -d --restart always \ | `STREAM_SCANNER_MAX_BUFFER_MB` | Max per-line buffer (MB) for the stream scanner; increase when upstream sends huge image/base64 payloads | `64` | | `AZURE_DEFAULT_API_VERSION` | Azure API version | `2025-04-01-preview` | | `ERROR_LOG_ENABLED` | Error log switch | `false` | +| `PYROSCOPE_URL` | Pyroscope server address | - | +| `PYROSCOPE_APP_NAME` | Pyroscope application name | `new-api` | +| `PYROSCOPE_BASIC_AUTH_USER` | Pyroscope basic auth user | - | +| `PYROSCOPE_BASIC_AUTH_PASSWORD` | Pyroscope basic auth password | - | +| `HOSTNAME` | Hostname tag for Pyroscope | `new-api` | 📖 **Complete configuration:** [Environment Variables Documentation](https://docs.newapi.pro/installation/environment-variables) diff --git a/README.fr.md b/README.fr.md index 35051223e..362a8b652 100644 --- a/README.fr.md +++ b/README.fr.md @@ -303,6 +303,11 @@ docker run --name new-api -d --restart always \ | `STREAM_SCANNER_MAX_BUFFER_MB` | Taille max du buffer par ligne (Mo) pour le scanner SSE ; à augmenter quand les sorties image/base64 sont très volumineuses (ex. images 4K) | `64` | | `AZURE_DEFAULT_API_VERSION` | Version de l'API Azure | `2025-04-01-preview` | | `ERROR_LOG_ENABLED` | Interrupteur du journal d'erreurs | `false` | +| `PYROSCOPE_URL` | Adresse du serveur Pyroscope | - | +| `PYROSCOPE_APP_NAME` | Nom de l'application Pyroscope | `new-api` | +| `PYROSCOPE_BASIC_AUTH_USER` | Utilisateur Basic Auth Pyroscope | - | +| `PYROSCOPE_BASIC_AUTH_PASSWORD` | Mot de passe Basic Auth Pyroscope | - | +| `HOSTNAME` | Nom d'hôte tagué pour Pyroscope | `new-api` | 📖 **Configuration complète:** [Documentation des variables d'environnement](https://docs.newapi.pro/installation/environment-variables) diff --git a/README.ja.md b/README.ja.md index 0c4b91f66..258280f07 100644 --- a/README.ja.md +++ b/README.ja.md @@ -312,6 +312,11 @@ docker run --name new-api -d --restart always \ | `STREAM_SCANNER_MAX_BUFFER_MB` | ストリームスキャナの1行あたりバッファ上限(MB)。4K画像など巨大なbase64 `data:` ペイロードを扱う場合は値を増加させてください | `64` | | `AZURE_DEFAULT_API_VERSION` | Azure APIバージョン | `2025-04-01-preview` | | `ERROR_LOG_ENABLED` | エラーログスイッチ | `false` | +| `PYROSCOPE_URL` | Pyroscopeサーバーのアドレス | - | +| `PYROSCOPE_APP_NAME` | Pyroscopeアプリ名 | `new-api` | +| `PYROSCOPE_BASIC_AUTH_USER` | Pyroscope Basic Authユーザー | - | +| `PYROSCOPE_BASIC_AUTH_PASSWORD` | Pyroscope Basic Authパスワード | - | +| `HOSTNAME` | Pyroscope用のホスト名タグ | `new-api` | 📖 **完全な設定:** [環境変数ドキュメント](https://docs.newapi.pro/installation/environment-variables) diff --git a/README.md b/README.md index 3d5b6923c..8210babe8 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,11 @@ docker run --name new-api -d --restart always \ | `STREAM_SCANNER_MAX_BUFFER_MB` | 流式扫描器单行最大缓冲(MB),图像生成等超大 `data:` 片段(如 4K 图片 base64)需适当调大 | `64` | | `AZURE_DEFAULT_API_VERSION` | Azure API 版本 | `2025-04-01-preview` | | `ERROR_LOG_ENABLED` | 错误日志开关 | `false` | +| `PYROSCOPE_URL` | Pyroscope 服务地址 | - | +| `PYROSCOPE_APP_NAME` | Pyroscope 应用名 | `new-api` | +| `PYROSCOPE_BASIC_AUTH_USER` | Pyroscope Basic Auth 用户名 | - | +| `PYROSCOPE_BASIC_AUTH_PASSWORD` | Pyroscope Basic Auth 密码 | - | +| `HOSTNAME` | Pyroscope 标签里的主机名 | `new-api` | 📖 **完整配置:** [环境变量文档](https://docs.newapi.pro/installation/environment-variables) diff --git a/common/pyro.go b/common/pyro.go index 9891bac1c..739f1d116 100644 --- a/common/pyro.go +++ b/common/pyro.go @@ -14,6 +14,9 @@ func StartPyroScope() error { } pyroscopeAppName := GetEnvOrDefaultString("PYROSCOPE_APP_NAME", "new-api") + pyroscopeBasicAuthUser := GetEnvOrDefaultString("PYROSCOPE_BASIC_AUTH_USER", "") + pyroscopeBasicAuthPassword := GetEnvOrDefaultString("PYROSCOPE_BASIC_AUTH_PASSWORD", "") + pyroscopeHostname := GetEnvOrDefaultString("HOSTNAME", "new-api") // These 2 lines are only required if you're using mutex or block profiling // Read the explanation below for how to set these rates: @@ -23,11 +26,13 @@ func StartPyroScope() error { _, err := pyroscope.Start(pyroscope.Config{ ApplicationName: pyroscopeAppName, - ServerAddress: pyroscopeUrl, + ServerAddress: pyroscopeUrl, + BasicAuthUser: pyroscopeBasicAuthUser, + BasicAuthPassword: pyroscopeBasicAuthPassword, Logger: nil, - Tags: map[string]string{"hostname": GetEnvOrDefaultString("HOSTNAME", "new-api")}, + Tags: map[string]string{"hostname": pyroscopeHostname}, ProfileTypes: []pyroscope.ProfileType{ pyroscope.ProfileCPU,