Skip to content

Commit e8d3e18

Browse files
authored
feat: add disable_metrics config option for WebUI (#7946)
* feat: add disable_metrics config option for WebUI * fix: remove dead code _disable_metrics, narrow exception catching * fix: add Russian translation for disable_metrics * fix: 将 disable_metrics 移到系统配置 * fix: 将 disable_metrics 元数据从 general 移到 system 分组 --------- Co-authored-by: Blueteemo <Blueteemo@users.noreply.github.com>
1 parent 942dcdf commit e8d3e18

5 files changed

Lines changed: 32 additions & 2 deletions

File tree

astrbot/core/config/default.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
"kb_final_top_k": 5, # 知识库检索最终返回结果数量
292292
"kb_agentic_mode": False,
293293
"disable_builtin_commands": False,
294+
"disable_metrics": False,
294295
}
295296

296297

@@ -2924,6 +2925,11 @@
29242925
"callback_api_base": {
29252926
"type": "string",
29262927
},
2928+
"disable_metrics": {
2929+
"description": "禁用匿名使用统计",
2930+
"type": "bool",
2931+
"hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。",
2932+
},
29272933
"log_level": {
29282934
"type": "string",
29292935
"options": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],

astrbot/core/utils/metrics.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ class Metric:
2323
_lock: asyncio.Lock | None = None
2424
_lock_loop: asyncio.AbstractEventLoop | None = None
2525

26+
@staticmethod
27+
def _is_disabled() -> bool:
28+
"""检查是否禁用指标上传(配置或环境变量)"""
29+
if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1":
30+
return True
31+
try:
32+
from astrbot.core import astrbot_config
33+
34+
return astrbot_config.get("disable_metrics", False)
35+
except (ImportError, AttributeError, KeyError):
36+
return False
37+
2638
@staticmethod
2739
def get_installation_id():
2840
"""获取或创建一个唯一的安装ID"""
@@ -173,7 +185,7 @@ async def flush() -> None:
173185

174186
@staticmethod
175187
async def _post_metrics(metrics_data: dict[str, Any]) -> None:
176-
if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1":
188+
if Metric._is_disabled():
177189
return
178190

179191
base_url = "https://tickstats.soulter.top/api/metric/90a6c2a1"
@@ -204,7 +216,7 @@ async def upload(**kwargs) -> None:
204216
205217
Powered by TickStats.
206218
"""
207-
if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1":
219+
if Metric._is_disabled():
208220
return
209221

210222
await Metric._save_platform_stats(kwargs)

dashboard/src/i18n/locales/en-US/features/config-metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@
10831083
"description": "Externally Accessible Callback API Address",
10841084
"hint": "External services may access AstrBot's backend through callback links generated by AstrBot (such as file download links). Since AstrBot cannot automatically determine the externally accessible host address in the deployment environment, this configuration item is needed to explicitly specify how external services should access AstrBot's address. Examples: [http://localhost:6185](http://localhost:6185), [https://example.com](https://example.com), etc."
10851085
},
1086+
"disable_metrics": {
1087+
"description": "Disable Anonymous Usage Statistics",
1088+
"hint": "When disabled, AstrBot will not upload anonymous usage statistics."
1089+
},
10861090
"dashboard": {
10871091
"ssl": {
10881092
"enable": {

dashboard/src/i18n/locales/ru-RU/features/config-metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@
10841084
"description": "Внешний адрес для Callback API",
10851085
"hint": "Используется для сервисов, требующих обратных выливов (например, в песочнице)."
10861086
},
1087+
"disable_metrics": {
1088+
"description": "Отключить анонимную статистику",
1089+
"hint": "После отключения AstrBot не будет отправлять анонимные данные об использовании."
1090+
},
10871091
"dashboard": {
10881092
"ssl": {
10891093
"enable": {

dashboard/src/i18n/locales/zh-CN/features/config-metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,10 @@
10851085
"description": "对外可达的回调接口地址",
10861086
"hint": "外部服务可能会通过 AstrBot 生成的回调链接(如文件下载链接)访问 AstrBot 后端。由于 AstrBot 无法自动判断部署环境中对外可达的主机地址(host),因此需要通过此配置项显式指定外部服务如何访问 AstrBot 的地址。如 [http://localhost:6185](http://localhost:6185),[https://example.com](https://example.com) 等。"
10871087
},
1088+
"disable_metrics": {
1089+
"description": "禁用匿名使用统计",
1090+
"hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。"
1091+
},
10881092
"dashboard": {
10891093
"ssl": {
10901094
"enable": {

0 commit comments

Comments
 (0)