diff --git a/doc/api/http_api.md b/doc/api/http_api.md index 3d81811c7..5be9cb3a4 100644 --- a/doc/api/http_api.md +++ b/doc/api/http_api.md @@ -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}}` + diff --git a/src/node/db/API.js b/src/node/db/API.js index 998d9acd1..441cc358d 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -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 */ /******************************/ diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 3685b28ad..cac8c15c5 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -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;