mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
directly return number of active users from backend for usage display
This commit is contained in:
@@ -58,7 +58,7 @@ from open_webui.socket.main import (
|
|||||||
app as socket_app,
|
app as socket_app,
|
||||||
periodic_usage_pool_cleanup,
|
periodic_usage_pool_cleanup,
|
||||||
get_models_in_use,
|
get_models_in_use,
|
||||||
get_active_user_ids,
|
get_active_users_count,
|
||||||
)
|
)
|
||||||
from open_webui.routers import (
|
from open_webui.routers import (
|
||||||
audio,
|
audio,
|
||||||
@@ -1663,7 +1663,7 @@ async def get_current_usage(user=Depends(get_verified_user)):
|
|||||||
This is an experimental endpoint and subject to change.
|
This is an experimental endpoint and subject to change.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return {"model_ids": get_models_in_use(), "user_ids": get_active_user_ids()}
|
return {"model_ids": get_models_in_use(), "users_count": get_active_users_count()}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Error getting usage statistics: {e}")
|
log.error(f"Error getting usage statistics: {e}")
|
||||||
raise HTTPException(status_code=500, detail="Internal Server Error")
|
raise HTTPException(status_code=500, detail="Internal Server Error")
|
||||||
|
|||||||
@@ -152,6 +152,11 @@ def get_models_in_use():
|
|||||||
return models_in_use
|
return models_in_use
|
||||||
|
|
||||||
|
|
||||||
|
def get_active_users_count():
|
||||||
|
"""Get the number of active users."""
|
||||||
|
return len(USER_POOL)
|
||||||
|
|
||||||
|
|
||||||
def get_active_user_ids():
|
def get_active_user_ids():
|
||||||
"""Get the list of active user IDs."""
|
"""Get the list of active user IDs."""
|
||||||
return list(USER_POOL.keys())
|
return list(USER_POOL.keys())
|
||||||
|
|||||||
@@ -206,40 +206,40 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{#if usage}
|
{#if usage}
|
||||||
{#if usage?.user_ids?.length > 0}
|
<hr class=" border-gray-100 dark:border-gray-800 my-1 p-0" />
|
||||||
<hr class=" border-gray-100 dark:border-gray-800 my-1 p-0" />
|
|
||||||
|
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={usage?.model_ids && usage?.model_ids.length > 0
|
content={usage?.model_ids && usage?.model_ids.length > 0
|
||||||
? `${$i18n.t('Running')}: ${usage.model_ids.join(', ')} ✨`
|
? `${$i18n.t('Running')}: ${usage.model_ids.join(', ')} ✨`
|
||||||
: ''}
|
: ''}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex rounded-md py-1 px-3 text-xs gap-2.5 items-center"
|
||||||
|
on:mouseenter={() => {
|
||||||
|
getUsageInfo();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div class=" flex items-center">
|
||||||
class="flex rounded-md py-1 px-3 text-xs gap-2.5 items-center"
|
<span class="relative flex size-2">
|
||||||
on:mouseenter={() => {
|
<span
|
||||||
getUsageInfo();
|
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
|
||||||
}}
|
/>
|
||||||
>
|
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
|
||||||
<div class=" flex items-center">
|
</span>
|
||||||
<span class="relative flex size-2">
|
</div>
|
||||||
<span
|
|
||||||
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
|
|
||||||
/>
|
|
||||||
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
{#if usage?.users_count}
|
||||||
<div class=" ">
|
<div class=" ">
|
||||||
<span class="">
|
<span class="">
|
||||||
{$i18n.t('Active Users')}:
|
{$i18n.t('Active Users')}:
|
||||||
</span>
|
</span>
|
||||||
<span class=" font-semibold">
|
<span class=" font-semibold">
|
||||||
{usage?.user_ids?.length}
|
{usage?.users_count}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
</Tooltip>
|
</div>
|
||||||
{/if}
|
</Tooltip>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- <DropdownMenu.Item class="flex items-center py-1.5 px-3 text-sm ">
|
<!-- <DropdownMenu.Item class="flex items-center py-1.5 px-3 text-sm ">
|
||||||
|
|||||||
Reference in New Issue
Block a user