Skip to content

Commit 0e9f0b9

Browse files
committed
CHANGES:
- Slight rework of /serverstats BUGFIX: - /doc did show ports of disabled extensions
1 parent 12e5097 commit 0e9f0b9

File tree

9 files changed

+34
-49
lines changed

9 files changed

+34
-49
lines changed

extensions/grpc/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ def is_installed(self) -> bool:
128128
async def get_ports(self) -> dict:
129129
return {
130130
"gRPC": self.locals.get('port', 50051)
131-
}
131+
} if self.enabled else {}

extensions/lardoon/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,4 @@ def run_subprocess(args):
188188
async def get_ports(self) -> dict:
189189
return {
190190
"Lardoon": self.config['bind'].split(':')[1]
191-
}
191+
} if self.enabled else {}

extensions/lotatc/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,4 @@ async def schedule(self):
345345
async def get_ports(self) -> dict:
346346
return {
347347
"LotAtc": self.locals.get('port', 10310)
348-
}
348+
} if self.enabled else {}

extensions/olympus/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,4 @@ def get_ports(self) -> dict:
321321
return {
322322
"Olympus " + self.backend_tag.capitalize(): self.config.get(self.backend_tag, {}).get('port', 3001),
323323
"Olympus " + self.frontend_tag.capitalize(): self.config.get(self.frontend_tag, {}).get('port', 3000)
324-
}
324+
} if self.enabled else {}

extensions/sneaker/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ async def render(self, param: Optional[dict] = None) -> dict:
190190
def get_ports(self) -> dict:
191191
return {
192192
"Sneaker": self.config['bind'].split(':')[1]
193-
}
193+
} if self.enabled else {}

extensions/srs/extension.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,12 @@ async def schedule(self):
565565
self.log.exception(ex)
566566

567567
async def get_ports(self) -> dict:
568-
rc = {
569-
"SRS Port": self.locals['Server Settings']['SERVER_PORT']
570-
}
571-
if self.locals['General Settings'].get('LOTATC_EXPORT_ENABLED', False):
572-
rc["LotAtc Export Port"] = self.locals['General Settings'].get('LOTATC_EXPORT_PORT', 10712)
568+
if self.enabled:
569+
rc = {
570+
"SRS Port": self.locals['Server Settings']['SERVER_PORT']
571+
}
572+
if self.locals['General Settings'].get('LOTATC_EXPORT_ENABLED', False):
573+
rc["LotAtc Export Port"] = self.locals['General Settings'].get('LOTATC_EXPORT_PORT', 10712)
574+
else:
575+
rc = {}
573576
return rc

extensions/tacview/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ async def get_ports(self) -> dict:
428428
return {
429429
"tacviewRealTimeTelemetryPort": self.locals.get('tacviewRealTimeTelemetryPort', 42674),
430430
"tacviewRemoteControlPort": self.locals.get('tacviewRemoteControlPort', 42675)
431-
}
431+
} if self.enabled else {}
432432

433433
async def change_config(self, config: dict):
434434
if config.get('target') and not self.config.get('target'):

plugins/monitoring/reports/serverstats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"type": "Graph",
4545
"params":
4646
{
47-
"width": 25,
47+
"width": 24,
4848
"height": 25,
4949
"dpi": 100,
5050
"cols": 1,

plugins/monitoring/serverstats.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,78 +58,60 @@ async def render(self, server_name: Optional[str], period: StatisticsFilter):
5858

5959
where_clause = "AND m.server_name = %(server_name)s" if server_name else ""
6060
sql = f"""
61-
SELECT trim(regexp_replace(m.server_name, '{self.bot.filter['server_name']}', '', 'g')) AS server_name,
62-
m.mission_theatre,
61+
SELECT m.mission_theatre,
6362
COALESCE(ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600), 0) AS playtime
6463
FROM missions m, statistics s
6564
WHERE m.id = s.mission_id
6665
{where_clause}
6766
AND {period.filter(self.env.bot)}
68-
GROUP BY 1, 2
69-
ORDER BY 3 DESC
67+
GROUP BY 1
68+
ORDER BY 2 DESC
7069
"""
7170

7271
async with self.apool.connection() as conn:
7372
async with conn.cursor(row_factory=dict_row) as cursor:
74-
servers = theatres = playtimes = ''
73+
theatres = playtimes = ''
7574
await cursor.execute(sql, {"server_name": server_name})
7675
async for row in cursor:
77-
servers += utils.escape_string(row['server_name'])[:30] + '\n'
7876
theatres += utils.escape_string(row['mission_theatre'])[:20] + '\n'
7977
playtimes += '{:.0f}\n'.format(row['playtime'])
8078

81-
if len(servers) > 0:
82-
if not server_name:
83-
self.add_field(name='Server', value=servers)
79+
if len(theatres) > 0:
8480
self.add_field(name='TOP Theatre' if not server_name else f"TOP Theatres", value=theatres)
8581
self.add_field(name='Playtime (h)', value=playtimes)
86-
if server_name:
87-
self.add_field(name='_ _', value='_ _')
82+
self.add_field(name='_ _', value='_ _')
8883

8984

9085
class TopMissionPerServer(report.EmbedElement):
9186

9287
async def render(self, server_name: Optional[str], period: StatisticsFilter, limit: int):
9388

9489
where_clause = "AND m.server_name = %(server_name)s" if server_name else ""
95-
limit_clause = f"WHERE rn <= {limit}" if server_name else "WHERE rn = 1"
9690
sql = f"""
97-
SELECT server_name, mission_name, playtime
98-
FROM (
99-
SELECT server_name, mission_name, playtime,
100-
ROW_NUMBER() OVER(PARTITION BY server_name ORDER BY playtime DESC) AS rn
101-
FROM (
102-
SELECT trim(regexp_replace(m.server_name, '{self.bot.filter['server_name']}', '', 'g')) AS server_name,
103-
trim(regexp_replace(m.mission_name, '{self.bot.filter['mission_name']}', ' ', 'g')) AS mission_name,
104-
ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600) AS playtime
105-
FROM missions m, statistics s
106-
WHERE m.id = s.mission_id
107-
AND s.hop_off IS NOT NULL
108-
{where_clause}
109-
AND {period.filter(self.env.bot)}
110-
GROUP BY 1, 2
111-
) AS x
112-
) AS y
113-
{limit_clause}
114-
ORDER BY 3 DESC
91+
SELECT trim(regexp_replace(m.mission_name, '{self.bot.filter['mission_name']}', ' ', 'g')) AS mission_name,
92+
ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600) AS playtime
93+
FROM missions m, statistics s
94+
WHERE m.id = s.mission_id
95+
AND s.hop_off IS NOT NULL
96+
{where_clause}
97+
AND {period.filter(self.env.bot)}
98+
GROUP BY 1
99+
ORDER BY 2 DESC
100+
LIMIT {limit}
115101
"""
116102

117103
async with self.apool.connection() as conn:
118104
async with conn.cursor(row_factory=dict_row) as cursor:
119-
servers = missions = playtimes = ''
105+
missions = playtimes = ''
120106
await cursor.execute(sql, {"server_name": server_name})
121107
async for row in cursor:
122-
servers += utils.escape_string(row['server_name'])[:30] + '\n'
123108
missions += row['mission_name'][:20] + '\n'
124109
playtimes += '{:.0f}\n'.format(row['playtime'])
125110

126-
if len(servers) > 0:
127-
if not server_name:
128-
self.add_field(name='Server', value=servers)
111+
if len(missions) > 0:
129112
self.add_field(name='TOP Mission' if not server_name else f"TOP {limit} Missions", value=missions)
130113
self.add_field(name='Playtime (h)', value=playtimes)
131-
if server_name:
132-
self.add_field(name='_ _', value='_ _')
114+
self.add_field(name='_ _', value='_ _')
133115

134116

135117
class TopModulesPerServer(report.EmbedElement):

0 commit comments

Comments
 (0)