mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
api: add getStats() function
This commit is contained in:
parent
eb45934788
commit
82b919fc65
3 changed files with 49 additions and 2 deletions
|
@ -65,7 +65,7 @@ Portal submits content into new blog post
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### API version
|
### API version
|
||||||
The latest version is `1.2.13`
|
The latest version is `1.2.14`
|
||||||
|
|
||||||
The current version can be queried via /api.
|
The current version can be queried via /api.
|
||||||
|
|
||||||
|
@ -634,3 +634,14 @@ lists all pads on this epl instance
|
||||||
|
|
||||||
*Example returns:*
|
*Example returns:*
|
||||||
* `{code: 0, message:"ok", data: {padIDs: ["testPad", "thePadsOfTheOthers"]}}`
|
* `{code: 0, message:"ok", data: {padIDs: ["testPad", "thePadsOfTheOthers"]}}`
|
||||||
|
|
||||||
|
### Global
|
||||||
|
|
||||||
|
#### getStats()
|
||||||
|
* API >= 1.2.14
|
||||||
|
|
||||||
|
get stats of the etherpad instance
|
||||||
|
|
||||||
|
*Example returns*
|
||||||
|
* `{"code":0,"message":"ok","data":{"totalPads":3,"totalSessions": 2,"totalActivePads": 1}}`
|
||||||
|
|
||||||
|
|
|
@ -837,6 +837,37 @@ exports.createDiffHTML = async function(padID, startRev, endRev) {
|
||||||
return { html, authors };
|
return { html, authors };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************/
|
||||||
|
/** GLOBAL FUNCTIONS **/
|
||||||
|
/**********************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
getStats() returns an json object with some instance stats
|
||||||
|
|
||||||
|
Example returns:
|
||||||
|
|
||||||
|
{"code":0,"message":"ok","data":{"totalPads":3,"totalSessions": 2,"totalActivePads": 1}}
|
||||||
|
{"code":4,"message":"no or wrong API Key","data":null}
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.getStats = async function() {
|
||||||
|
const sessionKeys = Object.keys(padMessageHandler.sessioninfos);
|
||||||
|
|
||||||
|
const activePads = new Set();
|
||||||
|
|
||||||
|
sessionKeys
|
||||||
|
.map(k => padMessageHandler.sessioninfos[k])
|
||||||
|
.forEach(o => activePads.add(o.padId));
|
||||||
|
|
||||||
|
const { padIDs } = await padManager.listAllPads();
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalPads: padIDs.length,
|
||||||
|
totalSessions: sessionKeys.length,
|
||||||
|
totalActivePads: activePads.size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
/** INTERNAL HELPER FUNCTIONS */
|
/** INTERNAL HELPER FUNCTIONS */
|
||||||
/******************************/
|
/******************************/
|
||||||
|
|
|
@ -137,8 +137,13 @@ version["1.2.13"] = Object.assign({}, version["1.2.12"],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
version["1.2.14"] = Object.assign({}, version["1.2.13"],
|
||||||
|
{ "getStats" : []
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// set the latest available API version here
|
// set the latest available API version here
|
||||||
exports.latestApiVersion = '1.2.13';
|
exports.latestApiVersion = '1.2.14';
|
||||||
|
|
||||||
// exports the versions so it can be used by the new Swagger endpoint
|
// exports the versions so it can be used by the new Swagger endpoint
|
||||||
exports.version = version;
|
exports.version = version;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue