Skip to content
Merged
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
41 changes: 41 additions & 0 deletions doc/7/controllers/index/stats/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
code: true
type: page
title: stats
description: Gets detailed storage statistics
---

# stats

<SinceBadge version="Kuzzle 2.10.0"/>
<SinceBadge version="auto-version"/>

Gets detailed storage usage statistics.

<br/>

```js
stats([options]);
```

<br/>

| Arguments | Type | Description |
| --------- | ----------------- | ------------- |
| `options` | <pre>object</pre> | Query options |

### options

Additional query options

| Property | Type<br/>(default) | Description |
| ---------- | ------------------------------- | ---------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |

## Resolves

Returns detailed storage usage statistics: overall index/collection sizes and the number of documents per collection.

## Usage

<<< ./snippets/stats.js
21 changes: 21 additions & 0 deletions doc/7/controllers/index/stats/snippets/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const stats = await kuzzle.index.stats();

console.log(JSON.stringify(stats));
/*
{
"indexes":[
{
"name":"nyc-open-data",
"size":42,
"collections":[
{
"name":"yellow-taxi",
"documentCount":42,
"size":42
}
]
}
],
"size":42
}
*/
10 changes: 10 additions & 0 deletions doc/7/controllers/index/stats/snippets/stats.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: index#stats
description: Gets detailed storage statistics
hooks:
before: |
curl -X POST kuzzle:7512/nyc-open-data/_create
curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi
after: curl -X DELETE kuzzle:7512/nyc-open-data
template: catch
expected: ["documentCount":0]
16 changes: 16 additions & 0 deletions src/controllers/Index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseController } from './Base';
import { JSONObject } from '../types';

export class IndexController extends BaseController {

Expand Down Expand Up @@ -99,4 +100,19 @@ export class IndexController extends BaseController {
return this.query(request, options)
.then(response => response.result.deleted);
}

/**
* Returns detailed storage usage statistics.
*
* @see https://docs.kuzzle.io/sdk/js/7/controllers/index/stats/
*
* @param options Additional options
* - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
*/
stats (options: { queuable?: boolean } = {}): Promise<JSONObject> {
return this.query({
action: 'stats'
}, options)
.then(response => response.result);
}
}
33 changes: 33 additions & 0 deletions test/controllers/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,37 @@ describe('Index Controller', () => {
});
});
});

describe('stats', () => {
it('should call index/stats query and return a Promise which resolves to an object containing detailed storage statistics', () => {
const result = {
indexes: [
{
name: 'nyc-open-data',
size: 42,
collections: [
{
name: 'yellow-taxi',
documentCount: 42,
size: 42,
}
]
}
]
};
kuzzle.query.resolves({result});

return kuzzle.index.stats(options)
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
controller: 'index',
action: 'stats'
}, options);

should(res).be.equal(result);
});
});
});
});