-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to see server status without login (#131)
- Loading branch information
Showing
15 changed files
with
100 additions
and
83 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
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 was deleted.
Oops, something went wrong.
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,15 @@ | ||
#server-status-dot[data-status="red"] .animate-ping { | ||
background-color: #f87171 !important; /* Tailwind CSS bg-red-400 */ | ||
} | ||
|
||
#server-status-dot[data-status="red"] .relative { | ||
background-color: #dc2626 !important; /* Tailwind CSS bg-red-600 */ | ||
} | ||
|
||
#server-status-dot[data-status="green"] .animate-ping { | ||
background-color: #34d399 !important; /* Tailwind CSS bg-green-400 */ | ||
} | ||
|
||
#server-status-dot[data-status="green"] .relative { | ||
background-color: #059669 !important; /* Tailwind CSS bg-green-600 */ | ||
} |
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,12 +1,9 @@ | ||
import express from "express"; | ||
|
||
import { ServerStatusController } from "@/controller/ServerStatusController"; | ||
import { jwtAuth } from "@/middleware/auth"; | ||
|
||
const router = express.Router(); | ||
|
||
router.use(jwtAuth()); | ||
|
||
router.get("", ServerStatusController.render); | ||
|
||
export { router as serverStatusRouter }; |
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,6 +1,8 @@ | ||
import { User } from "./user"; | ||
import type { WebSocket as InitialWebSocket } from "ws"; | ||
|
||
export interface WebSocket extends InitialWebSocket { | ||
route?: string; | ||
params?: Record<string, string>; | ||
route?: string; | ||
user?: User; | ||
} |
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,35 @@ | ||
import { cpus, loadavg } from "os"; | ||
import pidusage from "pidusage"; | ||
|
||
import { WebSocket } from "@/types/ws"; | ||
import { eventType } from "@/utils/eventTypeConstant"; | ||
|
||
const State = { | ||
type: eventType.Resource, | ||
cpu: "0.00", | ||
memory: "0.00", | ||
uptime: 0, | ||
load: "0.00", | ||
}; | ||
|
||
setInterval(() => { | ||
pidusage(process.pid, (err, stat) => { | ||
if (err) { | ||
console.log(err); | ||
return null; | ||
} | ||
|
||
State["cpu"] = Number(stat.cpu).toFixed(2); | ||
State["memory"] = Number(stat.memory / 1024 / 1024).toFixed(2); | ||
State["uptime"] = stat.elapsed; | ||
State["load"] = (loadavg()?.[1] / cpus()?.length)?.toFixed(2) ?? "0.00"; // 5 minutes load average | ||
}); | ||
}, 1000); | ||
|
||
function sendStatus(client: WebSocket) { | ||
return setInterval(() => { | ||
client.send(JSON.stringify(State)); | ||
}, 1000); | ||
} | ||
|
||
export { State, sendStatus }; |
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