-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Florent FAYOLLE <[email protected]>
- Loading branch information
Showing
5 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', '[email protected]'); | ||
// Set directory for uploaded documents. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1739,6 +1739,11 @@ binary@~0.3.0: | |
buffers "~0.1.1" | ||
chainsaw "~0.1.0" | ||
|
||
[email protected]: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.2.tgz#49f896d6e858a4a499df85c38fb399b9aff840f8" | ||
integrity sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw== | ||
|
||
bl@^4.0.3: | ||
version "4.1.0" | ||
resolved "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz" | ||
|
@@ -6520,6 +6525,13 @@ process@~0.11.0: | |
resolved "https://registry.npmjs.org/process/-/process-0.11.10.tgz" | ||
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI= | ||
|
||
[email protected]: | ||
version "14.2.0" | ||
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.2.0.tgz#ca94504e64156f6506574c25fb1c34df7812cf11" | ||
integrity sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA== | ||
dependencies: | ||
tdigest "^0.1.1" | ||
|
||
promise-inflight@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" | ||
|
@@ -7688,6 +7700,13 @@ tar@^6.0.2, tar@^6.1.11, tar@^6.1.2: | |
mkdirp "^1.0.3" | ||
yallist "^4.0.0" | ||
|
||
tdigest@^0.1.1: | ||
version "0.1.2" | ||
resolved "https://registry.yarnpkg.com/tdigest/-/tdigest-0.1.2.tgz#96c64bac4ff10746b910b0e23b515794e12faced" | ||
integrity sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA== | ||
dependencies: | ||
bintrees "1.0.2" | ||
|
||
term-size@^2.1.0: | ||
version "2.2.0" | ||
resolved "https://registry.npmjs.org/term-size/-/term-size-2.2.0.tgz" | ||
|