-
-
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.
Run prometheus-exporter as a module #671
- Loading branch information
Florent FAYOLLE
committed
Oct 24, 2023
1 parent
06559da
commit a7a14e3
Showing
4 changed files
with
18 additions
and
22 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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { collectDefaultMetrics, register } from 'prom-client'; | ||
import http from 'http'; | ||
|
||
collectDefaultMetrics(); | ||
|
||
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => { | ||
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); | ||
}); | ||
}); | ||
}; | ||
|
||
const port = parseInt(process.env.GRIST_PROMCLIENT_PORT!, 10); | ||
if (isNaN(port)) { | ||
throw new Error(`Invalid port: ${process.env.GRIST_PROMCLIENT_PORT}`); | ||
} | ||
server.listen(port, '0.0.0.0'); | ||
export function runPrometheusExporter(port: number) { | ||
collectDefaultMetrics(); | ||
|
||
console.log("---------------------------------------------"); | ||
console.log(`Prometheus exporter listening on port ${port}`); | ||
console.log("---------------------------------------------"); | ||
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. | ||
|