diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 60a5a7555d..4d7eadbc09 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, } @@ -2942,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"], diff --git a/astrbot/core/utils/metrics.py b/astrbot/core/utils/metrics.py index 43955568e1..6831eaca9b 100644 --- a/astrbot/core/utils/metrics.py +++ b/astrbot/core/utils/metrics.py @@ -23,6 +23,18 @@ class Metric: _lock: asyncio.Lock | None = None _lock_loop: asyncio.AbstractEventLoop | None = None + @staticmethod + def _is_disabled() -> bool: + """检查是否禁用指标上传(配置或环境变量)""" + 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 (ImportError, AttributeError, KeyError): + return False + @staticmethod def get_installation_id(): """获取或创建一个唯一的安装ID""" @@ -173,7 +185,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 +216,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..de4872fc48 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -1083,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 ec124eeeec..3b620a514c 100644 --- a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json +++ b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json @@ -1084,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 e00ba6cb5f..52833acd53 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -1085,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": {