|
|
@@ -209,6 +209,40 @@ export class QdrantEndpoint extends BaseEndpointComponent {
|
|
|
}
|
|
|
),
|
|
|
|
|
|
+ // System Stats
|
|
|
+ this.createEndpoint(
|
|
|
+ 'GET',
|
|
|
+ '/api/qdrant/stats',
|
|
|
+ this.getSystemStats.bind(this),
|
|
|
+ {
|
|
|
+ summary: 'Get Qdrant system statistics',
|
|
|
+ description: 'Get system-wide Qdrant statistics and metrics',
|
|
|
+ tags: ['Qdrant'],
|
|
|
+ requiresAuth: true,
|
|
|
+ responses: {
|
|
|
+ '200': {
|
|
|
+ description: 'System statistics',
|
|
|
+ schema: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ data: {
|
|
|
+ type: 'object',
|
|
|
+ properties: {
|
|
|
+ total_collections: { type: 'number' },
|
|
|
+ total_vectors: { type: 'number' },
|
|
|
+ enabled_shops: { type: 'number' },
|
|
|
+ recent_embeddings: { type: 'number' },
|
|
|
+ embedding_queue_size: { type: 'number' }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ success: { type: 'boolean' }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ),
|
|
|
+
|
|
|
// Health Check
|
|
|
this.createEndpoint(
|
|
|
'GET',
|
|
|
@@ -593,4 +627,71 @@ export class QdrantEndpoint extends BaseEndpointComponent {
|
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async getSystemStats(req: Request, res: Response): Promise<void> {
|
|
|
+ try {
|
|
|
+ let totalCollections = 0;
|
|
|
+ let totalVectors = 0;
|
|
|
+ let enabledShops = 0;
|
|
|
+ let recentEmbeddings = 0;
|
|
|
+ let embeddingQueueSize = 0;
|
|
|
+
|
|
|
+ // Get enabled shops count
|
|
|
+ try {
|
|
|
+ const shops = this.db.getQdrantEnabledShops();
|
|
|
+ enabledShops = shops.length;
|
|
|
+ } catch (error) {
|
|
|
+ logger.debug('Could not get enabled shops:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get collection stats if Qdrant is available
|
|
|
+ try {
|
|
|
+ if (this.qdrantService) {
|
|
|
+ const collections = await this.qdrantService.listCollections();
|
|
|
+ totalCollections = collections.length;
|
|
|
+ totalVectors = collections.reduce((sum, col) => sum + (col.vectors_count || 0), 0);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ logger.debug('Could not get Qdrant stats:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get recent embeddings count (last 24 hours)
|
|
|
+ try {
|
|
|
+ const oneDayAgo = new Date();
|
|
|
+ oneDayAgo.setDate(oneDayAgo.getDate() - 1);
|
|
|
+
|
|
|
+ // This would need to be implemented in the database
|
|
|
+ // For now, we'll return 0 or estimate based on available data
|
|
|
+ recentEmbeddings = 0;
|
|
|
+ } catch (error) {
|
|
|
+ logger.debug('Could not get recent embeddings:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get embedding queue size (pending embeddings)
|
|
|
+ try {
|
|
|
+ // This would typically check pending embedding jobs
|
|
|
+ // For now, return 0 as a placeholder
|
|
|
+ embeddingQueueSize = 0;
|
|
|
+ } catch (error) {
|
|
|
+ logger.debug('Could not get embedding queue size:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ res.json({
|
|
|
+ data: {
|
|
|
+ total_collections: totalCollections,
|
|
|
+ total_vectors: totalVectors,
|
|
|
+ enabled_shops: enabledShops,
|
|
|
+ recent_embeddings: recentEmbeddings,
|
|
|
+ embedding_queue_size: embeddingQueueSize
|
|
|
+ },
|
|
|
+ success: true
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ logger.error('Failed to get system stats:', error);
|
|
|
+ res.status(500).json({
|
|
|
+ error: 'Internal server error',
|
|
|
+ success: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|