From 3ad7dd49b6c838f3c6cf166343171a12591e7f1f Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Fri, 1 May 2026 21:05:26 +0800 Subject: [PATCH 1/5] feat: add disable_metrics config option for WebUI --- astrbot/core/config/default.py | 6 ++++++ astrbot/core/utils/metrics.py | 19 +++++++++++++++++-- .../en-US/features/config-metadata.json | 4 ++++ .../zh-CN/features/config-metadata.json | 4 ++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 60a5a7555d..174c111460 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -291,6 +291,7 @@ "kb_final_top_k": 5, # 知识库检索最终返回结果数量 "kb_agentic_mode": False, "disable_builtin_commands": False, + "disable_metrics": False, } @@ -3820,6 +3821,11 @@ class ChatProviderTemplate(TypedDict): "type": "bool", "hint": "禁用所有 AstrBot 的自带指令,如 help, provider, model 等。", }, + "disable_metrics": { + "description": "禁用匿名使用统计", + "type": "bool", + "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。", + }, }, }, "whitelist": { diff --git a/astrbot/core/utils/metrics.py b/astrbot/core/utils/metrics.py index 43955568e1..af42a23450 100644 --- a/astrbot/core/utils/metrics.py +++ b/astrbot/core/utils/metrics.py @@ -22,6 +22,21 @@ class Metric: _flush_task: asyncio.Task | None = None _lock: asyncio.Lock | None = None _lock_loop: asyncio.AbstractEventLoop | None = None + _disable_metrics: bool = False + + @staticmethod + def _is_disabled() -> bool: + """检查是否禁用指标上传(配置或环境变量)""" + if Metric._disable_metrics: + return True + if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1": + return True + try: + from astrbot.core import astrbot_config + + return astrbot_config.get("disable_metrics", False) + except Exception: + return False @staticmethod def get_installation_id(): @@ -173,7 +188,7 @@ async def flush() -> None: @staticmethod async def _post_metrics(metrics_data: dict[str, Any]) -> None: - if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1": + if Metric._is_disabled(): return base_url = "https://tickstats.soulter.top/api/metric/90a6c2a1" @@ -204,7 +219,7 @@ async def upload(**kwargs) -> None: Powered by TickStats. """ - if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1": + if Metric._is_disabled(): return await Metric._save_platform_stats(kwargs) diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index 689c460d83..ae4850bf72 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -790,6 +790,10 @@ "disable_builtin_commands": { "description": "Disable Built-in Commands", "hint": "Disable all built-in AstrBot commands such as help, provider, model, etc." + }, + "disable_metrics": { + "description": "Disable Anonymous Usage Statistics", + "hint": "When disabled, AstrBot will not upload anonymous usage statistics." } }, "whitelist": { diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index e00ba6cb5f..c3bc5fe1b8 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -792,6 +792,10 @@ "disable_builtin_commands": { "description": "禁用自带指令", "hint": "禁用所有 AstrBot 自带指令,如 help, provider, model 等" + }, + "disable_metrics": { + "description": "禁用匿名使用统计", + "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。" } }, "whitelist": { From 5f961b571795a49d66a295f9ce47bfc04e5a12a5 Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Fri, 1 May 2026 21:14:16 +0800 Subject: [PATCH 2/5] fix: remove dead code _disable_metrics, narrow exception catching --- astrbot/core/utils/metrics.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/astrbot/core/utils/metrics.py b/astrbot/core/utils/metrics.py index af42a23450..6831eaca9b 100644 --- a/astrbot/core/utils/metrics.py +++ b/astrbot/core/utils/metrics.py @@ -22,20 +22,17 @@ class Metric: _flush_task: asyncio.Task | None = None _lock: asyncio.Lock | None = None _lock_loop: asyncio.AbstractEventLoop | None = None - _disable_metrics: bool = False @staticmethod def _is_disabled() -> bool: """检查是否禁用指标上传(配置或环境变量)""" - if Metric._disable_metrics: - return True if os.environ.get("ASTRBOT_DISABLE_METRICS", "0") == "1": return True try: from astrbot.core import astrbot_config return astrbot_config.get("disable_metrics", False) - except Exception: + except (ImportError, AttributeError, KeyError): return False @staticmethod From c22a1c99375ec730a941656c63be7f1e8e17b85b Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Fri, 1 May 2026 21:50:46 +0800 Subject: [PATCH 3/5] fix: add Russian translation for disable_metrics --- .../src/i18n/locales/ru-RU/features/config-metadata.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json index ec124eeeec..e9479cbf7f 100644 --- a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json +++ b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json @@ -791,6 +791,10 @@ "disable_builtin_commands": { "description": "Отключить встроенные команды", "hint": "Отключает help, provider, model и другие базовые команды." + }, + "disable_metrics": { + "description": "Отключить анонимную статистику", + "hint": "После отключения AstrBot не будет отправлять анонимные данные об использовании." } }, "whitelist": { From df0999c4faf394eeac463a9aeba198fe832e84e2 Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Sun, 3 May 2026 03:13:45 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E5=B0=86=20disable=5Fmetrics=20?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/i18n/locales/en-US/features/config-metadata.json | 8 ++++---- .../src/i18n/locales/ru-RU/features/config-metadata.json | 8 ++++---- .../src/i18n/locales/zh-CN/features/config-metadata.json | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index ae4850bf72..de4872fc48 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -790,10 +790,6 @@ "disable_builtin_commands": { "description": "Disable Built-in Commands", "hint": "Disable all built-in AstrBot commands such as help, provider, model, etc." - }, - "disable_metrics": { - "description": "Disable Anonymous Usage Statistics", - "hint": "When disabled, AstrBot will not upload anonymous usage statistics." } }, "whitelist": { @@ -1087,6 +1083,10 @@ "description": "Externally Accessible Callback API Address", "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." }, + "disable_metrics": { + "description": "Disable Anonymous Usage Statistics", + "hint": "When disabled, AstrBot will not upload anonymous usage statistics." + }, "dashboard": { "ssl": { "enable": { diff --git a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json index e9479cbf7f..3b620a514c 100644 --- a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json +++ b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json @@ -791,10 +791,6 @@ "disable_builtin_commands": { "description": "Отключить встроенные команды", "hint": "Отключает help, provider, model и другие базовые команды." - }, - "disable_metrics": { - "description": "Отключить анонимную статистику", - "hint": "После отключения AstrBot не будет отправлять анонимные данные об использовании." } }, "whitelist": { @@ -1088,6 +1084,10 @@ "description": "Внешний адрес для Callback API", "hint": "Используется для сервисов, требующих обратных выливов (например, в песочнице)." }, + "disable_metrics": { + "description": "Отключить анонимную статистику", + "hint": "После отключения AstrBot не будет отправлять анонимные данные об использовании." + }, "dashboard": { "ssl": { "enable": { diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index c3bc5fe1b8..52833acd53 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -792,10 +792,6 @@ "disable_builtin_commands": { "description": "禁用自带指令", "hint": "禁用所有 AstrBot 自带指令,如 help, provider, model 等" - }, - "disable_metrics": { - "description": "禁用匿名使用统计", - "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。" } }, "whitelist": { @@ -1089,6 +1085,10 @@ "description": "对外可达的回调接口地址", "hint": "外部服务可能会通过 AstrBot 生成的回调链接(如文件下载链接)访问 AstrBot 后端。由于 AstrBot 无法自动判断部署环境中对外可达的主机地址(host),因此需要通过此配置项显式指定外部服务如何访问 AstrBot 的地址。如 [http://localhost:6185](http://localhost:6185),[https://example.com](https://example.com) 等。" }, + "disable_metrics": { + "description": "禁用匿名使用统计", + "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。" + }, "dashboard": { "ssl": { "enable": { From 2f9b94dd5a2cb3f94e92f66b534f1d5ff6dadb47 Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Sun, 3 May 2026 03:53:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E5=B0=86=20disable=5Fmetrics=20?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E4=BB=8E=20general=20=E7=A7=BB?= =?UTF-8?q?=E5=88=B0=20system=20=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 174c111460..4d7eadbc09 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -2943,6 +2943,11 @@ class ChatProviderTemplate(TypedDict): "callback_api_base": { "type": "string", }, + "disable_metrics": { + "description": "禁用匿名使用统计", + "type": "bool", + "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。", + }, "log_level": { "type": "string", "options": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], @@ -3821,11 +3826,6 @@ class ChatProviderTemplate(TypedDict): "type": "bool", "hint": "禁用所有 AstrBot 的自带指令,如 help, provider, model 等。", }, - "disable_metrics": { - "description": "禁用匿名使用统计", - "type": "bool", - "hint": "禁用后,AstrBot 将不再上传匿名使用统计数据。", - }, }, }, "whitelist": {