Compare commits
5 Commits
2992ad84da
...
main
Author | SHA1 | Date | |
---|---|---|---|
41c28168e9 | |||
565b533ad4 | |||
5c5e44ad20 | |||
f9a9a37e1a | |||
0fbea0cb4e |
@ -4,7 +4,7 @@
|
||||
|
||||
# Minetrack
|
||||
|
||||
Minetrack makes it easy to keep an eye on your favorite Minecraft servers. Simple and hackable, Minetrack easily runs on any hardware. Use it for monitoring, analytics, or just for fun. [Check it out](https://minetrack.me).
|
||||
Minetrack makes it easy to keep an eye on your favorite Minecraft servers. Simple and hackable, Minetrack easily runs on any hardware. Use it for monitoring, analytics, or just for fun. [Check it out](https://mc.fascinated.cc/).
|
||||
|
||||
### This project is not actively supported
|
||||
|
||||
|
@ -2,8 +2,18 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../css/main.css" />
|
||||
<title>Minetrack</title>
|
||||
<meta charset="UTF-8" />
|
||||
|
||||
<!-- Discord Embed -->
|
||||
<meta content="Minetrack" property="og:title" />
|
||||
<meta
|
||||
content="Tracking minecraft servers since 2023"
|
||||
property="og:description"
|
||||
/>
|
||||
<meta content="https://mc.fascinated.cc/" property="og:url" />
|
||||
|
||||
<link rel="stylesheet" href="../css/main.css" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;700&display=swap"
|
||||
@ -11,11 +21,7 @@
|
||||
|
||||
<link rel="icon" type="image/svg+xml" href="../images/logo.svg" />
|
||||
|
||||
<meta charset="UTF-8" />
|
||||
|
||||
<script defer type="module" src="../js/main.js"></script>
|
||||
|
||||
<title>Minetrack</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -4,8 +4,8 @@
|
||||
"ip": "0.0.0.0"
|
||||
},
|
||||
"rates": {
|
||||
"pingAll": 15000,
|
||||
"connectTimeout": 2500
|
||||
"pingAll": 30000,
|
||||
"connectTimeout": 5000
|
||||
},
|
||||
"oldPingsCleanup": {
|
||||
"enabled": false,
|
||||
@ -13,6 +13,6 @@
|
||||
},
|
||||
"logFailedPings": true,
|
||||
"logToDatabase": true,
|
||||
"graphDuration": 86400000,
|
||||
"serverGraphDuration": 180000
|
||||
"graphDuration": 604800000,
|
||||
"serverGraphDuration": 360000
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ services:
|
||||
- 8.8.8.8
|
||||
- 1.1.1.1
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "8880:8080"
|
||||
volumes:
|
||||
# Copy these from the git repo
|
||||
- ./servers.json:/usr/src/minetrack/servers.json
|
||||
- ./config.json:/usr/src/minetrack/config.json
|
||||
|
||||
- ./data:/data # The sqlite database will be stored here
|
||||
- ./data:/usr/src/minetrack/data # The sqlite database will be stored here
|
||||
restart: always
|
||||
|
@ -6,6 +6,7 @@ const MessageOf = require("./message");
|
||||
|
||||
const config = require("../config");
|
||||
const minecraftVersions = require("../minecraft_versions");
|
||||
const { formatMsToTime } = require("./utils/timeUtils");
|
||||
|
||||
class App {
|
||||
serverRegistrations = [];
|
||||
@ -74,9 +75,11 @@ class App {
|
||||
|
||||
// Send configuration data for rendering the page
|
||||
return {
|
||||
// graphDurationLabel:
|
||||
// config.graphDurationLabel ||
|
||||
// Math.floor(config.graphDuration / (60 * 60 * 1000)) + "h",
|
||||
graphDurationLabel:
|
||||
config.graphDurationLabel ||
|
||||
Math.floor(config.graphDuration / (60 * 60 * 1000)) + "h",
|
||||
config.graphDurationLabel || formatMsToTime(config.graphDuration),
|
||||
graphMaxLength: TimeTracker.getMaxGraphDataLength(),
|
||||
serverGraphMaxLength: TimeTracker.getMaxServerGraphDataLength(),
|
||||
servers: this.serverRegistrations.map((serverRegistration) =>
|
||||
|
@ -239,7 +239,6 @@ class Database {
|
||||
|
||||
// Record not found
|
||||
if (data[0] === undefined) {
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
@ -248,7 +247,6 @@ class Database {
|
||||
const timestamp = data[0].timestamp;
|
||||
|
||||
// Allow null player counts and timestamps, the frontend will safely handle them
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
callback(true, playerCount, timestamp);
|
||||
}
|
||||
);
|
||||
@ -272,10 +270,8 @@ class Database {
|
||||
// Allow null timestamps, the frontend will safely handle them
|
||||
// This allows insertion of free standing records without a known timestamp
|
||||
if (playerCount !== null) {
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
callback(true, playerCount, timestamp);
|
||||
} else {
|
||||
// eslint-disable-next-line node/no-callback-literal
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ class PingController {
|
||||
|
||||
schedule() {
|
||||
setInterval(this.pingAll, config.rates.pingAll);
|
||||
// todo: make this a cron job?
|
||||
|
||||
this.pingAll();
|
||||
}
|
||||
|
28
lib/utils/timeUtils.js
Normal file
28
lib/utils/timeUtils.js
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Formats a time in milliseconds to a human readable format
|
||||
* eg: 1000ms -> 1s or 60000ms -> 1m
|
||||
*
|
||||
* @param ms the time in milliseconds
|
||||
* @returns the formatted time
|
||||
*/
|
||||
function formatMsToTime(ms) {
|
||||
// this is really fucking shitty but it works!
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) {
|
||||
return `${days}d`;
|
||||
} else if (hours > 0) {
|
||||
return `${hours}h`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m`;
|
||||
} else {
|
||||
return `${seconds}s`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatMsToTime,
|
||||
};
|
Reference in New Issue
Block a user