Přidat index.js
Some checks failed
Build Minecore UDP check image / Build-Minecraft-Stats-Image (push) Failing after 33s
Some checks failed
Build Minecore UDP check image / Build-Minecraft-Stats-Image (push) Failing after 33s
This commit is contained in:
parent
39b7755aef
commit
fdc258989f
26
index.js
Normal file
26
index.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const express = require('express')
|
||||||
|
const { ping } = require('bedrock-protocol')
|
||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
app.listen(3000)
|
||||||
|
|
||||||
|
if(!process.env.HOSTNAME) throw new Error("HOSTNAME not set")
|
||||||
|
|
||||||
|
const template = (status)=> `# HELP minecraft_bedrock_check Information about liveness of target bedrock server
|
||||||
|
# TYPE minecraft_bedrock_check gauge
|
||||||
|
minecraft_bedrock_check{server="${process.env.HOSTNAME}"} ${status}
|
||||||
|
`
|
||||||
|
|
||||||
|
app.get('/metrics',async (req, res) => {
|
||||||
|
try {
|
||||||
|
const hostname = process.env.HOSTNAME
|
||||||
|
await ping({host: hostname, port: 19132, connectTimeout: process.env.TIMEOUT ?? 4000})
|
||||||
|
res.contentType("text/plain; charset=utf-8")
|
||||||
|
res.send(template("1"))
|
||||||
|
} catch (e) {
|
||||||
|
res.contentType("text/plain; charset=utf-8")
|
||||||
|
res.send(template("0"))
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user