Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
"kb_final_top_k": 5, # 知识库检索最终返回结果数量
"kb_agentic_mode": False,
"disable_builtin_commands": False,
"disable_metrics": False,
}


Expand Down Expand Up @@ -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"],
Expand Down
16 changes: 14 additions & 2 deletions astrbot/core/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Comment thread
Blueteemo marked this conversation as resolved.
"""获取或创建一个唯一的安装ID"""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@
"description": "Внешний адрес для Callback API",
"hint": "Используется для сервисов, требующих обратных выливов (например, в песочнице)."
},
"disable_metrics": {
"description": "Отключить анонимную статистику",
"hint": "После отключения AstrBot не будет отправлять анонимные данные об использовании."
},
"dashboard": {
"ssl": {
"enable": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading