-
Notifications
You must be signed in to change notification settings - Fork 170
/
stats.js
45 lines (40 loc) · 1.19 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const schema = require('screwdriver-data-schema');
/**
* Hapi interface for plugin to set up status endpoint (see Hapi docs)
* @method register
* @param {Hapi.Server} server
* @param {Object} options
* @param {Function} next
*/
const statsPlugin = {
name: 'stats',
async register(server, options) {
const { executor, scm } = options;
server.route({
method: 'GET',
path: '/stats',
config: {
description: 'API stats',
notes: 'Should return statistics for the entire system',
tags: ['api', 'stats'],
plugins: {
'hapi-rate-limit': {
enabled: false
}
},
response: {
schema: schema.api.stats
}
},
handler: async (request, h) => {
const executorStats = await executor.stats({ token: '' });
return h.response({
executor: executorStats,
scm: scm.stats()
});
}
});
}
};
module.exports = statsPlugin;