-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathbackstage.ts
37 lines (31 loc) · 1.13 KB
/
backstage.ts
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
import { writeHeapSnapshot } from 'v8';
import { tmpdir } from 'os';
import { join } from 'path';
import { register as prometheusRegister } from 'prom-client';
import Controller from './controller';
import type { IUnleashConfig } from '../types/option';
class BackstageController extends Controller {
logger: any;
constructor(config: IUnleashConfig) {
super(config);
this.logger = config.getLogger('backstage.js');
if (config.server.serverMetrics) {
this.get('/prometheus', async (req, res) => {
res.set('Content-Type', prometheusRegister.contentType);
res.end(await prometheusRegister.metrics());
});
}
if (config.server.enableHeapSnapshotEnpoint) {
this.get('/heap-snapshot', async (req, res) => {
const fileName = join(
tmpdir(),
`unleash-${Date.now()}.heapsnapshot`,
);
writeHeapSnapshot(fileName);
res.status(200);
res.end('Snapshot written');
});
}
}
}
export { BackstageController };