mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
feat(usage): add in-memory usage statistics tracking and API endpoint
- Introduced in-memory request statistics aggregation in `LoggerPlugin`. - Added new structures for detailed metrics collection (e.g., token breakdown, request success/failure). - Implemented `/usage` management API endpoint for retrieving aggregated statistics. - Updated management handlers to support the new usage statistics functionality. - Enhanced documentation to describe the usage metrics API.
This commit is contained in:
@@ -476,31 +476,6 @@ func (s *Service) ensureAuthDir() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// syncCoreAuthFromAuths registers or updates core auths and disables missing ones.
|
||||
func (s *Service) syncCoreAuthFromAuths(ctx context.Context, auths []*coreauth.Auth) {
|
||||
if s.coreManager == nil {
|
||||
return
|
||||
}
|
||||
seen := make(map[string]struct{}, len(auths))
|
||||
for _, a := range auths {
|
||||
if a == nil || a.ID == "" {
|
||||
continue
|
||||
}
|
||||
seen[a.ID] = struct{}{}
|
||||
s.applyCoreAuthAddOrUpdate(ctx, a)
|
||||
}
|
||||
// Disable removed auths
|
||||
for _, stored := range s.coreManager.List() {
|
||||
if stored == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[stored.ID]; ok {
|
||||
continue
|
||||
}
|
||||
s.applyCoreAuthRemoval(ctx, stored.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// registerModelsForAuth (re)binds provider models in the global registry using the core auth ID as client identifier.
|
||||
func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
if a == nil || a.ID == "" {
|
||||
|
||||
Reference in New Issue
Block a user