Add gzip compression & prometheus with config toggle
This commit is contained in:
parent
b837bfcbc3
commit
eb75626471
2 changed files with 24 additions and 1 deletions
21
Binato.js
21
Binato.js
|
@ -5,14 +5,35 @@ global.consoleHelper = require("./consoleHelper.js");
|
||||||
global.protocolVersion = 19;
|
global.protocolVersion = 19;
|
||||||
|
|
||||||
const app = require("express")(),
|
const app = require("express")(),
|
||||||
|
prometheusApp = require("express")(),
|
||||||
|
compression = require("compression"),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
|
prom = require("prom-client"),
|
||||||
serverHandler = require("./server/serverHandler.js"),
|
serverHandler = require("./server/serverHandler.js"),
|
||||||
config = require("./config.json");
|
config = require("./config.json");
|
||||||
|
|
||||||
const debugMode = true;
|
const debugMode = true;
|
||||||
|
|
||||||
|
if (config.prometheusEnabled) {
|
||||||
|
const register = new prom.Registry();
|
||||||
|
|
||||||
|
register.setDefaultLabels({ app: "nodejs_binato" });
|
||||||
|
|
||||||
|
prom.collectDefaultMetrics({ register });
|
||||||
|
|
||||||
|
prometheusApp.get("*", async (req, res) => {
|
||||||
|
if (req.url.split("?")[0] != "/metrics") return res.status(404).end("");
|
||||||
|
|
||||||
|
res.end(await register.metrics());
|
||||||
|
});
|
||||||
|
|
||||||
|
prometheusApp.listen(config.prometheusPort, () => global.consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheusPort}`));
|
||||||
|
} else global.consoleHelper.printWarn("Prometheus is disabled!");
|
||||||
|
|
||||||
|
if (config.compression) {
|
||||||
|
app.use(compression());
|
||||||
|
global.consoleHelper.printBancho("Gzip Compression is enabled.");
|
||||||
|
} else global.consoleHelper.printWarn("Gzip Compression is disabled!");
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
req.packet = new Buffer.alloc(0);
|
req.packet = new Buffer.alloc(0);
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
|
"compression": "^1.7.4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"osu-packet": "^4.1.2",
|
"osu-packet": "^4.1.2",
|
||||||
|
"prom-client": "^13.2.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue