api: add getStats() function

pull/3851/head
Chocobozzz 2020-04-01 10:57:43 +02:00 committed by muxator
parent eb45934788
commit 82b919fc65
3 changed files with 49 additions and 2 deletions

View File

@ -65,7 +65,7 @@ Portal submits content into new blog post
## Usage
### API version
The latest version is `1.2.13`
The latest version is `1.2.14`
The current version can be queried via /api.
@ -634,3 +634,14 @@ lists all pads on this epl instance
*Example returns:*
* `{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}}`

View File

@ -837,6 +837,37 @@ exports.createDiffHTML = async function(padID, startRev, endRev) {
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 */
/******************************/

View File

@ -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
exports.latestApiVersion = '1.2.13';
exports.latestApiVersion = '1.2.14';
// exports the versions so it can be used by the new Swagger endpoint
exports.version = version;