mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) updates from grist-core
This commit is contained in:
25
stubs/app/server/prometheus-exporter.ts
Normal file
25
stubs/app/server/prometheus-exporter.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { collectDefaultMetrics, register } from 'prom-client';
|
||||
import http from 'http';
|
||||
|
||||
const reqListener = (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
register.metrics().then((metrics) => {
|
||||
res.writeHead(200, { 'Content-Type': register.contentType });
|
||||
res.end(metrics);
|
||||
}).catch((e) => {
|
||||
res.writeHead(500);
|
||||
res.end(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
export function runPrometheusExporter(port: number) {
|
||||
collectDefaultMetrics();
|
||||
|
||||
if (isNaN(port)) {
|
||||
throw new Error(`Invalid port: ${process.env.GRIST_PROMCLIENT_PORT}`);
|
||||
}
|
||||
const server = http.createServer(reqListener);
|
||||
server.listen(port, '0.0.0.0');
|
||||
|
||||
console.log(`Prometheus exporter listening on port ${port}.`);
|
||||
return server;
|
||||
}
|
||||
@@ -36,6 +36,7 @@ setDefaultEnv('GRIST_WIDGET_LIST_URL', commonUrls.gristLabsWidgetRepository);
|
||||
import {updateDb} from 'app/server/lib/dbUtils';
|
||||
import {main as mergedServerMain, parseServerTypes} from 'app/server/mergedServerMain';
|
||||
import * as fse from 'fs-extra';
|
||||
import {runPrometheusExporter} from './prometheus-exporter';
|
||||
|
||||
const G = {
|
||||
port: parseInt(process.env.PORT!, 10) || 8484,
|
||||
@@ -102,6 +103,10 @@ export async function main() {
|
||||
console.log('For full logs, re-run with DEBUG=1');
|
||||
}
|
||||
|
||||
if (process.env.GRIST_PROMCLIENT_PORT) {
|
||||
runPrometheusExporter(parseInt(process.env.GRIST_PROMCLIENT_PORT, 10));
|
||||
}
|
||||
|
||||
// If SAML is not configured, there's no login system, so provide a default email address.
|
||||
setDefaultEnv('GRIST_DEFAULT_EMAIL', 'you@example.com');
|
||||
// Set directory for uploaded documents.
|
||||
|
||||
Reference in New Issue
Block a user