Skip to content

Commit d080221

Browse files
committed
Added exclude admin coins
1 parent 92c4afb commit d080221

4 files changed

Lines changed: 44 additions & 31 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ DB_HOST=localhost
22
DB_USER=
33
DB_PASSWORD=
44
DB_DATABASE=
5+
56
CheckDelayInMS=10000
7+
ExcludeAdminCoins=true
68

79
Influx_Host=
810
Influx_Protocol=

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ DB_HOST=localhost
7979
DB_USER=dashboarduser
8080
DB_PASSWORD=mysecretpassword
8181
DB_DATABASE=dashboard
82+
8283
CheckDelayInMS=10000
84+
ExcludeAdminCoins=true // If true, the admin coins will not be shown in the stats.
8385
8486
Influx_Host=InfluxDB Ip
8587
Influx_Protocol=http
@@ -89,6 +91,9 @@ Influx_Token=The token that you put into grafana data source
8991
orga=YourOrga
9092
bucket=YourDefaultBucket
9193
host=Dashboard
94+
95+
PteroStatusURL= //Pterostatus URL (with protocol and port, like http://myserver.com:8080)
96+
PteroStatusToken= //Barer Token for the Pterostatus API
9297
```
9398
4. Install node modules and setup pm2
9499
```sh

lib/db/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let GetAllUsers = function () {
5050
console.log(err);
5151
throw new Error("Error in MYSQL Connection" + err);
5252
}
53-
connection.query('SELECT credits, server_limit, email_verified_at, discord_verified_at, ip, suspended FROM users;', function (err, rows, fields) {
53+
connection.query('SELECT credits, server_limit, email_verified_at, discord_verified_at, ip, suspended, role FROM users;', function (err, rows, fields) {
5454
connection.release();
5555
if (Object.entries(rows).length === 0) {
5656
reject(0);

src/collectStats.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
11
const geoip = require('geoip-country');
22
const db = require('../lib/db/mysql');
33
const pterostatus = require('../lib/pterostatus')
4-
const DBDelay = Number(process.env.CheckDelayInMS)/1000;
4+
const DBDelay = Number(process.env.CheckDelayInMS) / 1000;
55

6-
let StatsCollector = function() {
7-
return new Promise(function(resolve, reject) {
6+
let StatsCollector = function () {
7+
return new Promise(function (resolve, reject) {
88
const Promisees = [db.GetAllUsers(), db.GetAllServers(), db.GetAllProducts(), db.GetFailedJobsSinceLastCheck(DBDelay)];
99

10-
if(process.env.PteroStatusURL) {
10+
if (process.env.PteroStatusURL) {
1111
Promisees.push(pterostatus.GetPteroStatusData())
1212
}
13-
13+
1414
try {
15-
Promise.all(Promisees).then(function(values) {
15+
Promise.all(Promisees).then(function (values) {
1616
const Users = values[0];
1717
const Servers = values[1];
1818
const Products = values[2];
1919
const FailedJobs = values[3];
2020
let PteroStatusData = {};
21-
if(process.env.PteroStatusURL) {
22-
PteroStatusData = values[values.length-1];
21+
if (process.env.PteroStatusURL) {
22+
PteroStatusData = values[values.length - 1];
2323
}
24-
24+
2525
let [TotalCoins, TotalSuspendedUsers, TotalAllowedServers, TotalVerifiedUsers, TotalVerifiedDiscordUsers, TotalCPU, TotalRAM, TotalSWAP, TotalDisk, TotalAllocations, TotalDB, TotalServerCostMonthly, ServerSuspended] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
2626
let UserCountrys = [];
2727
let ServerProducts = [];
2828

29-
Users.map(function(User) {
30-
if(User.suspended === 0){
31-
TotalCoins += User.credits;
29+
Users.map(function (User) {
30+
if (User.suspended === 0) {
31+
if (process.env.ExcludeAdminCoins !== 'true' || User.role !== "admin") {
32+
TotalCoins += User.credits;
33+
}
3234
TotalAllowedServers += User.server_limit;
3335

34-
if(User.email_verified_at !== null){
36+
if (User.email_verified_at !== null) {
3537
TotalVerifiedUsers += 1;
3638
}
3739

38-
if(User.discord_verified_at !== null){
40+
if (User.discord_verified_at !== null) {
3941
TotalVerifiedDiscordUsers += 1;
4042
}
4143

42-
if(User.ip !== null && geoip.lookup(User.ip)){
44+
if (User.ip !== null && geoip.lookup(User.ip)) {
4345
UserCountrys.push(geoip.lookup(User.ip).country);
44-
}else{
45-
UserCountrys.push("Local");
46+
} else {
47+
UserCountrys.push("Local");
4648
}
4749

48-
}else{
50+
} else {
4951
TotalSuspendedUsers += 1;
5052
}
5153
});
5254

53-
Servers.map(function(Server) {
54-
if(Server.suspended === null){
55-
Products.map(function(Product) {
56-
if(Server.product_id === Product.id){
55+
Servers.map(function (Server) {
56+
if (Server.suspended === null) {
57+
Products.map(function (Product) {
58+
if (Server.product_id === Product.id) {
5759
TotalCPU += Product.cpu;
5860
TotalRAM += Product.memory;
5961
TotalSWAP += Product.swap;
@@ -62,13 +64,13 @@ let StatsCollector = function() {
6264
TotalAllocations += Product.allocations;
6365
TotalServerCostMonthly += Product.price;
6466
ServerProducts.push(Product.name);
65-
}
67+
}
6668
})
67-
}else{
69+
} else {
6870
ServerSuspended += 1;
6971
}
7072
});
71-
73+
7274
const UserCountrysObject = UserCountrys.reduce(function (acc, curr) {
7375
return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc
7476
}, {})
@@ -107,14 +109,18 @@ let StatsCollector = function() {
107109
Failed: FailedJobs[0]['COUNT(*)'],
108110
}
109111
}
110-
111-
if(process.env.PteroStatusURL) {
112+
113+
if (process.env.PteroStatusURL) {
112114
ExportStats["PteroStatus"] = PteroStatusData;
113115
}
114-
116+
115117
resolve(ExportStats);
116-
}).catch(function(err) {
117-
console.log(err);
118+
}).catch(function (err) {
119+
if (err.response.status === 403) {
120+
console.log("PteroStatus API Key is invalid");
121+
} else {
122+
console.log(err);
123+
}
118124
});
119125
} catch (error) {
120126
reject(error);

0 commit comments

Comments
 (0)