File tree Expand file tree Collapse file tree 5 files changed +121
-0
lines changed 
doc/7/controllers/index/stats Expand file tree Collapse file tree 5 files changed +121
-0
lines changed Original file line number Diff line number Diff line change 1+ --- 
2+ code : true 
3+ type : page 
4+ title : stats 
5+ description : Gets detailed storage statistics 
6+ --- 
7+ 
8+ # stats  
9+ 
10+ <SinceBadge  version =" Kuzzle 2.10.0 " />
11+ <SinceBadge  version =" auto-version " />
12+ 
13+ Gets detailed storage usage statistics.
14+ 
15+ <br />
16+ 
17+ ``` js 
18+ stats ([options]);
19+ ``` 
20+ 
21+ <br />
22+ 
23+ |  Arguments |  Type              |  Description   | 
24+ |  --------- |  ----------------- |  ------------- | 
25+ |  ` options `  |  <pre >object</pre > |  Query options | 
26+ 
27+ ### options  
28+ 
29+ Additional query options
30+ 
31+ |  Property   |  Type<br />(default)              |  Description                                                                  | 
32+ |  ---------- |  ------------------------------- |  ---------------------------------------------------------------------------- | 
33+ |  ` queuable `  |  <pre >boolean</pre ><br />(` true ` ) |  If true, queues the request during downtime, until connected to Kuzzle again | 
34+ 
35+ ## Resolves  
36+ 
37+ Returns detailed storage usage statistics: overall index/collection sizes and the number of documents per collection.
38+ 
39+ ## Usage  
40+ 
41+ <<< ./snippets/stats.js
Original file line number Diff line number Diff line change 1+ const  stats  =  await  kuzzle . index . stats ( ) ; 
2+ 
3+ console . log ( JSON . stringify ( stats ) ) ; 
4+ /* 
5+   { 
6+     "indexes":[ 
7+       { 
8+         "name":"nyc-open-data", 
9+         "size":42, 
10+         "collections":[ 
11+           { 
12+             "name":"yellow-taxi", 
13+             "documentCount":42, 
14+             "size":42 
15+           } 
16+         ] 
17+       } 
18+     ], 
19+     "size":42 
20+   } 
21+ */ 
Original file line number Diff line number Diff line change 1+ ---
2+ name : index#stats 
3+ description : Gets detailed storage statistics 
4+ hooks :
5+   before : | 
6+     curl -X POST kuzzle:7512/nyc-open-data/_create 
7+     curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi 
8+    after : curl -X DELETE kuzzle:7512/nyc-open-data 
9+ template : catch 
10+ expected : ["documentCount":0] 
Original file line number Diff line number Diff line change 11import  {  BaseController  }  from  './Base' ; 
2+ import  {  JSONObject  }  from  '../types' ; 
23
34export  class  IndexController  extends  BaseController  { 
45
@@ -99,4 +100,19 @@ export class IndexController extends BaseController {
99100    return  this . query ( request ,  options ) 
100101      . then ( response  =>  response . result . deleted ) ; 
101102  } 
103+ 
104+   /** 
105+    * Returns detailed storage usage statistics. 
106+    * 
107+    * @see  https://docs.kuzzle.io/sdk/js/7/controllers/index/stats/ 
108+    * 
109+    * @param  options Additional options 
110+    *    - `queuable` If true, queues the request during downtime, until connected to Kuzzle again 
111+    */ 
112+   stats  ( options : {  queuable ?: boolean  }  =  { } ) : Promise < JSONObject >  { 
113+     return  this . query ( { 
114+       action : 'stats' 
115+     } ,  options ) 
116+       . then ( response  =>  response . result ) ; 
117+   } 
102118} 
Original file line number Diff line number Diff line change @@ -120,4 +120,37 @@ describe('Index Controller', () => {
120120        } ) ; 
121121    } ) ; 
122122  } ) ; 
123+ 
124+   describe ( 'stats' ,  ( )  =>  { 
125+     it ( 'should call index/stats query and return a Promise which resolves to an object containing detailed storage statistics' ,  ( )  =>  { 
126+       const  result  =  { 
127+         indexes : [ 
128+           { 
129+             name : 'nyc-open-data' , 
130+             size : 42 , 
131+             collections : [ 
132+               { 
133+                 name : 'yellow-taxi' , 
134+                 documentCount : 42 , 
135+                 size : 42 , 
136+               } 
137+             ] 
138+           } 
139+         ] 
140+       } ; 
141+       kuzzle . query . resolves ( { result} ) ; 
142+ 
143+       return  kuzzle . index . stats ( options ) 
144+         . then ( res  =>  { 
145+           should ( kuzzle . query ) 
146+             . be . calledOnce ( ) 
147+             . be . calledWith ( { 
148+               controller : 'index' , 
149+               action : 'stats' 
150+             } ,  options ) ; 
151+ 
152+           should ( res ) . be . equal ( result ) ; 
153+         } ) ; 
154+     } ) ; 
155+   } ) ; 
123156} ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments